Merge branch 'minor'
[automake.git] / t / yacc-deleted-headers.sh
blob87a2acca16a9d2ac7163e2d6fcf59ff3dea1d711
1 #! /bin/sh
2 # Copyright (C) 2011-2017 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 bin_PROGRAMS = p1 p2 p3 p4
30 # The order in which files are listed in the p*_SOURCES variables
31 # below is significant, since it causes make failures whenever
32 # the proper definition of BUILT_SOURCES or the declaration of
33 # extra dependencies for 'main3.o' are removed.
34 p1_SOURCES = main1.c parse1.y
35 p2_SOURCES = main2.c parse2.y
36 p3_SOURCES = main3.c parse3.y parse3.h
37 p4_SOURCES = parse4.y
38 AM_YFLAGS = -d
39 p2_YFLAGS = -d
41 BUILT_SOURCES = parse1.h p2-parse2.h
43 # When we know which files include a yacc-generated header, we
44 # should be able to just declare dependencies directly instead
45 # of relying on the BUILT_SOURCES hack, and things should still
46 # work correctly.
47 main3.@OBJEXT@ parse3.@OBJEXT@: parse3.h
49 .PHONY: clean-p3 build-p3
50 build-p3: p3$(EXEEXT)
51 clean-p3:
52 rm -f p3$(EXEEXT)
53 END
55 cat > parse1.y << 'END'
57 #include "parse1.h"
58 int yylex () { return 0; }
59 void yyerror (char *s) { return; }
61 %token ZARDOZ
63 x : 'x' {};
65 END
67 cat > main1.c << 'END'
68 #include "parse1.h"
69 int main (void)
71 return ZARDOZ + yyparse ();
73 END
75 sed 's/"parse1\.h"/"p2-parse2.h"/' parse1.y > parse2.y
76 sed 's/"parse1\.h"/"p2-parse2.h"/' main1.c > main2.c
78 sed 's/"parse1\.h"/"parse3.h"/' parse1.y > parse3.y
79 sed 's/"parse1\.h"/"parse3.h"/' main1.c > main3.c
81 cat > parse4.y << 'END'
83 int yylex () { return 0; }
84 void yyerror (char *s) { return; }
87 x : 'x' {};
89 int main (void)
91 return 0;
93 END
95 $ACLOCAL
96 $AUTOCONF
97 $AUTOMAKE -a
99 ./configure
100 $MAKE
102 headers='parse1.h p2-parse2.h parse3.h parse4.h'
104 # Check that we remake only the necessary headers.
106 rm -f $headers
107 $MAKE parse1.h
108 test -f parse1.h
109 test ! -e p2-parse2.h
110 test ! -e parse3.h
111 test ! -e parse4.h
113 rm -f $headers
114 $MAKE p2-parse2.h
115 test ! -e parse1.h
116 test -f p2-parse2.h
117 test ! -e parse3.h
118 test ! -e parse4.h
120 rm -f $headers
121 $MAKE parse3.h
122 test ! -e parse1.h
123 test ! -e p2-parse2.h
124 test -f parse3.h
125 test ! -e parse4.h
126 # Since we declared parse3.h into $(p3_SOURCES), make should be
127 # able to rebuild it automatically before remaking 'p3'.
128 rm -f $headers
129 $MAKE clean-p3
130 test ! -e parse3.h # Sanity check.
131 $MAKE build-p3
132 test -f parse3.h
134 $MAKE
136 rm -f $headers
137 $MAKE parse4.h
138 test ! -e parse1.h
139 test ! -e p2-parse2.h
140 test ! -e parse3.h
141 test -f parse4.h
143 # Now remake all the headers together.
145 rm -f $headers
146 $MAKE $headers
147 test -f parse1.h
148 test -f p2-parse2.h
149 test -f parse3.h
150 test -f parse4.h
152 # Most headers should be remade by "make all".
154 rm -f $headers
155 $MAKE all
156 test -f parse1.h
157 test -f p2-parse2.h
158 test -f parse3.h
159 # parse4.h is not declared in any *_SOURCES variable, nor #included
160 # by any C source file, so it shouldn't be rebuilt by "make all".
161 test ! -e parse4.h