Merge branch 'fix-pr13588-pax-hangs' into branch-1.13.2
[automake.git] / t / yacc-d-basic.sh
blob929185c1fa29e5049058fcd713b52f50e8fb393c
1 #! /bin/sh
2 # Copyright (C) 2011-2013 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 <http://www.gnu.org/licenses/>.
17 # Tests Yacc support with yacc-generated headers
18 # (i.e., '-d' in *YFLAGS).
19 # Keep in sync with sister test 'yacc-d-cxx.sh'.
21 required='cc yacc'
22 . test-init.sh
24 cat >> configure.ac << 'END'
25 AC_PROG_CC
26 AC_PROG_YACC
27 AC_CONFIG_FILES([foo/Makefile bar/Makefile baz/Makefile])
28 AC_OUTPUT
29 END
31 cat > Makefile.am <<'END'
32 SUBDIRS = foo bar baz
33 END
35 mkdir foo bar baz
37 cat > foo/Makefile.am <<'END'
38 bin_PROGRAMS = zardoz
39 zardoz_SOURCES = parse.y main.c
40 .PHONY: echo-distcom
41 echo-distcom:
42 @echo ' ' $(DIST_COMMON) ' '
43 END
44 cp foo/Makefile.am bar/Makefile.am
45 cp foo/Makefile.am baz/Makefile.am
47 cat > foo/parse.y << 'END'
49 #include "parse.h"
50 int yylex () { return 0; }
51 void yyerror (char *s) {}
54 x : 'x' {};
56 END
57 # Using ylwrap, we actually generate y.tab.[ch]. Unfortunately, we
58 # forgot to rename #include "y.tab.h" into #include "parse.h" during
59 # the conversion from y.tab.c to parse.c. This was OK when Bison was
60 # not issuing such an #include (up to 2.6).
62 # To make sure that we perform this conversion even with version of
63 # Bison that do not generate this include, in bar/parse.y, use y.tab.h
64 # instead of parse.h, and check the ylwrap does replace "y.tab.h" with
65 # "parse.h".
66 sed -e 's/parse\.h/y.tab.h/' <foo/parse.y >bar/parse.y
68 cat > foo/main.c << 'END'
69 #include "parse.h"
70 int main ()
72 return yyparse ();
74 END
75 cp foo/main.c bar/main.c
77 # Even the generated header file is renamed when target-specific YFLAGS
78 # are used. This might not be the best behavior, but it has been in
79 # place for quite a long time, so just go along with it for now.
80 sed 's/"parse\.h"/"zardoz-parse.h"/' foo/parse.y > baz/parse.y
81 sed 's/"parse\.h"/"zardoz-parse.h"/' foo/main.c > baz/main.c
83 $ACLOCAL
84 $AUTOCONF
86 $AUTOMAKE -a
87 $FGREP parse.h foo/Makefile.in bar/Makefile.in baz/Makefile.in && exit 1
89 cat >> foo/Makefile.am <<END
90 BUILT_SOURCES = parse.h
91 YFLAGS=\
93 END
94 $AUTOMAKE -Wno-gnu foo/Makefile
96 sed 's/EOL$//' >> bar/Makefile.am <<END
97 AM_YFLAGS${tab}= -d EOL
98 BUILT_SOURCES = parse.h
99 END
100 $AUTOMAKE bar/Makefile
102 cat >> baz/Makefile.am <<END
103 BUILT_SOURCES = zardoz-parse.h
104 zardoz_YFLAGS =-d${tab}
106 $AUTOMAKE baz/Makefile
108 ./configure
110 $MAKE
112 generated="
113 foo/parse.c
114 foo/parse.h
115 bar/parse.c
116 bar/parse.h
117 baz/zardoz-parse.c
118 baz/zardoz-parse.h
121 for i in $generated; do
122 test -f $i
123 done
125 # There must remain no obsolete header guard.
126 grep Y_TAB_H $generated && exit 1
128 # The generated C source and header files must be shipped.
129 for dir in foo bar; do
130 cd $dir
131 $MAKE echo-distcom
132 $MAKE -s echo-distcom | grep '[ /]parse.c '
133 $MAKE -s echo-distcom | grep '[ /]parse.h '
134 cd ..
135 done
136 cd baz
137 $MAKE echo-distcom
138 $MAKE -s echo-distcom | grep '[ /]zardoz-parse.c '
139 $MAKE -s echo-distcom | grep '[ /]zardoz-parse.h '
140 cd ..
142 $MAKE distdir
143 ls -l $distdir
144 for i in $generated; do
145 test -f $distdir/$i
146 done
148 # Sanity check the distribution.
149 yl_distcheck
151 # While we are at it, make sure that 'parse.c' and 'parse.h' are erased
152 # by maintainer-clean, and not by distclean.
153 $MAKE distclean
154 for i in $generated; do
155 test -f $i
156 done
157 ./configure # Re-create 'Makefile'.
158 $MAKE maintainer-clean
159 for i in $generated; do
160 test ! -e $i
161 done