maint: it seems APIVERSION only changes for minor/major releases.
[automake.git] / t / yacc-mix-c-cxx.sh
blob021b4223ddb2ff01653fccc302149fee124f79a3
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 extern int yyparse (void);
75 int main ()
77 int new = ZARDOZ;
78 return yyparse () + new;
81 END
83 cat > 2.c <<'END'
84 extern int yyparse (void);
85 int main ()
87 int yyparse ();
88 int new = 0;
89 return yyparse () + new;
91 END
93 cat > parse.yy <<'END'
95 // Include C header to provide global symbols that flex assumes.
96 // https://bugs.gnu.org/20031
97 #include <stdlib.h>
98 // Valid C++, but deliberately invalid C.
99 #include <cstdlib>
100 using std::exit;
101 using std::free;
102 using std::malloc;
103 #include "parse.hh"
104 #if (defined __cplusplus) && ((!defined __sun) || (defined __EXTERN_C__))
105 extern "C" {
106 #endif
107 int yylex (void) { return 0; }
108 void yyerror (const char *s) {}
109 #if (defined __cplusplus) && ((!defined __sun) || (defined __EXTERN_C__))
111 #endif
113 %token FOOBAR
115 x : 'x' {};
119 cat > parse2.y++ <<'END'
121 #include <cstdlib>
122 int yylex (void) { return 0; }
123 void yyerror (const char *s) {}
126 x : 'x' {};
130 cat > main1.cc <<'END'
131 using namespace std;
132 #include "parse.hh"
133 int main (int argc, char **argv)
135 int yyparse (void);
136 return yyparse () + FOOBAR;
140 cat > main2.c++ <<'END'
141 using namespace std;
142 int main (int argc, char **argv)
144 int yyparse (void);
145 return yyparse ();
149 edit () { sed -e 's/FOOBAR/BAZQUUX/' -e 's/"parse\.hh"/"parse3.hxx"/'; }
150 edit <parse.yy >parse3.yxx
151 edit <main1.cc >main3.cxx
153 $ACLOCAL
154 $AUTOCONF
155 $AUTOMAKE -a
157 # Try a VPATH and by default serial build first, and then an in-tree
158 # and by default parallel build.
160 for try in 0 1; do
162 if test $try -eq 0; then
163 # VPATH serial build.
164 mkdir build
165 cd build
166 srcdir=..
167 debug_info="ls -l . $srcdir"
168 run_make=$MAKE
169 elif test $try -eq 1; then
170 # In-tree parallel build.
171 srcdir=.
172 debug_info="ls -l"
173 case $MAKE in
174 *\ -j*)
175 # Degree of parallelism already specified by the user: do
176 # not override it.
177 run_make=$MAKE;;
179 # Some make implementations (e.g., HP-UX) don't grok '-j',
180 # some require no space between '-j' and the number of jobs
181 # (e.g., older GNU make versions), and some *do* require a
182 # space between '-j' and the number of jobs (e.g., Solaris
183 # dmake). We need a runtime test to see what works.
184 echo 'all:' > Makefile
185 for run_make in "$MAKE -j3" "$MAKE -j 3" "$MAKE"; do
186 $run_make && break
187 done
188 rm -f Makefile
189 esac
190 else
191 echo "$me: invalid value of \$try '$try'" >&2
192 exit 99
195 $srcdir/configure
197 $run_make
198 $debug_info
200 test -f p.c
201 test -f p.h
202 test -f c2-p.c
203 test ! -e c2-p.h
205 test -f parse.cc
206 test -f parse.hh
207 test -f parse3.cxx
208 test -f parse3.hxx
210 test -f cxx2-parse2.c++
211 test ! -e parse2.h++
212 test ! -e cxx2-parse2.h++
214 # Minimal checks about recovering from header removal.
215 rm -f p.h parse.hh parse3.hxx
216 $run_make p.h parse.hh
217 $debug_info
218 test -f p.h
219 test -f parse.hh
220 test ! -e parse3.hxx
221 $run_make
222 $debug_info
223 test -f parse3.hxx
225 cd $srcdir
227 done