Merge branch 'maint'
[platform/upstream/automake.git] / t / yacc-cxx.sh
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 # Basic semantic checks on Yacc + C++ support (when yacc-generated
18 # headers are not involved).
19 # Keep in sync with sister test 'yacc-basic.test'.
20
21 required=yacc
22 . ./defs || Exit 1
23
24 cat >> configure.ac << 'END'
25 AC_PROG_CXX
26 AC_PROG_YACC
27 AC_OUTPUT
28 END
29
30 cat > Makefile.am << 'END'
31 bin_PROGRAMS = foo1 foo2 foo3 foo4
32 foo1_SOURCES = parse1.yy  foo.cc
33 foo2_SOURCES = parse2.y++ bar.c++
34 foo3_SOURCES = parse3.yxx foo.cc
35 foo4_SOURCES = parse4.ypp bar2.cxx
36 foo3_YFLAGS = -v
37 foo4_YFLAGS = $(foo3_YFLAGS)
38
39 .PHONY: echo-distcom
40 echo-distcom:
41         @echo ' ' $(DIST_COMMON) ' '
42 END
43
44 cat > parse1.yy << 'END'
45 %{
46 // Valid C++, but deliberately invalid C.
47 #include <cstdio>
48 #include <cstdlib>
49 int yylex (void) { return getchar (); }
50 void yyerror (const char *s) { return; }
51 %}
52 %%
53 a : 'a' { exit(0); };
54 END
55 cp parse1.yy parse2.y++
56 cp parse1.yy parse3.yxx
57 cp parse1.yy parse4.ypp
58
59 cat > foo.cc << 'END'
60 // Valid C++, but deliberately invalid C.
61 using namespace std;
62 int main (int argc, char **argv)
63 {
64   int yyparse (void);
65   yyparse ();
66   return 1;
67 }
68 END
69 cp foo.cc bar.c++
70 cp foo.cc bar2.cxx
71
72 $ACLOCAL
73 $AUTOCONF
74 $AUTOMAKE -a
75
76 ./configure
77
78 $MAKE
79
80 # The Yacc-derived C++ sources must be created, and not removed once
81 # compiled (i.e., not treated like "intermediate files" in the GNU
82 # make sense).
83 test -f parse1.cc
84 test -f parse2.c++
85 test -f foo3-parse3.cxx
86 test -f foo4-parse4.cpp
87 # Check that per-object flags are honored.
88 test -f foo3-parse3.output
89 test -f foo4-parse4.output
90
91 for i in 1 2 3 4; do
92   echo a | ./foo$i
93   echo b | ./foo$i && Exit 1
94   : For shells with busted 'set -e'.
95 done
96
97 # The Yacc-derived C++ sources must be shipped.
98 $MAKE echo-distcom
99 $MAKE -s echo-distcom | grep '[ /]parse1\.cc '
100 $MAKE -s echo-distcom | grep '[ /]parse2\.c++ '
101 $MAKE -s echo-distcom | grep '[ /]foo3-parse3\.cxx '
102 $MAKE -s echo-distcom | grep '[ /]foo4-parse4\.cpp '
103 $MAKE distdir
104 ls -l $distdir
105 test -f $distdir/parse1.cc
106 test -f $distdir/parse2.c++
107 test -f $distdir/foo3-parse3.cxx
108 test -f $distdir/foo4-parse4.cpp
109
110 # Sanity check on distribution.
111 # Note that, for this to succeed, foo3-parse3.output and foo4-parse4.output
112 # must either not be distributed, or properly cleaned by automake-generated
113 # rules.  We don't want to set the exact semantics yet, but want to ensure
114 # they are are consistent.
115 yl_distcheck
116
117 # Make sure that the Yacc-derived C++ sources are erased by
118 # maintainer-clean, and not by distclean.
119 test -f parse1.cc
120 test -f parse2.c++
121 test -f foo3-parse3.cxx
122 test -f foo4-parse4.cpp
123 $MAKE distclean
124 ls -l
125 test -f parse1.cc
126 test -f parse2.c++
127 test -f foo3-parse3.cxx
128 test -f foo4-parse4.cpp
129 ./configure # Re-create 'Makefile'.
130 $MAKE maintainer-clean
131 ls -l
132 test ! -f parse1.cc
133 test ! -f parse2.c++
134 test ! -f foo3-parse3.cxx
135 test ! -f foo4-parse4.cpp
136
137 :