Merge branch 'minor'
[automake.git] / t / yacc-d-cxx.sh
blobc6452a3ad6adfe5428dc3258c411cd4dbccd7bd2
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 # Various tests on Yacc/C++ support with yacc-generated headers
18 # (i.e., '-d' in *YFLAGS).
19 # Keep in sync with sister test 'yacc-d-basic.sh'.
21 required='c++ yacc'
22 . test-init.sh
24 write_parse ()
26 header=$1
27 unindent <<END
29 // Valid C++, but deliberately invalid C.
30 #include <cstdlib>
31 #include "$header"
32 int yylex (void) { return 0; }
33 void yyerror (const char *s) {}
36 x : 'x' {};
38 END
41 write_main ()
43 header=$1
44 unindent <<END
45 // Valid C++, but deliberately invalid C.
46 #include <cstdio>
47 #include "$header"
48 int main (int argc, char **argv)
50 int yyparse (void);
51 return yyparse ();
53 END
56 cat >> configure.ac << 'END'
57 AC_PROG_CXX
58 AC_PROG_YACC
59 AC_CONFIG_FILES([foo/Makefile bar/Makefile baz/Makefile qux/Makefile])
60 AC_OUTPUT
61 END
63 mkdir foo bar baz qux baz/sub
65 # These makefiles will be extended later.
66 cat > Makefile.am <<'END'
67 .PHONY: echo-distcom
68 echo-distcom:
69 @echo ' ' $(DIST_COMMON) ' '
70 END
71 cp Makefile.am foo/Makefile.am
72 cp Makefile.am bar/Makefile.am
73 cp Makefile.am baz/Makefile.am
74 cp Makefile.am qux/Makefile.am
76 cat >> Makefile.am <<'END'
77 SUBDIRS = foo bar baz qux
78 END
80 $ACLOCAL
81 $AUTOCONF
83 cp "$am_scriptdir/ylwrap" . \
84 || fatal_ "cannot fetch auxiliary script 'ylwrap'"
86 $AUTOMAKE Makefile
88 # Try with -d in $(YFLAGS) (don't do this in real life!).
89 cat >> foo/Makefile.am <<END
90 bin_PROGRAMS = zardoz
91 zardoz_SOURCES = parse.yy main.cc
92 BUILT_SOURCES = parse.hh
93 YFLAGS=\
95 END
97 $AUTOMAKE -Wno-gnu foo/Makefile
99 write_parse parse.hh > foo/parse.yy
100 write_main parse.hh > foo/main.cc
102 # Try with -d in $(AM_YFLAGS).
103 cat >> bar/Makefile.am <<END
104 bin_PROGRAMS = zardoz
105 zardoz_SOURCES = parse.ypp main.cpp
106 BUILT_SOURCES = parse.hpp
107 AM_YFLAGS${tab}= -d ${tab}
110 $AUTOMAKE bar/Makefile
112 write_parse parse.hpp > bar/parse.ypp
113 write_main parse.hpp > bar/main.cpp
115 # Try with -d in $(AM_YFLAGS), and a subdir parser.
116 cat >> baz/Makefile.am <<END
117 AUTOMAKE_OPTIONS = subdir-objects
118 bin_PROGRAMS = joe
119 joe_SOURCES = sub/parse.y++ sub/main.c++
120 BUILT_SOURCES = sub/parse.h++
121 AM_YFLAGS = \
122 ${tab}-d
125 $AUTOMAKE baz/Makefile
127 write_parse sub/parse.h++ > baz/sub/parse.y++
128 write_main sub/parse.h++ > baz/sub/main.c++
130 # Try with -d in $(xxx_YFLAGS) (per-object flag).
131 cat >> qux/Makefile.am <<END
132 bin_PROGRAMS = maude
133 maude_SOURCES = parse.yxx main.cxx
134 maude_YFLAGS=${tab} -d${tab}
135 BUILT_SOURCES = maude-parse.hxx
138 $AUTOMAKE qux/Makefile
140 write_parse maude-parse.hxx > qux/parse.yxx
141 write_main maude-parse.hxx > qux/main.cxx
143 ./configure
145 $MAKE
146 ls -l . foo bar baz baz/sub qux # For debugging.
148 test -f foo/parse.cc
149 test -f foo/parse.hh
150 test -f bar/parse.cpp
151 test -f bar/parse.hpp
152 test -f baz/sub/parse.c++
153 test -f baz/sub/parse.h++
154 test -f qux/maude-parse.cxx
155 test -f qux/maude-parse.hxx
157 # The ylwrap script must be shipped.
158 $MAKE echo-distcom
159 $MAKE -s echo-distcom | grep '[ /]ylwrap '
161 # The generated C++ source and header files must be shipped.
162 cd foo
163 $MAKE echo-distcom
164 $MAKE -s echo-distcom | grep '[ /]parse\.cc '
165 $MAKE -s echo-distcom | grep '[ /]parse\.hh '
166 cd ..
167 cd bar
168 $MAKE echo-distcom
169 $MAKE -s echo-distcom | grep '[ /]parse\.cpp '
170 $MAKE -s echo-distcom | grep '[ /]parse\.hpp '
171 cd ..
172 cd baz
173 $MAKE echo-distcom
174 $MAKE -s echo-distcom | grep '[ /]sub/parse\.c++ '
175 $MAKE -s echo-distcom | grep '[ /]sub/parse\.h++ '
176 cd ..
177 cd qux
178 $MAKE echo-distcom
179 $MAKE -s echo-distcom | grep '[ /]maude-parse\.cxx '
180 $MAKE -s echo-distcom | grep '[ /]maude-parse\.hxx '
181 cd ..
183 $MAKE distdir
184 find $distdir # For debugging.
186 test -f $distdir/ylwrap
187 test -f $distdir/foo/parse.cc
188 test -f $distdir/foo/parse.hh
189 test -f $distdir/bar/parse.cpp
190 test -f $distdir/bar/parse.hpp
191 test -f $distdir/baz/sub/parse.c++
192 test -f $distdir/baz/sub/parse.h++
193 test -f $distdir/qux/maude-parse.cxx
194 test -f $distdir/qux/maude-parse.hxx
196 # The Yacc-derived C++ sources must be created, and not removed once
197 # compiled (i.e., not treated like "intermediate files" in the GNU
198 # make sense).
199 yl_distcheck
201 # Check that we can recover from deleted headers.
202 $MAKE clean
203 rm -f foo/parse.hh bar/parse.hpp baz/sub/parse.h++ qux/maude-parse.hxx
204 $MAKE
205 test -f foo/parse.hh
206 test -f bar/parse.hpp
207 test -f baz/sub/parse.h++
208 test -f qux/maude-parse.hxx
210 # Make sure that the Yacc-derived C++ sources are erased by
211 # maintainer-clean, and not by distclean.
212 $MAKE distclean
213 test -f foo/parse.cc
214 test -f foo/parse.hh
215 test -f bar/parse.cpp
216 test -f bar/parse.hpp
217 test -f baz/sub/parse.c++
218 test -f baz/sub/parse.h++
219 test -f qux/maude-parse.cxx
220 test -f qux/maude-parse.hxx
221 ./configure # Re-create 'Makefile'.
222 $MAKE maintainer-clean
223 test ! -e foo/parse.cc
224 test ! -e foo/parse.hh
225 test ! -e bar/parse.cpp
226 test ! -e bar/parse.hpp
227 test ! -e baz/sub/parse.c++
228 test ! -e baz/sub/parse.h++
229 test ! -e qux/maude-parse.cxx
230 test ! -e qux/maude-parse.hxx