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)
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'.
29 // Include C header to provide global symbols that flex assumes.
30 // https://bugs.gnu.org/20031
32 // Valid C++, but deliberately invalid C.
38 #if (defined __cplusplus) && ((!defined __sun) || (defined __EXTERN_C__))
41 int yylex (void) { return 0; }
42 void yyerror (const char *s) {}
43 #if (defined __cplusplus) && ((!defined __sun) || (defined __EXTERN_C__))
57 // Valid C++, but deliberately invalid C.
60 int main (int argc, char **argv)
68 cat >> configure.ac
<< 'END'
71 AC_CONFIG_FILES
([foo
/Makefile bar
/Makefile baz
/Makefile qux
/Makefile
])
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
83 @echo ' ' $(DIST_COMMON) ' '
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
97 cp "$am_scriptdir/ylwrap" . \
98 || fatal_
"cannot fetch auxiliary script 'ylwrap'"
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
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
133 joe_SOURCES = sub/parse.y++ sub/main.c++
134 BUILT_SOURCES = sub/parse.h++
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
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
160 ls -l . foo bar baz baz
/sub qux
# For debugging.
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.
173 $MAKE -s echo-distcom |
grep '[ /]ylwrap '
175 # The generated C++ source and header files must be shipped.
178 $MAKE -s echo-distcom |
grep '[ /]parse\.cc '
179 $MAKE -s echo-distcom |
grep '[ /]parse\.hh '
183 $MAKE -s echo-distcom |
grep '[ /]parse\.cpp '
184 $MAKE -s echo-distcom |
grep '[ /]parse\.hpp '
188 $MAKE -s echo-distcom |
grep '[ /]sub/parse\.c++ '
189 $MAKE -s echo-distcom |
grep '[ /]sub/parse\.h++ '
193 $MAKE -s echo-distcom |
grep '[ /]maude-parse\.cxx '
194 $MAKE -s echo-distcom |
grep '[ /]maude-parse\.hxx '
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
215 # Check that we can recover from deleted headers.
217 rm -f foo
/parse.hh bar
/parse.hpp baz
/sub
/parse.h
++ qux
/maude-parse.hxx
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.
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