Merge branch 'msvc'
[platform/upstream/automake.git] / tests / pr307.test
1 #! /bin/sh
2 # Copyright (C) 2002, 2004, 2010 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 # Test for PR 307: depcomp with depmode=dashmstdout libtool race condition
18 # Report from Laurent Morichetti.
19 # (Also exercises check_LTLIBRARIES.)
20 #
21 # == Report ==
22 #  The dashmstdout depmode calls libtool in parallel to generate the
23 #  dependencies (with -M flag) and to build the objfile (both have
24 #  --mode=compile and -o).
25 #  The process with 'libtool --mode=compile .* -M' can corrupt the objfile
26 #  as none is generated by the compiler.  Since --mode=compile and -o are
27 #  set libtool assumes that a objfile should be generated and will execute
28 #  invalid $mv & $LN_S.
29 #
30 # == Fix ==
31 #  Now 'depcomp' never compute dependencies in the background, as this can
32 #  cause races with libtool.  Compute the dependencies after the actual
33 #  compilation.
34
35 required='libtoolize gcc'
36 . ./defs || Exit 1
37
38 set -e
39
40 cat >> configure.in << 'END'
41 AC_PROG_CC
42 AC_PROG_LIBTOOL
43 AC_OUTPUT
44 END
45
46 cat > Makefile.am << 'END'
47 check_LTLIBRARIES = librace.la
48 librace_la_SOURCES = a.c b.c c.c d.c e.c f.c g.c h.c
49
50 # Make sure the dependencies are updated.
51 check-local:
52         for i in $(librace_la_SOURCES:.c=.Plo); do \
53           echo "checking ./$(DEPDIR)/$$i"; \
54           grep 'foo\.h' ./$(DEPDIR)/$$i >tst || exit 1; \
55           test `wc -l <tst` -eq 2 || exit 1; \
56         done
57 END
58
59 : >foo.h
60
61 for i in a b c d e f g h; do
62   cat >$i.c <<EOF
63 #include "foo.h"
64 int $i() { return 0; }
65 EOF
66 done
67
68 libtoolize --force
69 $ACLOCAL
70 $AUTOCONF
71 $AUTOMAKE -a
72
73 # Sanity check: make sure the variable we are attempting to force
74 # is used by configure
75 grep am_cv_CC_dependencies_compiler_type configure
76
77 ./configure am_cv_CC_dependencies_compiler_type=dashmstdout
78
79 $MAKE
80 test -f librace.la && Exit 1
81 $MAKE check
82
83 # The failure we check usually occurs during the above build,
84 # with an output such as
85 #
86 # mv -f .libs/f.lo f.lo
87 # mv: cannot stat `.libs/f.lo': No such file or directory
88 #
89 # (This may happen on `f' or on some other files.)
90
91 test -f librace.la
92 test -f tst # a proof that check-local was run
93
94 :