readme: fixlets to HACKING
[automake.git] / t / yacc-d-basic.sh
blob72872f24f42a894279e693f048c5942eec818c71
1 #! /bin/sh
2 # Copyright (C) 2011-2012 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.test'.
21 required='cc yacc'
22 . ./defs || exit 1
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, in bar/parse.y, use
63 # y.tab.h instead of parse.c.
64 sed -e 's/parse\.h/y.tab.h/' <foo/parse.y >bar/parse.y
66 cat > foo/main.c << 'END'
67 #include "parse.h"
68 int main ()
70 return yyparse ();
72 END
73 cp foo/main.c bar/main.c
75 # Even the generated header file is renamed when target-specific YFLAGS
76 # are used. This might not be the best behavior, but it has been in
77 # place for quite a long time, so just go along with it for now.
78 sed 's/"parse\.h"/"zardoz-parse.h"/' foo/parse.y > baz/parse.y
79 sed 's/"parse\.h"/"zardoz-parse.h"/' foo/main.c > baz/main.c
81 $ACLOCAL
82 $AUTOCONF
84 $AUTOMAKE -a
85 $FGREP parse.h foo/Makefile.in bar/Makefile.in baz/Makefile.in && exit 1
87 cat >> foo/Makefile.am <<END
88 BUILT_SOURCES = parse.h
89 YFLAGS=\
91 END
92 $AUTOMAKE -Wno-gnu foo/Makefile
94 sed 's/EOL$//' >> bar/Makefile.am <<END
95 AM_YFLAGS${tab}= -d EOL
96 BUILT_SOURCES = parse.h
97 END
98 $AUTOMAKE bar/Makefile
100 cat >> baz/Makefile.am <<END
101 BUILT_SOURCES = zardoz-parse.h
102 zardoz_YFLAGS =-d${tab}
104 $AUTOMAKE baz/Makefile
106 ./configure
108 $MAKE
110 test -f foo/parse.c
111 test -f foo/parse.h
112 test -f bar/parse.c
113 test -f bar/parse.h
114 test -f baz/zardoz-parse.c
115 test -f baz/zardoz-parse.h
117 # The generated C source and header files must be shipped.
118 for dir in foo bar; do
119 cd $dir
120 $MAKE echo-distcom
121 $MAKE -s echo-distcom | grep '[ /]parse.c '
122 $MAKE -s echo-distcom | grep '[ /]parse.h '
123 cd ..
124 done
125 cd baz
126 $MAKE echo-distcom
127 $MAKE -s echo-distcom | grep '[ /]zardoz-parse.c '
128 $MAKE -s echo-distcom | grep '[ /]zardoz-parse.h '
129 cd ..
131 $MAKE distdir
132 ls -l $distdir
133 test -f $distdir/foo/parse.c
134 test -f $distdir/foo/parse.h
135 test -f $distdir/bar/parse.c
136 test -f $distdir/bar/parse.h
137 test -f $distdir/baz/zardoz-parse.c
138 test -f $distdir/baz/zardoz-parse.h
140 # Sanity check the distribution.
141 yl_distcheck
143 # While we are at it, make sure that 'parse.c' and 'parse.h' are erased
144 # by maintainer-clean, and not by distclean.
145 $MAKE distclean
146 test -f foo/parse.c
147 test -f foo/parse.h
148 test -f bar/parse.c
149 test -f bar/parse.h
150 test -f baz/zardoz-parse.c
151 test -f baz/zardoz-parse.h
152 ./configure # Re-create 'Makefile'.
153 $MAKE maintainer-clean
154 test ! -e foo/parse.c
155 test ! -e foo/parse.h
156 test ! -e bar/parse.c
157 test ! -e bar/parse.h
158 test ! -e baz/zardoz-parse.c
159 test ! -e baz/zardoz-parse.h