maint: run "make update-copyright"
[platform/upstream/automake.git] / tests / yacc-d-cxx.test
1 #! /bin/sh
2 # Copyright (C) 2011-2012 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 # 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.test'.
20
21 required=yacc
22 . ./defs || Exit 1
23
24 set -e
25
26 write_parse ()
27 {
28   header=$1
29   sed 's/^ *//' <<END
30     %{
31     // Valid C++, but deliberately invalid C.
32     #include <cstdlib>
33     #include "$header"
34     int yylex (void) { return 0; }
35     void yyerror (const char *s) {}
36     %}
37     %%
38     x : 'x' {};
39     %%
40 END
41 }
42
43 write_main ()
44 {
45   header=$1
46   sed 's/^ *//' <<END
47     // Valid C++, but deliberately invalid C.
48     #include <cstdio>
49     #include "$header"
50     int main (int argc, char **argv)
51     {
52       int yyparse (void);
53       return yyparse ();
54     }
55 END
56 }
57
58 cat >> configure.in << 'END'
59 AC_PROG_CXX
60 AC_PROG_YACC
61 AC_CONFIG_FILES([foo/Makefile bar/Makefile baz/Makefile qux/Makefile])
62 AC_OUTPUT
63 END
64
65 mkdir foo bar baz qux baz/sub
66
67 # These makefiles will be extended later.
68 cat > Makefile.am <<'END'
69 .PHONY: echo-distcom
70 echo-distcom:
71         @echo ' ' $(DIST_COMMON) ' '
72 END
73 cp Makefile.am foo/Makefile.am
74 cp Makefile.am bar/Makefile.am
75 cp Makefile.am baz/Makefile.am
76 cp Makefile.am qux/Makefile.am
77
78 cat >> Makefile.am <<'END'
79 SUBDIRS = foo bar baz qux
80 END
81
82 $ACLOCAL
83 $AUTOCONF
84
85 cp $testsrcdir/../lib/ylwrap .
86
87 $AUTOMAKE Makefile
88
89 # Try with -d in $(YFLAGS) (don't do this in real life!).
90 cat >> foo/Makefile.am <<END
91 bin_PROGRAMS = zardoz
92 zardoz_SOURCES = parse.yy main.cc
93 BUILT_SOURCES = parse.hh
94 YFLAGS=\
95 -d
96 END
97
98 $AUTOMAKE -Wno-gnu foo/Makefile
99
100 write_parse parse.hh > foo/parse.yy
101 write_main parse.hh > foo/main.cc
102
103 # Try with -d in $(AM_YFLAGS).
104 cat >> bar/Makefile.am <<END
105 bin_PROGRAMS = zardoz
106 zardoz_SOURCES = parse.ypp main.cpp
107 BUILT_SOURCES = parse.hpp
108 AM_YFLAGS${tab}=  -d ${tab}
109 END
110
111 $AUTOMAKE bar/Makefile
112
113 write_parse parse.hpp > bar/parse.ypp
114 write_main parse.hpp > bar/main.cpp
115
116 # Try with -d in $(AM_YFLAGS), and a subdir parser.
117 cat >> baz/Makefile.am <<END
118 AUTOMAKE_OPTIONS = subdir-objects
119 bin_PROGRAMS = joe
120 joe_SOURCES = sub/parse.y++ sub/main.c++
121 BUILT_SOURCES = sub/parse.h++
122 AM_YFLAGS = \
123 ${tab}-d
124 END
125
126 $AUTOMAKE baz/Makefile
127
128 write_parse sub/parse.h++ > baz/sub/parse.y++
129 write_main sub/parse.h++ > baz/sub/main.c++
130
131 # Try with -d in $(xxx_YFLAGS) (per-object flag).
132 cat >> qux/Makefile.am <<END
133 bin_PROGRAMS = maude
134 maude_SOURCES = parse.yxx main.cxx
135 maude_YFLAGS=${tab}  -d${tab}
136 BUILT_SOURCES = maude-parse.hxx
137 END
138
139 $AUTOMAKE qux/Makefile
140
141 write_parse maude-parse.hxx > qux/parse.yxx
142 write_main maude-parse.hxx > qux/main.cxx
143
144 ./configure
145
146 $MAKE
147 ls -l . foo bar baz baz/sub qux # For debugging.
148
149 test -f foo/parse.cc
150 test -f foo/parse.hh
151 test -f bar/parse.cpp
152 test -f bar/parse.hpp
153 test -f baz/sub/parse.c++
154 test -f baz/sub/parse.h++
155 test -f qux/maude-parse.cxx
156 test -f qux/maude-parse.hxx
157
158 # The ylwrap script must be shipped.
159 $MAKE echo-distcom
160 $MAKE -s echo-distcom | grep '[ /]ylwrap '
161
162 # The generated C++ source and header files must be shipped.
163 cd foo
164 $MAKE echo-distcom
165 $MAKE -s echo-distcom | grep '[ /]parse\.cc '
166 $MAKE -s echo-distcom | grep '[ /]parse\.hh '
167 cd ..
168 cd bar
169 $MAKE echo-distcom
170 $MAKE -s echo-distcom | grep '[ /]parse\.cpp '
171 $MAKE -s echo-distcom | grep '[ /]parse\.hpp '
172 cd ..
173 cd baz
174 $MAKE echo-distcom
175 $MAKE -s echo-distcom | grep '[ /]sub/parse\.c++ '
176 $MAKE -s echo-distcom | grep '[ /]sub/parse\.h++ '
177 cd ..
178 cd qux
179 $MAKE echo-distcom
180 $MAKE -s echo-distcom | grep '[ /]maude-parse\.cxx '
181 $MAKE -s echo-distcom | grep '[ /]maude-parse\.hxx '
182 cd ..
183
184 $MAKE distdir
185 find $distdir # For debugging.
186
187 test -f $distdir/ylwrap
188 test -f $distdir/foo/parse.cc
189 test -f $distdir/foo/parse.hh
190 test -f $distdir/bar/parse.cpp
191 test -f $distdir/bar/parse.hpp
192 test -f $distdir/baz/sub/parse.c++
193 test -f $distdir/baz/sub/parse.h++
194 test -f $distdir/qux/maude-parse.cxx
195 test -f $distdir/qux/maude-parse.hxx
196
197 # The Yacc-derived C++ sources must be created, and not removed once
198 # compiled (i.e., not treated like "intermediate files" in the GNU
199 # make sense).
200 yl_distcheck
201
202 # Check that we can recover from deleted headers.
203 $MAKE clean
204 rm -f foo/parse.hh bar/parse.hpp baz/sub/parse.h++ qux/maude-parse.hxx
205 $MAKE
206 test -f foo/parse.hh
207 test -f bar/parse.hpp
208 test -f baz/sub/parse.h++
209 test -f qux/maude-parse.hxx
210
211 # Make sure that the Yacc-derived C++ sources are erased by
212 # maintainer-clean, and not by distclean.
213 $MAKE distclean
214 test -f foo/parse.cc
215 test -f foo/parse.hh
216 test -f bar/parse.cpp
217 test -f bar/parse.hpp
218 test -f baz/sub/parse.c++
219 test -f baz/sub/parse.h++
220 test -f qux/maude-parse.cxx
221 test -f qux/maude-parse.hxx
222 ./configure # We must re-create `Makefile'.
223 $MAKE maintainer-clean
224 test ! -f foo/parse.cc
225 test ! -f foo/parse.hh
226 test ! -f bar/parse.cpp
227 test ! -f bar/parse.hpp
228 test ! -f baz/sub/parse.c++
229 test ! -f baz/sub/parse.h++
230 test ! -f qux/maude-parse.cxx
231 test ! -f qux/maude-parse.hxx
232
233 :