tests: rename 'tests/' => 't/', '*.test' => '*.sh'
[platform/upstream/automake.git] / t / silent-yacc-headers.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 # Check silent-rules mode for Yacc, when yacc-generated headers are
18 # involved (i.e., the '-d' option is in *YFLAGS).
19
20 required=yacc
21 . ./defs || Exit 1
22
23 mkdir sub
24
25 cat >>configure.ac <<'EOF'
26 AM_SILENT_RULES
27 AC_PROG_YACC
28 AC_PROG_CC
29 AC_OUTPUT
30 EOF
31
32 cat > Makefile.am <<'EOF'
33 # Need generic and non-generic rules.
34 AM_YFLAGS = -d
35 bin_PROGRAMS = foo bar
36 foo_SOURCES = parse.y
37 bar_SOURCES = $(foo_SOURCES)
38 bar_YFLAGS = $(AM_YFLAGS)
39 EOF
40
41 cat > parse.y <<'EOF'
42 %{
43 void yyerror (char *s) { return; }
44 int yylex (void) { return 0; }
45 int main (void) { return 0; }
46 %}
47 %token EOF
48 %%
49 fubar : 'f' 'o' 'o' 'b' 'a' 'r' EOF {};
50 EOF
51
52 $ACLOCAL
53 $AUTOMAKE --add-missing
54 $AUTOCONF
55
56 # Check that the expected non-generic rules has been truly generated.
57 # Otherwise, the coverage offered by this test will be weaker then
58 # expected and planned.
59 $FGREP 'bar-parse.c' Makefile.in
60 $FGREP '$(bar_YFLAGS)' Makefile.in
61
62 ./configure --enable-silent-rules
63
64 $MAKE >stdout || { cat stdout; Exit 1; }
65 cat stdout
66
67 $EGREP ' (-c|-d|-o)' stdout && Exit 1
68 $EGREP '(mv|ylwrap) ' stdout && Exit 1
69
70 grep 'YACC  *parse\.c' stdout
71 grep 'updating  *parse\.h' stdout
72 grep 'YACC  *bar-parse\.c' stdout
73 grep 'updating  *bar-parse\.h' stdout
74
75 grep ' CC  *parse\.' stdout
76 grep ' CC  *bar-parse\.' stdout
77 grep 'CCLD  *foo' stdout
78 grep 'CCLD  *bar' stdout
79
80 # Check recovering from header removal.
81 rm -f parse.h bar-parse.h
82 $MAKE parse.h bar-parse.h >stdout || { cat stdout; Exit 1; }
83 cat stdout
84
85 $EGREP ' (-c|-d|-o)' stdout && Exit 1
86 $EGREP '(mv|ylwrap) ' stdout && Exit 1
87
88 grep 'YACC  *parse\.c' stdout
89 grep 'updating  *parse\.h' stdout
90 grep 'YACC  *bar-parse\.c' stdout
91 grep 'updating  *bar-parse\.h' stdout
92
93 # Cleaning and then rebuilding with the same V flag (and without
94 # removing the generated sources in between) shouldn't trigger a
95 # different set of rules.
96 $MAKE clean
97
98 $MAKE >stdout || { cat stdout; Exit 1; }
99 cat stdout
100
101 $EGREP ' (-c|-d|-o)' stdout && Exit 1
102 $EGREP '(mv|ylwrap) ' stdout && Exit 1
103
104 # Don't look for "YACC *.c" and "updating *.h", as yacc shouldn't
105 # have been re-run.
106 grep ' CC  *parse\.' stdout
107 grep ' CC  *bar-parse\.' stdout
108 grep 'CCLD  *foo' stdout
109 grep 'CCLD  *bar' stdout
110
111 # Check recovering from header removal.
112 rm -f parse.h bar-parse.h
113 $MAKE parse.h bar-parse.h >stdout || { cat stdout; Exit 1; }
114 cat stdout
115
116 $EGREP ' (-c|-d|-o)' stdout && Exit 1
117 $EGREP '(mv|ylwrap) ' stdout && Exit 1
118
119 grep 'YACC  *parse\.c' stdout
120 grep 'updating  *parse\.h' stdout
121 grep 'YACC  *bar-parse\.c' stdout
122 grep 'updating  *bar-parse\.h' stdout
123
124 # Ensure a truly clean rebuild.
125 $MAKE maintainer-clean
126
127 ./configure --enable-silent-rules
128
129 $MAKE V=1 >stdout || { cat stdout; Exit 1; }
130 cat stdout
131
132 grep ' -c ' stdout
133 grep ' -o ' stdout
134 grep ' -d ' stdout
135 grep 'ylwrap ' stdout
136
137 $EGREP '(YACC|CC|CCLD) ' stdout && Exit 1
138
139 # Check recovering from header removal.
140 rm -f parse.h bar-parse.h
141 $MAKE V=1 parse.h bar-parse.h >stdout || { cat stdout; Exit 1; }
142 cat stdout
143
144 grep ' -d ' stdout
145 grep 'ylwrap ' stdout
146
147 grep 'YACC' stdout && Exit 1
148
149 # Cleaning and then rebuilding with the same V flag (and without
150 # removing the generated sources in between) shouldn't trigger a
151 # different set of rules.
152 $MAKE clean
153
154 $MAKE V=1 >stdout || { cat stdout; Exit 1; }
155 cat stdout
156
157 # Don't look for ylwrap, as probably lex hasn't been re-run.
158 grep ' -c ' stdout
159 grep ' -o ' stdout
160
161 $EGREP '(YACC|CC|CCLD) ' stdout && Exit 1
162
163 # Check recovering from header removal.
164 rm -f parse.h bar-parse.h
165 $MAKE V=1 parse.h bar-parse.h >stdout || { cat stdout; Exit 1; }
166 cat stdout
167
168 grep ' -d ' stdout
169 grep 'ylwrap ' stdout
170
171 grep 'YACC' stdout && Exit 1
172
173 :