packaging: Bump to 1.14.1
[platform/upstream/automake.git] / t / remake-timing-bug-pr8365.sh
1 #! /bin/sh
2 # Copyright (C) 2011-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 # Test for automake bug#8365, related to Makefile remake rules.
18 # The bug is due to subtle timestamp issues and limitations in
19 # make's behaviour, and is very unlikely to be triggered (we have
20 # to resort to timestamp edit hacks to consistently expose it); in
21 # any account, it is nigh to impossible to trigger it by running
22 # make by hand.  Thus, fixing it would not be worth the hassle, but
23 # we prefer to keep it exposed anyway.
24
25 . test-init.sh
26
27 # We'll use calls to stat to get debugging information.
28 if stat /dev/null; then stat=stat; else stat=:; fi
29
30 cat >> configure.ac << 'END'
31 FOOBAR=zardoz
32 AC_OUTPUT
33 END
34
35 : > Makefile.am
36
37 $ACLOCAL
38 # Run automake *before* autoconf, because we want to ensure that
39 # Makefile.in is not newer than configure.
40 $AUTOMAKE
41 $AUTOCONF
42
43 ./configure
44 $MAKE Makefile
45 # Sanity check.
46 $EGREP 'FOOBAR|zardoz' Makefile && fatal_ 'unexpected AC_SUBST in Makefile'
47
48 echo 'AC_SUBST([FOOBAR])' >> configure.ac
49
50 # Modified configure dependencies must have the same timestamp of
51 # config.status and Makefile in order to trigger the bug.
52 # We also re-touch config.status, because "touch -r" can truncate
53 # timestamps on file systems with sub-second resolutions (see the
54 # autoconf manual).  Finally, we also sleep before touching, to ensure
55 # that the (possibly truncated) timestamps of config.status etc. are
56 # strictly newer than the non-truncated configure timestamp.
57 $stat config.status Makefile configure.ac
58 $sleep
59 touch config.status
60 touch -r config.status config.status Makefile configure.ac
61 $stat config.status Makefile configure.ac
62
63 # Also, the race condition is triggered only when aclocal, automake
64 # and aclocal run fast enough to keep the timestamp of the generated
65 # aclocal.m4, Makefile.in and configure equal to the timestamp of
66 # Makefile & config.status.  To reproduce this race consistently, we
67 # need the following hackish wrappers.
68
69 cat > aclocal-wrap <<END
70 #!/bin/sh
71 set -ex
72 # aclocal shouldn't use our autoconf wrapper when extracting
73 # the races from configure.ac.
74 AUTOCONF='$AUTOCONF'; export AUTOCONF
75 $ACLOCAL "\$@"
76 touch -r config.status aclocal.m4
77 $stat aclocal.m4
78 END
79
80 cat > automake-wrap <<END
81 #!/bin/sh
82 set -ex
83 # automake shouldn't use our autoconf wrapper when extracting
84 # the races from configure.ac.
85 AUTOCONF='$AUTOCONF'; export AUTOCONF
86 $AUTOMAKE "\$@"
87 touch -r config.status Makefile.in
88 $stat Makefile.in
89 END
90
91 cat > autoconf-wrap <<END
92 #!/bin/sh
93 set -ex
94 $AUTOCONF "\$@"
95 touch -r config.status configure
96 $stat configure
97 END
98
99 chmod a+x aclocal-wrap automake-wrap autoconf-wrap
100
101 run_make Makefile \
102   ACLOCAL=./aclocal-wrap AUTOMAKE=./automake-wrap AUTOCONF=./autoconf-wrap
103 grep '^FOOBAR =' Makefile.in
104 grep '^FOOBAR *= *zardoz *$' Makefile
105
106 :