Merge branch 'fix-pr13588-pax-hangs' into branch-1.13.2
[automake.git] / t / subobj-clean-pr10697.sh
blobdf97f070833e7f817b820c69169df89ad6e7d3eb
1 #! /bin/sh
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)
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 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.
24 required=cc
25 . test-init.sh
27 cat >> configure.ac << 'END'
28 AC_PROG_CC
29 AM_PROG_CC_C_O
30 AC_CONFIG_FILES([get-objext.sh:get-objext.in])
31 AC_OUTPUT
32 END
34 echo "OBJEXT='@OBJEXT@'" > get-objext.in
36 oPATH=$PATH
37 ocwd=$(pwd) || fatal_ "getting current working directory"
39 # An rm(1) wrapper that fails when invoked too many times.
40 mkdir rm-wrap
41 max_rm_invocations=3
42 count_file=$ocwd/rm-wrap/count
43 cat > rm-wrap/rm <<END
44 #!$AM_TEST_RUNNER_SHELL -e
45 count=\$((\$(cat '$count_file') + 1))
46 test \$count -le $max_rm_invocations || {
47 echo "rm invoked more than $max_rm_invocations times" >&2
48 exit 1
50 echo "\$count" > '$count_file'
51 PATH='$oPATH'; export PATH
52 exec rm "\$@"
53 END
54 chmod a+x rm-wrap/rm
55 echo "0" > rm-wrap/count
57 cat > Makefile.am <<'END'
58 .PHONY: sanity-check-rm
59 sanity-check-rm:
60 rm -f 1
61 rm -f 2
62 rm -f 3
63 rm -f x && exit 1; :
64 echo "0" > rm-wrap/count
66 AUTOMAKE_OPTIONS = subdir-objects
67 bin_PROGRAMS = foo
68 foo_SOURCES = \
69 sub1/a.c \
70 sub1/b.c \
71 sub1/c.c \
72 sub1/d.c \
73 sub1/e.c \
74 sub1/f.c \
75 sub2/a.c \
76 sub2/b.c \
77 sub2/c.c \
78 sub2/d.c \
79 sub2/e.c \
80 sub2/f.c \
81 main.c
82 END
84 mkdir sub1 sub2
85 echo 'int main (void)' > main.c
86 echo '{' >> main.c
87 for i in 1 2; do
88 for j in a b c d e f; do
89 echo "void $j$i (void) { }" > sub$i/$j.c
90 echo " $j$i ();" >> main.c
91 done
92 done
93 echo ' return 0;' >> main.c
94 echo '}' >> main.c
95 cat main.c # For debugging.
97 $ACLOCAL
98 $AUTOCONF
99 $AUTOMAKE -a
101 ./configure
103 test -f get-objext.sh
104 . ./get-objext.sh
106 $MAKE
108 # This must go after configure, since that will invoke rm many times.
109 PATH=$ocwd/rm-wrap$PATH_SEPARATOR$PATH; export PATH
110 $MAKE sanity-check-rm || fatal_ "rm wrapper doesn't work as expected"
112 $MAKE mostlyclean
113 ls -l . sub1 sub2
114 for i in 1 2; do
115 for j in a b c d e f; do
116 test ! -e sub$i/$j.o
117 test ! -e sub$i/$j.obj
118 test -f sub$i/$j.c || exit 99 # Sanity check
119 done
120 done
122 PATH=$oPATH; export PATH
123 rm -rf rm-wrap
125 $MAKE clean
126 $MAKE
127 test -f sub1/a.$OBJEXT
128 test -f sub2/d.$OBJEXT
130 $sleep
132 mv -f sub2/d.c sub2/x.c
133 rm -f sub1/a.c
135 sed -e '/ a1 ()/d' main.c > t
136 mv -f t main.c
138 sed -e '/sub1\/a\.c/d' -e 's|sub2/d\.c|sub2/x.c|' Makefile.am > t
139 mv -f t Makefile.am
141 using_gmake || $MAKE Makefile
142 $MAKE
143 test -f sub2/x.$OBJEXT
145 # The stale objects are still there after a mere "make all" ...
146 test -f sub1/a.$OBJEXT
147 test -f sub2/a.$OBJEXT
149 # ... but they get removed by "make mostlyclean" ...
150 $MAKE mostlyclean
151 test ! -e sub1/a.$OBJEXT
152 test ! -e sub2/d.$OBJEXT
154 # ... and do not get rebuilt ...
155 $MAKE clean
156 $MAKE all
157 test ! -e sub1/a.$OBJEXT
158 test ! -e sub2/d.$OBJEXT
160 # ... while the non-stale files do.
161 test -f sub1/b.$OBJEXT
162 test -f sub2/x.$OBJEXT