doc: typos in test file.
[automake.git] / t / subobj-clean-pr10697.sh
blob48089f75da3db735e74cbad1147d3a07e2abf7ec
1 #! /bin/sh
2 # Copyright (C) 1998-2024 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 <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.
24 required=cc
25 . test-init.sh
27 cat >> configure.ac << 'END'
28 AC_PROG_CC
29 AC_CONFIG_FILES([get-objext.sh:get-objext.in])
30 AC_OUTPUT
31 END
33 echo "OBJEXT='@OBJEXT@'" > get-objext.in
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=3
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
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 x && exit 1; :
63 echo "0" > rm-wrap/count
65 AUTOMAKE_OPTIONS = subdir-objects
66 bin_PROGRAMS = foo
67 foo_SOURCES = \
68 sub1/a.c \
69 sub1/b.c \
70 sub1/c.c \
71 sub1/d.c \
72 sub1/e.c \
73 sub1/f.c \
74 sub2/a.c \
75 sub2/b.c \
76 sub2/c.c \
77 sub2/d.c \
78 sub2/e.c \
79 sub2/f.c \
80 main.c
81 END
83 mkdir sub1 sub2
85 echo "/* Subobj clean: generic case*/" > main.c
86 for i in 1 2; do
87 for j in a b c d e f; do
88 echo "extern void $j$i (void);" >> main.c
89 done
90 done
92 echo 'int main (void)' >> main.c
93 echo '{' >> main.c
94 for i in 1 2; do
95 for j in a b c d e f; do
96 echo "void $j$i (void) { }" > sub$i/$j.c
97 echo " $j$i ();" >> main.c
98 done
99 done
100 echo ' return 0;' >> main.c
101 echo '}' >> main.c
102 cat main.c # For debugging.
104 $ACLOCAL
105 $AUTOCONF
106 $AUTOMAKE -a
108 ./configure
110 test -f get-objext.sh
111 . ./get-objext.sh
113 $MAKE
115 # This must go after configure, since that will invoke rm many times.
116 PATH=$ocwd/rm-wrap$PATH_SEPARATOR$PATH; export PATH
117 $MAKE sanity-check-rm || fatal_ "rm wrapper doesn't work as expected"
119 $MAKE mostlyclean
120 ls -l . sub1 sub2
121 for i in 1 2; do
122 for j in a b c d e f; do
123 test ! -e sub$i/$j.o
124 test ! -e sub$i/$j.obj
125 test -f sub$i/$j.c || exit 99 # Sanity check
126 done
127 done
129 PATH=$oPATH; export PATH
130 rm -rf rm-wrap
132 $MAKE clean
133 $MAKE
134 test -f sub1/a.$OBJEXT
135 test -f sub2/d.$OBJEXT
137 $sleep
139 mv -f sub2/d.c sub2/x.c
140 rm -f sub1/a.c
142 sed -e '/ a1 ()/d' main.c > t
143 mv -f t main.c
145 sed -e '/sub1\/a\.c/d' -e 's|sub2/d\.c|sub2/x.c|' Makefile.am > t
146 mv -f t Makefile.am
148 using_gmake || $MAKE Makefile
149 $MAKE
150 test -f sub2/x.$OBJEXT
152 # The stale objects are still there after a mere "make all" ...
153 test -f sub1/a.$OBJEXT
154 test -f sub2/a.$OBJEXT
156 # ... but they get removed by "make mostlyclean" ...
157 $MAKE mostlyclean
158 test ! -e sub1/a.$OBJEXT
159 test ! -e sub2/d.$OBJEXT
161 # ... and do not get rebuilt ...
162 $MAKE clean
163 $MAKE all
164 test ! -e sub1/a.$OBJEXT
165 test ! -e sub2/d.$OBJEXT
167 # ... while the non-stale files do.
168 test -f sub1/b.$OBJEXT
169 test -f sub2/x.$OBJEXT