Merge branch 'maint'
[platform/upstream/automake.git] / t / remake-subdir-long-time.sh
1 #! /bin/sh
2 # Copyright (C) 2011-2012 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 remake rules from subdirectories do not hang or cycle
18 # endlessly, even with build systems that takes several seconds to
19 # rebuild the Makefiles.
20 # This test tries to ensure a long-enough rebuild time by introducing
21 # an explicit delay in the build process.
22 # Suggestion by Ralf Wildenhues.
23
24 . test-init.sh
25
26 cat > configure.ac <<END
27 AC_INIT([$me], [1.0])
28 AM_INIT_AUTOMAKE([foreign -Wall -Werror])
29 AC_CONFIG_FILES([Makefile sub/Makefile])
30 AC_SUBST([MAGIC], [magic])
31 AC_OUTPUT
32 END
33
34 echo SUBDIRS = sub > Makefile.am
35 mkdir sub
36 : > sub/Makefile.am
37
38 # Both aclocal and automake are expected to run one and just one time.
39 # Create and use wrappers that will verify that.
40
41 ocwd=$(pwd) || fatal_ "cannot get current working directory"
42
43 mkdir bin
44
45 cat > bin/automake <<END
46 #!/bin/sh
47 set -e
48 PATH='$PATH'; export PATH
49 sentinel='$ocwd/automake-has-run'
50 if test -f "\$sentinel"; then
51   echo "Automake has been run more than one time" >&2
52   exit 1
53 else
54   echo automake has run > "\$sentinel"
55 fi
56 $sleep; $sleep;
57 exec $AUTOMAKE \${1+"\$@"}
58 END
59 chmod a+x bin/automake
60
61 cat > bin/aclocal <<END
62 #!/bin/sh
63 set -e
64 PATH='$PATH'; export PATH
65 sentinel='$ocwd/aclocal-has-run'
66 if test -f "\$sentinel"; then
67   echo "Aclocal has been run more than one time" >&2
68   exit 1
69 else
70   echo aclocal has run > "\$sentinel"
71 fi
72 $sleep; $sleep;
73 exec $ACLOCAL \${1+"\$@"}
74 END
75 chmod a+x bin/aclocal
76
77 # Just to be sure.
78 cp bin/automake bin/automake-$APIVERSION
79 cp bin/aclocal bin/aclocal-$APIVERSION
80
81 PATH=$ocwd/bin$PATH_SEPARATOR$PATH; export PATH
82
83 AUTOMAKE=automake ACLOCAL=aclocal; export AUTOMAKE ACLOCAL
84
85 $ACLOCAL  # Should use or just-defined wrapper.
86 $AUTOMAKE # Likewise.
87 $AUTOCONF
88
89 # Sanity check: the wrappers have been used.
90 test -f automake-has-run
91 test -f aclocal-has-run
92 rm -f automake-has-run aclocal-has-run
93
94 ./configure
95 # Sanity check: Makefile doesn't get updated uselessly.
96 ACLOCAL=false AUTOMAKE=false AUTOCONF=false $MAKE -e
97
98 $sleep
99 sed "s|magic|magic2|" configure.ac > t
100 mv -f t configure.ac
101
102 cd sub
103 AUTOMAKE="$AUTOMAKE" ACLOCAL="$ACLOCAL" $MAKE -e Makefile
104 cd ..
105
106 # For debugging.
107 ls -l . sub
108 grep -i magic configure Makefile.in Makefile sub/Makefile.in sub/Makefile
109 # Sanity checks.
110 $FGREP magic2 configure
111 $FGREP magic2 Makefile
112 $FGREP magic2 sub/Makefile
113
114 :