2 # Copyright (C) 1998-2017 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 <https://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 by
20 # "make mostlyclean". See automake bug#10697.
21 # This is the non-libtool case. Keep this test in sync with sister test
22 # 'subobj-clean-lt-pr10697.sh', which deals with the libtool case.
27 cat >> configure.ac
<< 'END'
29 AC_CONFIG_FILES
([get-objext.sh
:get-objext.
in])
33 echo "OBJEXT='@OBJEXT@'" > get-objext.
in
36 ocwd
=$
(pwd) || fatal_
"getting current working directory"
38 # An rm(1) wrapper that fails when invoked too many times.
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 test \$count -le $max_rm_invocations || {
46 echo "rm invoked more than $max_rm_invocations times" >&2
49 echo "\$count" > '$count_file'
50 PATH='$oPATH'; export PATH
54 echo "0" > rm-wrap
/count
56 cat > Makefile.am
<<'END'
57 .PHONY: sanity-check-rm
63 echo "0" > rm-wrap/count
65 AUTOMAKE_OPTIONS = subdir-objects
84 echo 'int main (void)' > main.c
87 for j
in a b c d e f
; do
88 echo "void $j$i (void) { }" > sub
$i/$j.c
89 echo " $j$i ();" >> main.c
92 echo ' return 0;' >> main.c
94 cat main.c
# For debugging.
102 test -f get-objext.sh
107 # This must go after configure, since that will invoke rm many times.
108 PATH
=$ocwd/rm-wrap
$PATH_SEPARATOR$PATH; export PATH
109 $MAKE sanity-check-rm || fatal_
"rm wrapper doesn't work as expected"
114 for j
in a b c d e f
; do
116 test ! -e sub
$i/$j.obj
117 test -f sub
$i/$j.c ||
exit 99 # Sanity check
121 PATH
=$oPATH; export PATH
126 test -f sub
1/a.
$OBJEXT
127 test -f sub
2/d.
$OBJEXT
131 mv -f sub
2/d.c sub
2/x.c
134 sed -e '/ a1 ()/d' main.c
> t
137 sed -e '/sub1\/a\.c/d' -e 's|sub2/d\.c|sub2/x.c|' Makefile.am
> t
140 using_gmake ||
$MAKE Makefile
142 test -f sub
2/x.
$OBJEXT
144 # The stale objects are still there after a mere "make all" ...
145 test -f sub
1/a.
$OBJEXT
146 test -f sub
2/a.
$OBJEXT
148 # ... but they get removed by "make mostlyclean" ...
150 test ! -e sub
1/a.
$OBJEXT
151 test ! -e sub
2/d.
$OBJEXT
153 # ... and do not get rebuilt ...
156 test ! -e sub
1/a.
$OBJEXT
157 test ! -e sub
2/d.
$OBJEXT
159 # ... while the non-stale files do.
160 test -f sub
1/b.
$OBJEXT
161 test -f sub
2/x.
$OBJEXT