2 # Copyright (C) 1998-2013 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)
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'
27 cat >> configure.ac << 'END'
35 ocwd=$(pwd) || fatal_ "getting current working directory"
37 # An rm(1) wrapper that fails when invoked too many times.
40 count_file=$ocwd/rm-wrap/count
41 cat > rm-wrap/rm <<END
42 #!$AM_TEST_RUNNER_SHELL -e
43 count=\$((\$(cat '$count_file') + 1))
44 if ! test \$count -le $max_rm_invocations; then
45 echo "rm invoked more than $max_rm_invocations times" >&2
48 echo "\$count" > '$count_file'
49 PATH='$oPATH'; export PATH
53 echo "0" > rm-wrap/count
55 cat > Makefile.am <<'END'
56 .PHONY: sanity-check-rm
65 echo "0" > rm-wrap/count
67 AUTOMAKE_OPTIONS = subdir-objects
68 lib_LTLIBRARIES = libfoo.la
86 echo 'int libmain (void)' > main.c
89 for j in a b c d e f; do
90 echo "void $j$i (void) { }" > sub$i/$j.c
91 echo " $j$i ();" >> main.c
94 echo ' return 0;' >> main.c
96 cat main.c # For debugging.
105 # The use of this variable is only meant to keep us better in sync
106 # with the sister test 'subobj-clean-pr10697.sh'.
111 # This must go after configure, since that will invoke rm many times.
112 PATH=$ocwd/rm-wrap$PATH_SEPARATOR$PATH; export PATH
113 $MAKE sanity-check-rm || fatal_ "rm wrapper doesn't work as expected"
118 for j in a b c d e f; do
120 test ! -e sub$i/$j.obj
121 test ! -e sub$i/$j.lo
122 test -f sub$i/$j.c || exit 99 # Sanity check
126 PATH=$oPATH; export PATH
131 test -f sub1/a.$OBJEXT
132 test -f sub2/d.$OBJEXT
136 mv -f sub2/d.c sub2/x.c
139 sed -e '/ a1 ()/d' main.c > t
142 sed -e '/sub1\/a\.c/d' -e 's|sub2/d\.c|sub2/x.c|' Makefile.am > t
145 using_gmake || $MAKE Makefile
147 test -f sub2/x.$OBJEXT
149 # The stale objects are still there after a mere "make all" ...
150 test -f sub1/a.$OBJEXT
151 test -f sub2/a.$OBJEXT
153 # ... but they get removed by "make mostlyclean" ...
155 test ! -e sub1/a.$OBJEXT
156 test ! -e sub2/d.$OBJEXT
158 # ... and do not get rebuilt ...
161 test ! -e sub1/a.$OBJEXT
162 test ! -e sub2/d.$OBJEXT
164 # ... while the non-stale files do.
165 test -f sub1/b.$OBJEXT
166 test -f sub2/x.$OBJEXT