coverage: obsolete macro AM_PROG_CC_C_O should cause no warning nor errors
[platform/upstream/automake.git] / t / am-prog-cc-c-o.sh
1 #! /bin/sh
2 # Copyright (C) 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 that uses of the obsolescent AM_PROG_CC_C_O macro doesn't
18 # cause spurious warnings or errors.  Suggested by Eric Blake.
19
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
26
27 echo bin_PROGRAMS = foo > Makefile.am
28 echo 'int main (void) { return 0; }' > foo.c
29
30 cp configure.ac configure.bak
31
32 cat >> configure.ac << 'END'
33 # Since AM_PROG_CC_C_O rewrites $CC, it's an error to call AC_PROG_CC
34 # after it.
35 AM_PROG_CC_C_O
36 AC_PROG_CC
37 END
38
39 $ACLOCAL -Wnone 2>stderr && { cat stderr >&2; exit 1; }
40 cat stderr >&2
41 grep '^configure\.ac:7:.* AC_PROG_CC .*called after AM_PROG_CC_C_O' stderr
42
43 cat configure.bak - > configure.ac << 'END'
44 dnl It's OK to call AM_PROG_CC_C_O after AC_PROG_CC.
45 AC_PROG_CC
46 AM_PROG_CC_C_O
47 # Make sure that $CC can be used after AM_PROG_CC_C_O.
48 $CC --version || exit 1
49 $CC -v || exit 1
50 AC_OUTPUT
51 END
52
53 $ACLOCAL
54 $AUTOCONF
55 $AUTOMAKE --add-missing
56
57 ./configure >stdout || { cat stdout; exit 1; }
58 cat stdout
59 grep 'understands -c and -o together.* yes$' stdout
60 # No repeated checks please.
61 test $(grep -c ".*-c['\" ].*-o['\" ]" stdout) -eq 1
62 $MAKE
63
64 $MAKE maintainer-clean
65
66 rm -rf autom4te*.cache
67
68 cat configure.bak - > configure.ac << 'END'
69 dnl It's also OK to call AM_PROG_CC_C_O *without* AC_PROG_CC.
70 AM_PROG_CC_C_O
71 # Make sure that $CC can be used after AM_PROG_CC_C_O.
72 $CC --version || exit 1
73 $CC -v || exit 1
74 AC_OUTPUT
75 END
76
77 $ACLOCAL
78 $AUTOCONF
79 $AUTOMAKE --add-missing
80
81 # Make sure the compiler doesn't understand '-c -o'
82 CC=$am_testaux_builddir/cc-no-c-o; export CC
83
84 ./configure >stdout || { cat stdout; exit 1; }
85 cat stdout
86 grep 'understands -c and -o together.* no$' stdout
87 # No repeated checks please.
88 test $(grep -c ".*-c['\" ].*-o['\" ]" stdout) -eq 1
89 $MAKE
90
91 :