test init: refactor: new function 'am_setup_testdir'
[automake.git] / t / subobj-clean-lt-pr10697.sh
blob6cbc0214b15b555fbb22c802307bfc075ac054b7
1 #! /bin/sh
2 # Copyright (C) 1998-2012 Free Software Foundation, Inc.
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.
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.
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/>.
17 # Removing subdir objects does not cause too much 'rm' invocations.
18 # Also, if we rename a source file in a subdirectory, the stale
19 # compiled object corresponding to the old name still gets removed
20 # by "make mostlyclean". See automake bug#10697.
21 # This is the libtool case. Keep this test in sync with sister test
22 # 'subobj-clean-pr10697.sh', which deals with the non-libtool case.
24 required='cc libtoolize'
25 . ./defs || exit 1
27 cat >> configure.ac << 'END'
28 AM_PROG_AR
29 AC_PROG_LIBTOOL
30 AC_PROG_CC
31 AM_PROG_CC_C_O
32 AC_OUTPUT
33 END
35 oPATH=$PATH
36 ocwd=$(pwd) || fatal_ "getting current working directory"
38 # An rm(1) wrapper that fails when invoked too many times.
39 mkdir rm-wrap
40 max_rm_invocations=6
41 count_file=$ocwd/rm-wrap/count
42 cat > rm-wrap/rm <<END
43 #!$AM_TEST_RUNNER_SHELL -e
44 count=\$((\$(cat '$count_file') + 1))
45 if ! test \$count -le $max_rm_invocations; then
46 echo "rm invoked more than $max_rm_invocations times" >&2
47 exit 1
49 echo "\$count" > '$count_file'
50 PATH='$oPATH'; export PATH
51 exec rm "\$@"
52 END
53 chmod a+x rm-wrap/rm
54 echo "0" > rm-wrap/count
56 cat > Makefile.am <<'END'
57 .PHONY: sanity-check-rm
58 sanity-check-rm:
59 rm -f 1
60 rm -f 2
61 rm -f 3
62 rm -f 4
63 rm -f 5
64 rm -f 6
65 rm -f x && exit 1; :
66 echo "0" > rm-wrap/count
68 AUTOMAKE_OPTIONS = subdir-objects
69 lib_LTLIBRARIES = libfoo.la
70 libfoo_la_SOURCES = \
71 sub1/a.c \
72 sub1/b.c \
73 sub1/c.c \
74 sub1/d.c \
75 sub1/e.c \
76 sub1/f.c \
77 sub2/a.c \
78 sub2/b.c \
79 sub2/c.c \
80 sub2/d.c \
81 sub2/e.c \
82 sub2/f.c \
83 main.c
84 END
86 mkdir sub1 sub2
87 echo 'int libmain (void)' > main.c
88 echo '{' >> main.c
89 for i in 1 2; do
90 for j in a b c d e f; do
91 echo "void $j$i (void) { }" > sub$i/$j.c
92 echo " $j$i ();" >> main.c
93 done
94 done
95 echo ' return 0;' >> main.c
96 echo '}' >> main.c
97 cat main.c # For debugging.
99 libtoolize
100 $ACLOCAL
101 $AUTOCONF
102 $AUTOMAKE -a
104 ./configure
106 # The use of this variable is only meant to keep us better in sync
107 # with the sister test 'subobj-clean-pr10697.sh'.
108 OBJEXT=lo
110 $MAKE
112 # This must go after configure, since that will invoke rm many times.
113 PATH=$ocwd/rm-wrap$PATH_SEPARATOR$PATH; export PATH
114 $MAKE sanity-check-rm || fatal_ "rm wrapper doesn't work as expected"
116 $MAKE mostlyclean
117 ls -l . sub1 sub2
118 for i in 1 2; do
119 for j in a b c d e f; do
120 test ! -e sub$i/$j.o
121 test ! -e sub$i/$j.obj
122 test ! -e sub$i/$j.lo
123 test -f sub$i/$j.c || exit 99 # Sanity check
124 done
125 done
127 PATH=$oPATH; export PATH
128 rm -rf rm-wrap
130 $MAKE clean
131 $MAKE
132 test -f sub1/a.$OBJEXT
133 test -f sub2/d.$OBJEXT
135 $sleep
137 mv -f sub2/d.c sub2/x.c
138 rm -f sub1/a.c
140 sed -e '/ a1 ()/d' main.c > t
141 mv -f t main.c
143 sed -e '/sub1\/a\.c/d' -e 's|sub2/d\.c|sub2/x.c|' Makefile.am > t
144 mv -f t Makefile.am
146 using_gmake || $MAKE Makefile
147 $MAKE
148 test -f sub2/x.$OBJEXT
150 # The stale objects are still there after a mere "make all" ...
151 test -f sub1/a.$OBJEXT
152 test -f sub2/a.$OBJEXT
154 # ... but they get removed by "make mostlyclean" ...
155 $MAKE mostlyclean
156 test ! -e sub1/a.$OBJEXT
157 test ! -e sub2/d.$OBJEXT
159 # ... and do not get rebuilt ...
160 $MAKE clean
161 $MAKE all
162 test ! -e sub1/a.$OBJEXT
163 test ! -e sub2/d.$OBJEXT
165 # ... while the non-stale files do.
166 test -f sub1/b.$OBJEXT
167 test -f sub2/x.$OBJEXT