automake: do not emit rule with two dependents
[automake.git] / t / am-prog-cc-c-o.sh
blob62f469b04d23a8b113f172c5bcd5272f9c09144a
1 #! /bin/sh
2 # Copyright (C) 2013-2015 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 <http://www.gnu.org/licenses/>.
17 # Check that uses of the obsolescent AM_PROG_CC_C_O macro doesn't
18 # cause spurious warnings or errors. Suggested by Eric Blake.
20 # We need gcc for for two reasons:
21 # 1. to ensure our C compiler grasps "-c -o" together.
22 # 2. to be able to later fake a dumb compiler not grasping that
23 # (done with 'cc-no-c-o' script below, which required gcc).
24 required=gcc
25 . test-init.sh
27 echo bin_PROGRAMS = foo > Makefile.am
28 echo 'int main (void) { return 0; }' > foo.c
30 cp configure.ac configure.bak
32 cat > acinclude.m4 <<'END'
33 AC_DEFUN([AM_TWEAKED_OUTPUT], [
34 # For debugging.
35 printf "CC = '%s'\\n" "$CC"
36 # Make sure that $CC can be used after AM_PROG_CC_C_O.
37 $CC --version || exit 1
38 $CC -v || exit 1
39 # $CC rewrite should only take place on time.
40 case " $CC " in
41 *" compile"*" compile"*) AC_MSG_ERROR([CC rewritten twice]);;
42 esac
43 AC_OUTPUT
45 END
47 # ---
49 cat configure.bak - > configure.ac << 'END'
50 dnl It's OK to call AM_PROG_CC_C_O after AC_PROG_CC.
51 AC_PROG_CC
52 AM_PROG_CC_C_O
53 AM_TWEAKED_OUTPUT
54 END
56 $ACLOCAL
57 $AUTOCONF
58 $AUTOMAKE --add-missing
60 ./configure >stdout || { cat stdout; exit 1; }
61 cat stdout
62 if test "$AM_TESTSUITE_SIMULATING_NO_CC_C_O" != no; then
63 $EGREP 'understands? -c and -o together.* no$' stdout
64 else
65 $EGREP 'understands? -c and -o together.* yes$' stdout
68 # No repeated checks please.
69 test $(grep -c ".*-c['\" ].*-o['\" ]" stdout) -eq 1
71 $MAKE
72 $MAKE maintainer-clean
73 rm -rf autom4te*.cache
75 # ---
77 cat configure.bak - > configure.ac << 'END'
78 dnl It's also OK to call AM_PROG_CC_C_O *before* AC_PROG_CC.
79 AM_PROG_CC_C_O
80 AC_PROG_CC
81 AM_TWEAKED_OUTPUT
82 END
84 $ACLOCAL
85 $AUTOCONF
86 $AUTOMAKE --add-missing
88 ./configure >stdout || { cat stdout; exit 1; }
89 cat stdout
90 if test "$AM_TESTSUITE_SIMULATING_NO_CC_C_O" != no; then
91 $EGREP 'understands? -c and -o together.* no$' stdout
92 else
93 $EGREP 'understands? -c and -o together.* yes$' stdout
96 # Repeated checks are OK in this case, but should be cached.
97 test $(grep ".*-c['\" ].*-o['\" ]" stdout \
98 | $FGREP -v ' (cached) ' | wc -l) -eq 1
100 $MAKE
101 $MAKE maintainer-clean
102 rm -rf autom4te*.cache
104 # ---
106 cat configure.bak - > configure.ac << 'END'
107 dnl It's also OK to call AM_PROG_CC_C_O *without* AC_PROG_CC.
108 AM_PROG_CC_C_O
109 AM_TWEAKED_OUTPUT
112 $ACLOCAL
113 $AUTOCONF
114 $AUTOMAKE --add-missing
116 # Make sure the compiler doesn't understand '-c -o'
117 CC=$am_testaux_builddir/cc-no-c-o; export CC
119 ./configure >stdout || { cat stdout; exit 1; }
120 cat stdout
121 $EGREP 'understands? -c and -o together.* no$' stdout
122 # No repeated checks please.
123 test $(grep -c ".*-c['\" ].*-o['\" ]" stdout) -eq 1
124 $MAKE