test: protect more yacc declarations against C vs. C++ linkage.
[automake.git] / t / remake-gnulib-remove-header.sh
blob2a536ff078288d3479fddbae57439965896a2d2d
1 #! /bin/sh
2 # Copyright (C) 2011-2024 Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2, or (at your option)
7 # any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <https://www.gnu.org/licenses/>.
17 # Test remake rules when a C header "guarded" by AC_SUBST'd variables
18 # is not needed anymore, or when it's needed again.
19 # This test requires some user-level machinery, overlaps with other tests,
20 # and is not strictly necessary per se, but it exercises a real, important
21 # use case (from gnulib, see:
22 # <https://lists.gnu.org/archive/html/bug-gnulib/2011-04/msg00005.html>
23 # for more info).
25 required=cc
26 . test-init.sh
28 cat >> configure.ac <<'END'
29 AC_CONFIG_HEADERS([config.h])
30 AC_PROG_CC
31 MY_MACROS
32 AC_OUTPUT
33 END
35 cat > Makefile.am <<'END'
36 ACLOCAL_AMFLAGS = -I .
37 noinst_PROGRAMS = foo
38 foo_SOURCES = foo.c
39 BUILT_SOURCES = $(STDIO_H)
40 if REPLACE_STDIO_H
41 stdio.h: stdio.in.h $(top_builddir)/config.status
42 cp $(srcdir)/stdio.in.h $@
43 else
44 stdio.h: $(top_builddir)/config.status
45 rm -f $@
46 endif
47 MOSTLYCLEANFILES = stdio.h
48 END
50 cat > macros.m4 <<'END'
51 AC_DEFUN([MY_MACROS], [
52 override_stdio=:
53 if $override_stdio; then
54 STDIO_H=stdio.h
55 use_dummies=1
56 else
57 STDIO_H=
58 use_dummies=0
60 AC_SUBST([STDIO_H])
61 AC_DEFINE_UNQUOTED([USE_DUMMIES], [$use_dummies],
62 [Whether to use dummy types.])
63 AM_CONDITIONAL([REPLACE_STDIO_H], [test -n "$STDIO_H"])
65 END
67 cat > stdio.in.h <<'END'
68 typedef struct dummyfile { void *p; } DUMMYFILE;
69 END
71 cat > foo.c <<'END'
72 #include <config.h>
73 #include <stdio.h>
74 #if USE_DUMMIES
75 DUMMYFILE *f;
76 #else
77 FILE *f;
78 #endif
79 int main () { return 0; }
80 END
82 $ACLOCAL -I .
83 $AUTOHEADER
84 $AUTOMAKE
85 $AUTOCONF
87 for vpath in : false; do
89 if $vpath; then
90 mkdir build
91 cd build
92 srcdir=..
93 else
94 srcdir=.
97 # Do not reject slow dependency extractors: we need dependency tracking.
98 $srcdir/configure --enable-dependency-tracking
99 if $FGREP 'depmode=none' Makefile; then
100 skip_ "automatic dependency tracking couldn't be activated"
103 $MAKE
104 ls -l
105 test -f stdio.h
107 # Simulate that we don't need our custom stdio.h anymore.
109 $sleep
110 sed -e 's/^\( *override_stdio\)=.*$/\1=false/' $srcdir/macros.m4 > t
111 diff $srcdir/macros.m4 t && fatal_ "failed to edit macros.m4"
112 mv -f t $srcdir/macros.m4
114 using_gmake || $MAKE Makefile
115 $MAKE
116 ls -l
117 test ! -e stdio.h
119 # And now simulate that we want our custom stdio.h back.
121 $sleep
122 sed -e 's/^\( *override_stdio\)=.*$/\1=:/' $srcdir/macros.m4 > t
123 diff $srcdir/macros.m4 t && fatal_ "failed to edit macros.m4"
124 mv -f t $srcdir/macros.m4
126 using_gmake || $MAKE Makefile
127 $MAKE
128 ls -l
129 test -f stdio.h
131 $MAKE distclean
132 cd $srcdir
134 done