automake: recognize all-numeric MAJ.MIN.MICROa.ALPHA versions better.
[automake.git] / t / yacc-d-cxx.sh
blob556977c220f9ac43f58e0d51cd05f174e15e7085
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 # 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 // Include C header to provide global symbols that flex assumes.
30 // https://bugs.gnu.org/20031
31 #include <stdlib.h>
32 // Valid C++, but deliberately invalid C.
33 #include <cstdlib>
34 using std::exit;
35 using std::free;
36 using std::malloc;
37 #include "$header"
38 #if (defined __cplusplus) && ((!defined __sun) || (defined __EXTERN_C__))
39 extern "C" {
40 #endif
41 int yylex (void) { return 0; }
42 void yyerror (const char *s) {}
43 #if (defined __cplusplus) && ((!defined __sun) || (defined __EXTERN_C__))
45 #endif
48 x : 'x' {};
50 END
53 write_main ()
55 header=$1
56 unindent <<END
57 // Valid C++, but deliberately invalid C.
58 #include <cstdio>
59 #include "$header"
60 int main (int argc, char **argv)
62 int yyparse (void);
63 return yyparse ();
65 END
68 cat >> configure.ac << 'END'
69 AC_PROG_CXX
70 AC_PROG_YACC
71 AC_CONFIG_FILES([foo/Makefile bar/Makefile baz/Makefile qux/Makefile])
72 AC_OUTPUT
73 END
75 mkdir foo bar baz qux baz/sub
77 # These makefiles will be extended later.
78 cat > Makefile.am <<'END'
79 AM_LFLAGS = --never-interactive
81 .PHONY: echo-distcom
82 echo-distcom:
83 @echo ' ' $(DIST_COMMON) ' '
84 END
85 cp Makefile.am foo/Makefile.am
86 cp Makefile.am bar/Makefile.am
87 cp Makefile.am baz/Makefile.am
88 cp Makefile.am qux/Makefile.am
90 cat >> Makefile.am <<'END'
91 SUBDIRS = foo bar baz qux
92 END
94 $ACLOCAL
95 $AUTOCONF
97 cp "$am_scriptdir/ylwrap" . \
98 || fatal_ "cannot fetch auxiliary script 'ylwrap'"
100 $AUTOMAKE Makefile
102 # Try with -d in $(YFLAGS) (don't do this in real life!).
103 cat >> foo/Makefile.am <<END
104 bin_PROGRAMS = zardoz
105 zardoz_SOURCES = parse.yy main.cc
106 BUILT_SOURCES = parse.hh
107 YFLAGS=\
111 $AUTOMAKE -Wno-gnu foo/Makefile
113 write_parse parse.hh > foo/parse.yy
114 write_main parse.hh > foo/main.cc
116 # Try with -d in $(AM_YFLAGS).
117 cat >> bar/Makefile.am <<END
118 bin_PROGRAMS = zardoz
119 zardoz_SOURCES = parse.ypp main.cpp
120 BUILT_SOURCES = parse.hpp
121 AM_YFLAGS${tab}= -d ${tab}
124 $AUTOMAKE bar/Makefile
126 write_parse parse.hpp > bar/parse.ypp
127 write_main parse.hpp > bar/main.cpp
129 # Try with -d in $(AM_YFLAGS), and a subdir parser.
130 cat >> baz/Makefile.am <<END
131 AUTOMAKE_OPTIONS = subdir-objects
132 bin_PROGRAMS = joe
133 joe_SOURCES = sub/parse.y++ sub/main.c++
134 BUILT_SOURCES = sub/parse.h++
135 AM_YFLAGS = \
136 ${tab}-d
139 $AUTOMAKE baz/Makefile
141 write_parse sub/parse.h++ > baz/sub/parse.y++
142 write_main sub/parse.h++ > baz/sub/main.c++
144 # Try with -d in $(xxx_YFLAGS) (per-object flag).
145 cat >> qux/Makefile.am <<END
146 bin_PROGRAMS = maude
147 maude_SOURCES = parse.yxx main.cxx
148 maude_YFLAGS=${tab} -d${tab}
149 BUILT_SOURCES = maude-parse.hxx
152 $AUTOMAKE qux/Makefile
154 write_parse maude-parse.hxx > qux/parse.yxx
155 write_main maude-parse.hxx > qux/main.cxx
157 ./configure
159 $MAKE
160 ls -l . foo bar baz baz/sub qux # For debugging.
162 test -f foo/parse.cc
163 test -f foo/parse.hh
164 test -f bar/parse.cpp
165 test -f bar/parse.hpp
166 test -f baz/sub/parse.c++
167 test -f baz/sub/parse.h++
168 test -f qux/maude-parse.cxx
169 test -f qux/maude-parse.hxx
171 # The ylwrap script must be shipped.
172 $MAKE echo-distcom
173 $MAKE -s echo-distcom | grep '[ /]ylwrap '
175 # The generated C++ source and header files must be shipped.
176 cd foo
177 $MAKE echo-distcom
178 $MAKE -s echo-distcom | grep '[ /]parse\.cc '
179 $MAKE -s echo-distcom | grep '[ /]parse\.hh '
180 cd ..
181 cd bar
182 $MAKE echo-distcom
183 $MAKE -s echo-distcom | grep '[ /]parse\.cpp '
184 $MAKE -s echo-distcom | grep '[ /]parse\.hpp '
185 cd ..
186 cd baz
187 $MAKE echo-distcom
188 $MAKE -s echo-distcom | grep '[ /]sub/parse\.c++ '
189 $MAKE -s echo-distcom | grep '[ /]sub/parse\.h++ '
190 cd ..
191 cd qux
192 $MAKE echo-distcom
193 $MAKE -s echo-distcom | grep '[ /]maude-parse\.cxx '
194 $MAKE -s echo-distcom | grep '[ /]maude-parse\.hxx '
195 cd ..
197 $MAKE distdir
198 find $distdir # For debugging.
200 test -f $distdir/ylwrap
201 test -f $distdir/foo/parse.cc
202 test -f $distdir/foo/parse.hh
203 test -f $distdir/bar/parse.cpp
204 test -f $distdir/bar/parse.hpp
205 test -f $distdir/baz/sub/parse.c++
206 test -f $distdir/baz/sub/parse.h++
207 test -f $distdir/qux/maude-parse.cxx
208 test -f $distdir/qux/maude-parse.hxx
210 # The Yacc-derived C++ sources must be created, and not removed once
211 # compiled (i.e., not treated like "intermediate files" in the GNU
212 # make sense).
213 yl_distcheck
215 # Check that we can recover from deleted headers.
216 $MAKE clean
217 rm -f foo/parse.hh bar/parse.hpp baz/sub/parse.h++ qux/maude-parse.hxx
218 $MAKE
219 test -f foo/parse.hh
220 test -f bar/parse.hpp
221 test -f baz/sub/parse.h++
222 test -f qux/maude-parse.hxx
224 # Make sure that the Yacc-derived C++ sources are erased by
225 # maintainer-clean, and not by distclean.
226 $MAKE distclean
227 test -f foo/parse.cc
228 test -f foo/parse.hh
229 test -f bar/parse.cpp
230 test -f bar/parse.hpp
231 test -f baz/sub/parse.c++
232 test -f baz/sub/parse.h++
233 test -f qux/maude-parse.cxx
234 test -f qux/maude-parse.hxx
235 ./configure # Re-create 'Makefile'.
236 $MAKE maintainer-clean
237 test ! -e foo/parse.cc
238 test ! -e foo/parse.hh
239 test ! -e bar/parse.cpp
240 test ! -e bar/parse.hpp
241 test ! -e baz/sub/parse.c++
242 test ! -e baz/sub/parse.h++
243 test ! -e qux/maude-parse.cxx
244 test ! -e qux/maude-parse.hxx