doc: typos in test file.
[automake.git] / t / yacc-deleted-headers.sh
blob81957eb867dcd439bcd4dcadec6750ca7ad90e1b
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 # Tests that we can recover from deleted headers generated by 'yacc -d'.
19 required='cc yacc'
20 . test-init.sh
22 cat >> configure.ac << 'END'
23 AC_PROG_CC
24 AC_PROG_YACC
25 AC_OUTPUT
26 END
28 cat > Makefile.am <<'END'
29 AM_LFLAGS = --never-interactive
31 bin_PROGRAMS = p1 p2 p3 p4
32 # The order in which files are listed in the p*_SOURCES variables
33 # below is significant, since it causes make failures whenever
34 # the proper definition of BUILT_SOURCES or the declaration of
35 # extra dependencies for 'main3.o' are removed.
36 p1_SOURCES = main1.c parse1.y
37 p2_SOURCES = main2.c parse2.y
38 p3_SOURCES = main3.c parse3.y parse3.h
39 p4_SOURCES = parse4.y
40 AM_YFLAGS = -d
41 p2_YFLAGS = -d
43 BUILT_SOURCES = parse1.h p2-parse2.h
45 # When we know which files include a yacc-generated header, we
46 # should be able to just declare dependencies directly instead
47 # of relying on the BUILT_SOURCES hack, and things should still
48 # work correctly.
49 main3.@OBJEXT@ parse3.@OBJEXT@: parse3.h
51 .PHONY: clean-p3 build-p3
52 build-p3: p3$(EXEEXT)
53 clean-p3:
54 rm -f p3$(EXEEXT)
55 END
57 cat > parse1.y << 'END'
59 #include "parse1.h"
60 int yylex () { return 0; }
61 void yyerror (const char *s) {}
63 %token ZARDOZ
65 x : 'x' {};
67 END
69 cat > main1.c << 'END'
70 #include "parse1.h"
71 int main (void)
73 return ZARDOZ + yyparse ();
75 END
77 sed 's/"parse1\.h"/"p2-parse2.h"/' parse1.y > parse2.y
78 sed 's/"parse1\.h"/"p2-parse2.h"/' main1.c > main2.c
80 sed 's/"parse1\.h"/"parse3.h"/' parse1.y > parse3.y
81 sed 's/"parse1\.h"/"parse3.h"/' main1.c > main3.c
83 cat > parse4.y << 'END'
85 int yylex () { return 0; }
86 void yyerror (const char *s) {}
89 x : 'x' {};
91 int main (void)
93 return 0;
95 END
97 $ACLOCAL
98 $AUTOCONF
99 $AUTOMAKE -a
101 ./configure
102 $MAKE
104 headers='parse1.h p2-parse2.h parse3.h parse4.h'
106 # Check that we remake only the necessary headers.
108 rm -f $headers
109 $MAKE parse1.h
110 test -f parse1.h
111 test ! -e p2-parse2.h
112 test ! -e parse3.h
113 test ! -e parse4.h
115 rm -f $headers
116 $MAKE p2-parse2.h
117 test ! -e parse1.h
118 test -f p2-parse2.h
119 test ! -e parse3.h
120 test ! -e parse4.h
122 rm -f $headers
123 $MAKE parse3.h
124 test ! -e parse1.h
125 test ! -e p2-parse2.h
126 test -f parse3.h
127 test ! -e parse4.h
128 # Since we declared parse3.h into $(p3_SOURCES), make should be
129 # able to rebuild it automatically before remaking 'p3'.
130 rm -f $headers
131 $MAKE clean-p3
132 test ! -e parse3.h # Sanity check.
133 $MAKE build-p3
134 test -f parse3.h
136 $MAKE
138 rm -f $headers
139 $MAKE parse4.h
140 test ! -e parse1.h
141 test ! -e p2-parse2.h
142 test ! -e parse3.h
143 test -f parse4.h
145 # Now remake all the headers together.
147 rm -f $headers
148 $MAKE $headers
149 test -f parse1.h
150 test -f p2-parse2.h
151 test -f parse3.h
152 test -f parse4.h
154 # Most headers should be remade by "make all".
156 rm -f $headers
157 $MAKE all
158 test -f parse1.h
159 test -f p2-parse2.h
160 test -f parse3.h
161 # parse4.h is not declared in any *_SOURCES variable, nor #included
162 # by any C source file, so it shouldn't be rebuilt by "make all".
163 test ! -e parse4.h