tests: Let 'ltorder.sh' run successfully with Guix dynamic loader
[automake.git] / t / silent-nested-vars.sh
blob9cb6591d2a8df6a275187c4fe341d6ea263ffb11
1 #!/bin/sh
2 # Copyright (C) 2011-2018 Free Software Foundation, Inc.
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.
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.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <https://www.gnu.org/licenses/>.
17 # Check silent-rules mode, on 'make' implementations that do not
18 # support nested variables (Bug#9928, Bug#10237).
20 . test-init.sh
22 cat >>configure.ac <<'EOF'
23 AM_SILENT_RULES
24 AC_PROG_CC
25 AC_OUTPUT
26 EOF
28 cat > Makefile.am <<'EOF'
29 # Need generic and non-generic rules.
30 bin_PROGRAMS = foo bar
31 bar_CFLAGS = $(AM_CFLAGS)
33 # Check that AM_V and AM_DEFAULT_V work as advertised.
34 pkg_verbose = $(pkg_verbose_@AM_V@)
35 pkg_verbose_ = $(pkg_verbose_@AM_DEFAULT_V@)
36 pkg_verbose_0 = @echo PKG-GEN $@;
38 bin_SCRIPTS = oop
39 oop:
40 $(pkg_verbose)echo $@ >$@
42 mostlyclean-local:
43 rm -f oop
44 EOF
46 cat > foo.c <<'EOF'
47 int main ()
49 return 0;
51 EOF
52 cp foo.c bar.c
54 cat >mymake <<'EOF'
55 #! /bin/sh
56 makerules=
58 case $1 in
59 -f)
60 makefile=$2
61 case $2 in
62 -) makerules=`cat` || exit ;;
63 esac ;;
65 for makefile in makefile Makefile; do
66 test -f $makefile && break
67 done ;;
68 esac
70 nested_var_pat='^[^#].*\$([^)]*\$'
72 case $makefile in
73 -) printf '%s\n' "$makerules" | grep "$nested_var_pat";;
74 *) grep "$nested_var_pat" $makefile;;
75 esac
76 then
77 echo >&2 "mymake: $makefile contains nested variables"
78 exit 1
81 case $makefile in
82 -) printf '%s\n' "$makerules" | $mymake_MAKE "$@";;
83 *) exec $mymake_MAKE "$@";;
84 esac
85 EOF
86 chmod a+x mymake
87 mymake_MAKE=${MAKE-make}
88 MAKE=./mymake
89 export MAKE mymake_MAKE
91 # As a sanity check, verify that 'mymake' rejects Makefiles that
92 # use nested variables.
93 cat > Makefile <<'END'
94 a = $(b$(c))
95 all:
96 touch bar
97 END
98 $MAKE && exit 99
99 mv -f Makefile foo.mk
100 $MAKE -f foo.mk && exit 99
101 cat foo.mk | $MAKE -f - && exit 99
102 test -f bar && exit 99
103 sed '/a =/d' foo.mk > Makefile
104 $MAKE && test -f bar || exit 99
105 rm -f bar Makefile foo.mk
107 $ACLOCAL
108 $AUTOMAKE --add-missing
109 $AUTOCONF
111 ./configure --enable-silent-rules >stdout || { cat stdout; exit 1; }
112 cat stdout
113 grep '^checking whether \./mymake supports nested variables\.\.\. no *$' \
114 stdout
115 $EGREP 'CC|AM_V|GEN' Makefile # For debugging.
116 grep '^AM_V_CC = *\$(am__v_CC_0) *$' Makefile
117 grep '^AM_V_GEN = *\$(am__v_GEN_0) *$' Makefile
118 run_make -O
119 $EGREP ' (-c|-o)' stdout && exit 1
120 grep 'mv ' stdout && exit 1
121 grep 'echo .*oop' stdout && exit 1
122 grep 'CC .*foo\.' stdout
123 grep 'CC .*bar\.' stdout
124 grep 'CCLD .*foo' stdout
125 grep 'CCLD .*bar' stdout
126 grep 'PKG-GEN .*oop' stdout
127 $MAKE distclean
129 ./configure --disable-silent-rules > stdout || { cat stdout; exit 1; }
130 cat stdout
131 grep '^checking whether \./mymake supports nested variables\.\.\. no *$' \
132 stdout
133 $EGREP 'CC|AM_V|GEN' Makefile # For debugging.
134 grep '^AM_V_CC = *\$(am__v_CC_1) *$' Makefile
135 grep '^AM_V_GEN = *\$(am__v_GEN_1) *$' Makefile
137 run_make -O
138 grep ' -c' stdout
139 grep ' -o foo' stdout
140 grep ' -o bar' stdout
141 grep 'echo .*>oop' stdout
142 $EGREP '(CC|LD) ' stdout && exit 1