tests: avoid '$MAKE' redirections, use 'run_make' instead
[platform/upstream/automake.git] / t / silent-many-languages.sh
1 #!/bin/sh
2 # Copyright (C) 2009-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 silent-rules mode, with many languages at once.
18 # This test partly overlaps with other 'silent*.sh', but it serves as
19 # a stress test by using many different languages at once -- so don't
20 # remove this test script.
21
22 required='cc c++ fortran fortran77 lex yacc'
23 . test-init.sh
24
25 # Avoids too much code duplication.
26 do_and_check_silent_build ()
27 {
28   case $1 in
29     --rebuild) rebuild=true;;
30             *) rebuild=false;;
31   esac
32
33   run_make -O
34   # Avoid spurious failures with SunStudio Fortran compilers.
35   sed '/^NOTICE:/d' stdout > t
36   mv -f t stdout
37   cat stdout
38
39   $EGREP ' (-c|-o)' stdout && exit 1
40   $EGREP '(mv|ylwrap) ' stdout && exit 1
41
42   grep 'CXX .*foo1\.' stdout
43   grep 'CXX .*baz1\.' stdout
44   grep 'FC .*foo2\.'  stdout
45   grep 'FC .*baz2\.'  stdout
46   grep 'F77 .*foo3\.' stdout
47   grep 'F77 .*baz3\.' stdout
48   grep ' CC .*foo5\.' stdout
49   grep ' CC .*baz5\.' stdout
50   grep ' CC .*foo6\.' stdout
51   grep ' CC .*baz6\.' stdout
52
53   grep 'CXXLD .*foo' stdout
54   grep 'CCLD .*bar'  stdout
55   grep 'CXXLD .*baz' stdout
56   grep 'CCLD .*bla'  stdout
57
58   if ! $rebuild; then
59     grep 'YACC .*foo6\.' stdout
60     grep 'YACC .*baz6\.' stdout
61     grep 'LEX .*foo5\.'  stdout
62     grep 'LEX .*baz5\.'  stdout
63   fi
64
65   unset rebuild
66 }
67
68 # Avoids too much code duplication.
69 do_and_check_verbose_build ()
70 {
71   case $1 in
72     --rebuild) rebuild=true;;
73             *) rebuild=false;;
74   esac
75
76   run_make -O V=1
77
78   grep ' -c ' stdout
79   grep ' -o ' stdout
80
81   $EGREP '(CC|CXX|FC|F77|LD) ' stdout && exit 1
82
83   if ! $rebuild; then
84     grep 'ylwrap ' stdout
85     $EGREP '(LEX|YACC) ' stdout && exit 1
86   fi
87
88   unset rebuild
89 }
90
91 mkdir sub
92
93 cat >>configure.ac <<'EOF'
94 AM_PROG_CC_C_O
95 AC_PROG_F77
96 AC_PROG_FC
97 AC_PROG_LEX
98 AC_PROG_YACC
99 AC_PROG_CXX
100
101 # FIXME: remove this hack once the requirements c++, fortran and fortran77
102 # are implemented correctly.
103 test -n "`echo $CXX`" || AC_MSG_ERROR([C++ compiler not found], [77])
104 test -n "`echo $FC`"  || AC_MSG_ERROR([Fortran compiler not found], [77])
105 test -n "`echo $F77`" || AC_MSG_ERROR([Fortran 77 compiler not found], [77])
106
107 # The SunStudio C++ compiler is unfortunately named 'sunCC' (or even just
108 # 'CC', yuck!); similarly and the Portland group C++ compiler is named
109 # 'pgCC'.  This can cause problems with our grepping checks on the output
110 # from make.  Avoid these problems by invoking a wrapper script, as
111 # filtering the make output proved too fragile.
112 case " $CXX " in
113   *'CC '*)
114     AC_MSG_WARN([the C++ compiler '$CXX' name ends with 'CC'])
115     AC_MSG_WARN([it will be wrapped with the custom script 'am--cxx'])
116     echo '#!/bin/sh' > bin/am--cxx
117     echo 'PATH=$saved_PATH; export PATH' >> bin/am--cxx
118     echo "case \$# in" >> bin/am--cxx
119     echo "  0) exec $CXX ;;" >> bin/am--cxx
120     echo "  *) exec $CXX \"\$@\" ;;" >> bin/am--cxx
121     echo "esac" >> bin/am--cxx
122     chmod a+x bin/am--cxx
123     CXX=am--cxx
124 esac
125
126 AC_CONFIG_FILES([sub/Makefile])
127 AC_OUTPUT
128 EOF
129
130 cat > Makefile.am <<'EOF'
131 # Need generic and non-generic rules.
132 bin_PROGRAMS = foo bar fo2
133 bar_CFLAGS = $(AM_CFLAGS)
134 foo_SOURCES = foo1.cpp foo2.f90 foo3.f foo5.l foo6.y
135 fo2_SOURCES = $(foo_SOURCES)
136 fo2_CPPFLAGS = $(AM_CPPFLAGS)
137 fo2_FFLAGS = $(AM_FFLAGS)
138 fo2_FCFLAGS = $(AM_FCFLAGS)
139 fo2_YFLAGS = -v
140 fo2_LFLAGS = -n
141 SUBDIRS = sub
142 AM_YFLAGS = -d
143 LDADD = $(LEXLIB)
144 BUILT_SOURCES = foo6.h
145 EOF
146
147 cat > sub/Makefile.am <<'EOF'
148 AUTOMAKE_OPTIONS = subdir-objects
149 # Need generic and non-generic rules.
150 bin_PROGRAMS = baz bla ba2
151 bla_CFLAGS = $(AM_CFLAGS)
152 baz_SOURCES = baz1.cpp baz2.f90 baz3.f baz5.l baz6.y
153 ba2_SOURCES = $(baz_SOURCES)
154 ba2_CPPFLAGS = $(AM_CPPFLAGS)
155 ba2_FFLAGS = $(AM_FFLAGS)
156 ba2_FCFLAGS = $(AM_FCFLAGS)
157 ba2_YFLAGS = -v
158 ba2_LFLAGS = -n
159 AM_YFLAGS = -d
160 LDADD = $(LEXLIB)
161 BUILT_SOURCES = baz6.h
162 EOF
163
164 cat > foo1.cpp <<'EOF'
165 int main ()
166 {
167   return 0;
168 }
169 EOF
170 cat > foo2.f90 <<'EOF'
171       subroutine foo2
172       return
173       end
174 EOF
175 cat > foo3.f <<'EOF'
176       subroutine foo3
177       return
178       end
179 EOF
180 cat > foo5.l <<'EOF'
181 %{
182 #define YY_NO_UNISTD_H 1
183 %}
184 %%
185 "END"   return EOF;
186 .
187 %%
188 /* Avoid possible link errors. */
189 int yywrap (void)
190 {
191   return 1;
192 }
193 EOF
194 cat > foo6.y <<'EOF'
195 %{
196 void yyerror (char *s) {}
197 %}
198 %token EOF
199 %%
200 fubar : 'f' 'o' 'o' 'b' 'a' 'r' EOF {};
201 EOF
202 cp foo1.cpp bar.c
203 cp foo1.cpp sub/baz.c
204 cp foo1.cpp sub/bla.c
205 cp foo1.cpp sub/baz1.cpp
206 cp foo2.f90 sub/baz2.f90
207 cp foo3.f sub/baz3.f
208 cp foo5.l sub/baz5.l
209 cp foo6.y sub/baz6.y
210
211 mkdir bin
212 saved_PATH=$PATH; export saved_PATH
213 PATH=$(pwd)/bin$PATH_SEPARATOR$PATH; export PATH
214
215 $ACLOCAL
216 $AUTOMAKE --add-missing
217 $AUTOCONF
218
219 # Ensure per-target rules are used, to ensure their coverage below.
220 # (We do not do an exhaustive check, that wouldn't be practical).
221 $FGREP 'bar-bar.o' Makefile.in
222 $FGREP 'fo2-foo5.c' Makefile.in
223 $FGREP 'fo2-foo6.c' Makefile.in
224
225 # Force dependency tracking explicitly, so that slow dependency
226 # extractors are not rejected.  Try also with dependency tracking
227 # explicitly disabled.
228 for config_args in \
229   --enable-dependency-tracking --disable-dependency-tracking
230 do
231
232   ./configure $config_args --enable-silent-rules
233
234   do_and_check_silent_build
235   # Cleaning and then rebuilding with the same V flag (and without
236   # removing the generated sources in between) shouldn't trigger a
237   # different set of rules.
238   $MAKE clean
239   do_and_check_silent_build --rebuild
240
241   # Ensure a clean rebuild.
242   $MAKE clean
243   # This is required, since these files are not removed by 'make clean'
244   # (as dictated by the GNU Coding Standards).
245   rm -f *foo5.c *foo6.[ch] sub/*baz5.c sub/*baz6.[ch]
246
247   do_and_check_verbose_build
248   # Cleaning and then rebuilding with the same V flag (and without
249   # removing the generated sources in between) shouldn't trigger a
250   # different set of rules.
251   $MAKE clean
252   do_and_check_verbose_build --rebuild
253
254   # Ensure a clean reconfiguration/rebuild.
255   $MAKE clean
256   $MAKE maintainer-clean
257
258 done
259
260 :