test harness: improve catching of usage errors in script 'test-driver'
[platform/upstream/automake.git] / t / ccnoco-deps.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 dependency tracking can also work with compilers that
18 # doesn't understand '-c -o', even if the AM_PROG_CC_C_O macro is not
19 # explicitly called.
20
21 required=gcc # For 'cc-no-c-o'.
22 . test-init.sh
23
24 echo '#define myStr "Hello"' > foobar.h
25
26 cat > foo.c << 'END'
27 #include <stdio.h>
28 #include "foobar.h"
29 int main (void)
30 {
31   printf ("%s\n", myStr);
32   return 0;
33 }
34 END
35
36 cat > Makefile.am <<'END'
37 bin_PROGRAMS = foo
38 foo_SOURCES = foo.c foobar.h
39 check-deps: all
40         test -n '$(DEPDIR)' && test -d '$(DEPDIR)'
41         ls -l $(DEPDIR)
42         grep 'stdio\.h' $(DEPDIR)/foo.Po
43         grep 'foobar\.h' $(DEPDIR)/foo.Po
44 check-updated: all
45         is_newest foo$(EXEEXT) foobar.h
46 END
47
48 # We deliberately don't invoke AM_PROG_CC_C_O here.
49 cat >> configure.ac << 'END'
50 AC_PROG_CC
51 AC_OUTPUT
52 END
53
54 $ACLOCAL
55 $AUTOCONF
56 $AUTOMAKE --add-missing
57
58 # Make sure the compiler doesn't understand '-c -o'.
59 CC=$am_testaux_builddir/cc-no-c-o; export CC
60
61 ./configure >stdout || { cat stdout; exit 1; }
62 cat stdout
63 $EGREP 'understands? -c and -o together.* no$' stdout
64 grep '^checking dependency style .*\.\.\. gcc' stdout
65
66 $MAKE check-deps
67
68 if ! cross_compiling; then
69   ./foo
70   test "$(./foo)" = Hello
71 fi
72
73 $sleep
74 echo '#define myStr "Howdy"' > foobar.h
75 $MAKE check-updated
76
77 if ! cross_compiling; then
78   ./foo
79   test "$(./foo)" = Howdy
80 fi
81
82 :