Merge branch 'maint'
[platform/upstream/automake.git] / t / silent-nested-vars.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, on 'make' implementations that do not
18 # support nested variables (Bug#9928, Bug#10237).
19
20 . test-init.sh
21
22 cat >>configure.ac <<'EOF'
23 AM_SILENT_RULES
24 AC_PROG_CC
25 AM_PROG_CC_C_O
26 AC_OUTPUT
27 EOF
28
29 cat > Makefile.am <<'EOF'
30 # Need generic and non-generic rules.
31 bin_PROGRAMS = foo bar
32 bar_CFLAGS = $(AM_CFLAGS)
33
34 # Check that AM_V and AM_DEFAULT_V work as advertised.
35 pkg_verbose = $(pkg_verbose_@AM_V@)
36 pkg_verbose_ = $(pkg_verbose_@AM_DEFAULT_V@)
37 pkg_verbose_0 = @echo PKG-GEN $@;
38
39 bin_SCRIPTS = oop
40 oop:
41         $(pkg_verbose)echo $@ >$@
42
43 mostlyclean-local:
44         rm -f oop
45 EOF
46
47 cat > foo.c <<'EOF'
48 int main ()
49 {
50   return 0;
51 }
52 EOF
53 cp foo.c bar.c
54
55 cat >mymake <<'EOF'
56 #! /bin/sh
57 makerules=
58
59 case $1 in
60   -f)
61     makefile=$2
62     case $2 in
63       -) makerules=`cat` || exit ;;
64     esac ;;
65   *)
66     for makefile in makefile Makefile; do
67       test -f $makefile && break
68     done ;;
69 esac
70
71 nested_var_pat='^[^#].*\$([^)]*\$'
72 if
73   case $makefile in
74     -) printf '%s\n' "$makerules" | grep "$nested_var_pat";;
75     *) grep "$nested_var_pat" $makefile;;
76   esac
77 then
78   echo >&2 "mymake: $makefile contains nested variables"
79   exit 1
80 fi
81
82 case $makefile in
83   -) printf '%s\n' "$makerules" | $mymake_MAKE "$@";;
84   *) exec $mymake_MAKE "$@";;
85 esac
86 EOF
87 chmod a+x mymake
88 mymake_MAKE=${MAKE-make}
89 MAKE=./mymake
90 export MAKE mymake_MAKE
91
92 # As a sanity check, verify that 'mymake' rejects Makefiles that
93 # use nested variables.
94 cat > Makefile <<'END'
95 a = $(b$(c))
96 all:
97         touch bar
98 END
99 $MAKE && exit 99
100 mv -f Makefile foo.mk
101 $MAKE -f foo.mk && exit 99
102 cat foo.mk | $MAKE -f - && exit 99
103 test -f bar && exit 99
104 sed '/a =/d' foo.mk > Makefile
105 $MAKE && test -f bar || exit 99
106 rm -f bar Makefile foo.mk
107
108 $ACLOCAL
109 $AUTOMAKE --add-missing
110 $AUTOCONF
111
112 ./configure --enable-silent-rules >stdout || { cat stdout; exit 1; }
113 cat stdout
114 grep '^checking whether \./mymake supports nested variables\.\.\. no *$' \
115   stdout
116 $EGREP 'CC|AM_V|GEN' Makefile # For debugging.
117 grep '^AM_V_CC =  *\$(am__v_CC_0) *$' Makefile
118 grep '^AM_V_GEN =  *\$(am__v_GEN_0) *$' Makefile
119 $MAKE >stdout || { cat stdout; exit 1; }
120 cat stdout
121 $EGREP ' (-c|-o)' stdout && exit 1
122 grep 'mv ' stdout && exit 1
123 grep 'echo .*oop' stdout && exit 1
124 grep 'CC .*foo\.' stdout
125 grep 'CC .*bar\.' stdout
126 grep 'CCLD .*foo' stdout
127 grep 'CCLD .*bar' stdout
128 grep 'PKG-GEN .*oop' stdout
129 $MAKE distclean
130
131 ./configure --disable-silent-rules > stdout || { cat stdout; exit 1; }
132 cat stdout
133 grep '^checking whether \./mymake supports nested variables\.\.\. no *$' \
134   stdout
135 $EGREP 'CC|AM_V|GEN' Makefile # For debugging.
136 grep '^AM_V_CC =  *\$(am__v_CC_1) *$' Makefile
137 grep '^AM_V_GEN =  *\$(am__v_GEN_1) *$' Makefile
138
139 $MAKE >stdout || { cat stdout; exit 1; }
140 cat stdout
141 grep ' -c' stdout
142 grep ' -o foo' stdout
143 grep ' -o bar' stdout
144 grep 'echo .*>oop' stdout
145 $EGREP '(CC|LD) ' stdout && exit 1
146
147 :