doc: typos in test file.
[automake.git] / t / yacc-mix-c-cxx.sh
blobd454fe244ebe2af95add117eebc8c681963f5d75
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 # Check that many different Yacc parsers (both C and C++) can co-exists
18 # in the same directory.
20 required='cc c++ yacc'
21 . test-init.sh
23 cat >> configure.ac << 'END'
24 AC_PROG_CC
25 AC_PROG_CXX
26 AC_PROG_YACC
27 AC_OUTPUT
28 END
30 cat > Makefile.am << 'END'
31 AM_LFLAGS = --never-interactive
33 bin_PROGRAMS = c1 c2 cxx1 cxx2 cxx3
34 AM_YFLAGS = -d
36 c1_SOURCES = p.y p.h 1.c
37 c2_SOURCES = p.y 2.c
38 c2_YFLAGS =
40 cxx1_SOURCES = parse.yy main1.cc parse.hh
42 cxx2_SOURCES = parse2.y++ main2.c++
43 cxx2_YFLAGS =
45 cxx3_SOURCES = parse3.yxx main3.cxx
47 BUILT_SOURCES = p.h parse.hh parse3.hxx
48 END
50 # The content of all the .c and .y files created below is valid C but
51 # deliberately invalid C++.
52 # Vice versa, the content of all the .c++, .cxx, .cc, .y++, .yxx and
53 # .yy files created below is valid C++ but deliberately invalid C.
55 cat > p.y <<'END'
57 #if (defined __cplusplus) && ((!defined __sun) || (defined __EXTERN_C__))
58 extern "C" {
59 #endif
60 int yylex (void) { int new = 0; return new; }
61 void yyerror (const char *s) {}
62 #if (defined __cplusplus) && ((!defined __sun) || (defined __EXTERN_C__))
64 #endif
66 %token ZARDOZ
68 x : 'x' {};
70 END
72 cat > 1.c <<'END'
73 #include "p.h"
74 int main ()
76 int new = ZARDOZ;
77 return yyparse () + new;
80 END
82 cat > 2.c <<'END'
83 int main ()
85 int yyparse ();
86 int new = 0;
87 return yyparse () + new;
89 END
91 cat > parse.yy <<'END'
93 // Include C header to provide global symbols that flex assumes.
94 // https://bugs.gnu.org/20031
95 #include <stdlib.h>
96 // Valid C++, but deliberately invalid C.
97 #include <cstdlib>
98 using std::exit;
99 using std::free;
100 using std::malloc;
101 #include "parse.hh"
102 #if (defined __cplusplus) && ((!defined __sun) || (defined __EXTERN_C__))
103 extern "C" {
104 #endif
105 int yylex (void) { return 0; }
106 void yyerror (const char *s) {}
107 #if (defined __cplusplus) && ((!defined __sun) || (defined __EXTERN_C__))
109 #endif
111 %token FOOBAR
113 x : 'x' {};
117 cat > parse2.y++ <<'END'
119 #include <cstdlib>
120 int yylex (void) { return 0; }
121 void yyerror (const char *s) {}
124 x : 'x' {};
128 cat > main1.cc <<'END'
129 using namespace std;
130 #include "parse.hh"
131 int main (int argc, char **argv)
133 int yyparse (void);
134 return yyparse () + FOOBAR;
138 cat > main2.c++ <<'END'
139 using namespace std;
140 int main (int argc, char **argv)
142 int yyparse (void);
143 return yyparse ();
147 edit () { sed -e 's/FOOBAR/BAZQUUX/' -e 's/"parse\.hh"/"parse3.hxx"/'; }
148 edit <parse.yy >parse3.yxx
149 edit <main1.cc >main3.cxx
151 $ACLOCAL
152 $AUTOCONF
153 $AUTOMAKE -a
155 # Try a VPATH and by default serial build first, and then an in-tree
156 # and by default parallel build.
158 for try in 0 1; do
160 if test $try -eq 0; then
161 # VPATH serial build.
162 mkdir build
163 cd build
164 srcdir=..
165 debug_info="ls -l . $srcdir"
166 run_make=$MAKE
167 elif test $try -eq 1; then
168 # In-tree parallel build.
169 srcdir=.
170 debug_info="ls -l"
171 case $MAKE in
172 *\ -j*)
173 # Degree of parallelism already specified by the user: do
174 # not override it.
175 run_make=$MAKE;;
177 # Some make implementations (e.g., HP-UX) don't grok '-j',
178 # some require no space between '-j' and the number of jobs
179 # (e.g., older GNU make versions), and some *do* require a
180 # space between '-j' and the number of jobs (e.g., Solaris
181 # dmake). We need a runtime test to see what works.
182 echo 'all:' > Makefile
183 for run_make in "$MAKE -j3" "$MAKE -j 3" "$MAKE"; do
184 $run_make && break
185 done
186 rm -f Makefile
187 esac
188 else
189 echo "$me: invalid value of \$try '$try'" >&2
190 exit 99
193 $srcdir/configure
195 $run_make
196 $debug_info
198 test -f p.c
199 test -f p.h
200 test -f c2-p.c
201 test ! -e c2-p.h
203 test -f parse.cc
204 test -f parse.hh
205 test -f parse3.cxx
206 test -f parse3.hxx
208 test -f cxx2-parse2.c++
209 test ! -e parse2.h++
210 test ! -e cxx2-parse2.h++
212 # Minimal checks about recovering from header removal.
213 rm -f p.h parse.hh parse3.hxx
214 $run_make p.h parse.hh
215 $debug_info
216 test -f p.h
217 test -f parse.hh
218 test ! -e parse3.hxx
219 $run_make
220 $debug_info
221 test -f parse3.hxx
223 cd $srcdir
225 done