am-ft: make the environment available earlier
[platform/upstream/automake.git] / t / yacc-mix-c-cxx.sh
1 #! /bin/sh
2 # Copyright (C) 2011-2013 Free Software Foundation, Inc.
3 #
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.
8 #
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.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17 # Check that many different Yacc parsers (both C and C++) can co-exists
18 # in the same directory.
19
20 required='cc c++ yacc'
21 . test-init.sh
22
23 cat >> configure.ac << 'END'
24 AC_PROG_CC
25 AC_PROG_CXX
26 AC_PROG_YACC
27 AC_OUTPUT
28 END
29
30 cat > Makefile.am << 'END'
31 bin_PROGRAMS = c1 c2 cxx1 cxx2 cxx3
32 AM_YFLAGS = -d
33
34 c1_SOURCES = p.y p.h 1.c
35 c2_SOURCES = p.y 2.c
36 c2_YFLAGS =
37
38 cxx1_SOURCES = parse.yy main1.cc parse.hh
39
40 cxx2_SOURCES = parse2.y++ main2.c++
41 cxx2_YFLAGS =
42
43 cxx3_SOURCES = parse3.yxx main3.cxx
44
45 BUILT_SOURCES = p.h parse.hh parse3.hxx
46 END
47
48 # The content of all the .c and .y files created below is valid C but
49 # deliberately invalid C++.
50 # Vice versa, the content of all the .c++, .cxx, .cc, .y++, .yxx and
51 # .yy files created below is valid C++ but deliberately invalid C.
52
53 cat > p.y <<'END'
54 %{
55 int yylex (void) { int new = 0; return new; }
56 void yyerror (char *s) { return; }
57 %}
58 %token ZARDOZ
59 %%
60 x : 'x' {};
61 %%
62 END
63
64 cat > 1.c <<'END'
65 #include "p.h"
66 int main ()
67 {
68     int new = ZARDOZ;
69     return yyparse () + new;
70 }
71
72 END
73
74 cat > 2.c <<'END'
75 int main ()
76 {
77     int yyparse ();
78     int new = 0;
79     return yyparse () + new;
80 }
81 END
82
83 cat > parse.yy <<'END'
84 %{
85 #include <cstdlib>
86 #include "parse.hh"
87 int yylex (void) { return 0; }
88 void yyerror (const char *s) { return; }
89 %}
90 %token FOOBAR
91 %%
92 x : 'x' {};
93 %%
94 END
95
96 cat > parse2.y++ <<'END'
97 %{
98 #include <cstdlib>
99 int yylex (void) { return 0; }
100 void yyerror (const char *s) { return; }
101 %}
102 %%
103 x : 'x' {};
104 %%
105 END
106
107 cat > main1.cc <<'END'
108 using namespace std;
109 #include "parse.hh"
110 int main (int argc, char **argv)
111 {
112     int yyparse (void);
113     return yyparse () + FOOBAR;
114 }
115 END
116
117 cat > main2.c++ <<'END'
118 using namespace std;
119 int main (int argc, char **argv)
120 {
121     int yyparse (void);
122     return yyparse ();
123 }
124 END
125
126 edit () { sed -e 's/FOOBAR/BAZQUUX/' -e 's/"parse\.hh"/"parse3.hxx"/'; }
127 edit <parse.yy >parse3.yxx
128 edit <main1.cc >main3.cxx
129
130 $ACLOCAL
131 $AUTOCONF
132 $AUTOMAKE -a
133
134 # Try a VPATH and by default serial build first, and then an in-tree
135 # and by default parallel build.
136
137 for try in 0 1; do
138
139   if test $try -eq 0; then
140     # VPATH serial build.
141     mkdir build
142     cd build
143     srcdir=..
144     debug_info="ls -l . $srcdir"
145     run_make=$MAKE
146   elif test $try -eq 1; then
147     # In-tree parallel build.
148     srcdir=.
149     debug_info="ls -l"
150     case $MAKE in
151       *\ -j*)
152         # Degree of parallelism already specified by the user: do
153         # not override it.
154         run_make=$MAKE;;
155       *)
156         # Some make implementations (e.g., HP-UX) don't grok '-j',
157         # some require no space between '-j' and the number of jobs
158         # (e.g., older GNU make versions), and some *do* require a
159         # space between '-j' and the number of jobs (e.g., Solaris
160         # dmake).  We need a runtime test to see what works.
161         echo 'all:' > Makefile
162         for run_make in "$MAKE -j3" "$MAKE -j 3" "$MAKE"; do
163           $run_make && break
164         done
165         rm -f Makefile
166     esac
167   else
168     echo "$me: invalid value of \$try '$try'" >&2
169     exit 99
170   fi
171
172   $srcdir/configure
173
174   $run_make
175   $debug_info
176
177   test -f p.c
178   test -f p.h
179   test -f c2-p.c
180   test ! -e c2-p.h
181
182   test -f parse.cc
183   test -f parse.hh
184   test -f parse3.cxx
185   test -f parse3.hxx
186
187   test -f cxx2-parse2.c++
188   test ! -e parse2.h++
189   test ! -e cxx2-parse2.h++
190
191   # Minimal checks about recovering from header removal.
192   rm -f p.h parse.hh parse3.hxx
193   $run_make p.h parse.hh
194   $debug_info
195   test -f p.h
196   test -f parse.hh
197   test ! -e parse3.hxx
198   $run_make
199   $debug_info
200   test -f parse3.hxx
201
202   cd $srcdir
203
204 done
205
206 :