Merge branch 'yacc-work' into yl-work-for-master
[platform/upstream/automake.git] / tests / yacc-d-basic.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 # Tests Yacc support with yacc-generated headers
18 # (i.e., '-d' in *YFLAGS).
19 # Keep in sync with sister test `yacc-d-cxx.test'.
20
21 required='cc yacc'
22 . ./defs || Exit 1
23
24 cat >> configure.in << 'END'
25 AC_PROG_CC
26 AC_PROG_YACC
27 AC_CONFIG_FILES([foo/Makefile bar/Makefile baz/Makefile])
28 AC_OUTPUT
29 END
30
31 cat > Makefile.am <<'END'
32 SUBDIRS = foo bar baz
33 END
34
35 mkdir foo bar baz
36
37 cat > foo/Makefile.am <<'END'
38 bin_PROGRAMS = zardoz
39 zardoz_SOURCES = parse.y main.c
40 .PHONY: echo-distcom
41 echo-distcom:
42         @echo ' ' $(DIST_COMMON) ' '
43 END
44 cp foo/Makefile.am bar/Makefile.am
45 cp foo/Makefile.am baz/Makefile.am
46
47 cat > foo/parse.y << 'END'
48 %{
49 #include "parse.h"
50 int yylex () { return 0; }
51 void yyerror (char *s) {}
52 %}
53 %%
54 x : 'x' {};
55 %%
56 END
57 cp foo/parse.y bar/parse.y
58
59 cat > foo/main.c << 'END'
60 #include "parse.h"
61 int main ()
62 {
63   return yyparse ();
64 }
65 END
66 cp foo/main.c bar/main.c
67
68 # Even the generated header file is renamed when target-specific YFLAGS
69 # are used.  This might not be the best behavior, but it has been in
70 # place for quite a long time, so just go along with it for now.
71 sed 's/"parse\.h"/"zardoz-parse.h"/' foo/parse.y > baz/parse.y
72 sed 's/"parse\.h"/"zardoz-parse.h"/' foo/main.c > baz/main.c
73
74 $ACLOCAL
75 $AUTOCONF
76
77 $AUTOMAKE -a
78 $FGREP parse.h foo/Makefile.in bar/Makefile.in baz/Makefile.in && Exit 1
79
80 cat >> foo/Makefile.am <<END
81 BUILT_SOURCES = parse.h
82 YFLAGS=\
83 -d
84 END
85 $AUTOMAKE -Wno-gnu foo/Makefile
86
87 sed 's/EOL$//' >> bar/Makefile.am <<END
88 AM_YFLAGS${tab}=  -d EOL
89 BUILT_SOURCES = parse.h
90 END
91 $AUTOMAKE bar/Makefile
92
93 cat >> baz/Makefile.am <<END
94 BUILT_SOURCES = zardoz-parse.h
95 zardoz_YFLAGS =-d${tab}
96 END
97 $AUTOMAKE baz/Makefile
98
99 ./configure
100
101 $MAKE
102
103 test -f foo/parse.c
104 test -f foo/parse.h
105 test -f bar/parse.c
106 test -f bar/parse.h
107 test -f baz/zardoz-parse.c
108 test -f baz/zardoz-parse.h
109
110 # The generated C source and header files must be shipped.
111 for dir in foo bar; do
112   cd $dir
113   $MAKE echo-distcom
114   $MAKE -s echo-distcom | grep '[ /]parse.c '
115   $MAKE -s echo-distcom | grep '[ /]parse.h '
116   cd ..
117 done
118 cd baz
119 $MAKE echo-distcom
120 $MAKE -s echo-distcom | grep '[ /]zardoz-parse.c '
121 $MAKE -s echo-distcom | grep '[ /]zardoz-parse.h '
122 cd ..
123
124 $MAKE distdir
125 ls -l $distdir
126 test -f $distdir/foo/parse.c
127 test -f $distdir/foo/parse.h
128 test -f $distdir/bar/parse.c
129 test -f $distdir/bar/parse.h
130 test -f $distdir/baz/zardoz-parse.c
131 test -f $distdir/baz/zardoz-parse.h
132
133 # Sanity check the distribution.
134 yl_distcheck
135
136 # While we are at it, make sure that `parse.c' and `parse.h' are erased
137 # by maintainer-clean, and not by distclean.
138 $MAKE distclean
139 test -f foo/parse.c
140 test -f foo/parse.h
141 test -f bar/parse.c
142 test -f bar/parse.h
143 test -f baz/zardoz-parse.c
144 test -f baz/zardoz-parse.h
145 ./configure # We must re-create `Makefile'.
146 $MAKE maintainer-clean
147 test ! -f foo/parse.c
148 test ! -f foo/parse.h
149 test ! -f bar/parse.c
150 test ! -f bar/parse.h
151 test ! -f baz/zardoz-parse.c
152 test ! -f baz/zardoz-parse.h
153
154 :