doc: update Vala documentation
[automake.git] / t / subobj-clean-lt-pr10697.sh
blob6eafc9a4c7f437151fb4bd9a085b477664cee268
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
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 . test-init.sh
27 cat >> configure.ac << 'END'
28 AM_PROG_AR
29 AC_PROG_LIBTOOL
30 AC_PROG_CC
31 AC_OUTPUT
32 END
34 oPATH=$PATH
35 ocwd=$(pwd) || fatal_ "getting current working directory"
37 # An rm(1) wrapper that fails when invoked too many times.
38 mkdir rm-wrap
39 max_rm_invocations=6
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
46 exit 1
48 echo "\$count" > '$count_file'
49 PATH='$oPATH'; export PATH
50 exec rm "\$@"
51 END
52 chmod a+x rm-wrap/rm
53 echo "0" > rm-wrap/count
55 cat > Makefile.am <<'END'
56 .PHONY: sanity-check-rm
57 sanity-check-rm:
58 rm -f 1
59 rm -f 2
60 rm -f 3
61 rm -f 4
62 rm -f 5
63 rm -f 6
64 rm -f x && exit 1; :
65 echo "0" > rm-wrap/count
67 AUTOMAKE_OPTIONS = subdir-objects
68 lib_LTLIBRARIES = libfoo.la
69 libfoo_la_SOURCES = \
70 sub1/a.c \
71 sub1/b.c \
72 sub1/c.c \
73 sub1/d.c \
74 sub1/e.c \
75 sub1/f.c \
76 sub2/a.c \
77 sub2/b.c \
78 sub2/c.c \
79 sub2/d.c \
80 sub2/e.c \
81 sub2/f.c \
82 main.c
83 END
85 mkdir sub1 sub2
87 echo "/* Subobj clean: libtool case*/" > main.c
88 for i in 1 2; do
89 for j in a b c d e f; do
90 echo "extern void $j$i (void);" >> main.c
91 done
92 done
94 echo 'int libmain (void)' >> main.c
95 echo '{' >> main.c
96 for i in 1 2; do
97 for j in a b c d e f; do
98 echo "void $j$i (void) { }" > sub$i/$j.c
99 echo " $j$i ();" >> main.c
100 done
101 done
102 echo ' return 0;' >> main.c
103 echo '}' >> main.c
104 cat main.c # For debugging.
106 libtoolize
107 $ACLOCAL
108 $AUTOCONF
109 $AUTOMAKE -a
111 ./configure
113 # The use of this variable is only meant to keep us better in sync
114 # with the sister test 'subobj-clean-pr10697.sh'.
115 OBJEXT=lo
117 $MAKE
119 # This must go after configure, since that will invoke rm many times.
120 PATH=$ocwd/rm-wrap$PATH_SEPARATOR$PATH; export PATH
121 $MAKE sanity-check-rm || fatal_ "rm wrapper doesn't work as expected"
123 $MAKE mostlyclean
124 ls -l . sub1 sub2
125 for i in 1 2; do
126 for j in a b c d e f; do
127 test ! -e sub$i/$j.o
128 test ! -e sub$i/$j.obj
129 test ! -e sub$i/$j.lo
130 test -f sub$i/$j.c || exit 99 # Sanity check
131 done
132 done
134 PATH=$oPATH; export PATH
135 rm -rf rm-wrap
137 $MAKE clean
138 $MAKE
139 test -f sub1/a.$OBJEXT
140 test -f sub2/d.$OBJEXT
142 $sleep
144 mv -f sub2/d.c sub2/x.c
145 rm -f sub1/a.c
147 sed -e '/ a1 ()/d' main.c > t
148 mv -f t main.c
150 sed -e '/sub1\/a\.c/d' -e 's|sub2/d\.c|sub2/x.c|' Makefile.am > t
151 mv -f t Makefile.am
153 using_gmake || $MAKE Makefile
154 $MAKE
155 test -f sub2/x.$OBJEXT
157 # The stale objects are still there after a mere "make all" ...
158 test -f sub1/a.$OBJEXT
159 test -f sub2/a.$OBJEXT
161 # ... but they get removed by "make mostlyclean" ...
162 $MAKE mostlyclean
163 test ! -e sub1/a.$OBJEXT
164 test ! -e sub2/d.$OBJEXT
166 # ... and do not get rebuilt ...
167 $MAKE clean
168 $MAKE all
169 test ! -e sub1/a.$OBJEXT
170 test ! -e sub2/d.$OBJEXT
172 # ... while the non-stale files do.
173 test -f sub1/b.$OBJEXT
174 test -f sub2/x.$OBJEXT