Merge branch 'silent-custom' into maint
[platform/upstream/automake.git] / t / subobj-clean-lt-pr10697.sh
1 #! /bin/sh
2 # Copyright (C) 1998-2012 Free Software Foundation, Inc.
3 #
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.
8 #
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.
13 #
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/>.
16
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.
23
24 required='cc libtoolize'
25 . ./defs || Exit 1
26
27 cat >> configure.ac << 'END'
28 AM_PROG_AR
29 AC_PROG_LIBTOOL
30 AC_PROG_CC
31 AM_PROG_CC_C_O
32 AC_OUTPUT
33 END
34
35 oPATH=$PATH
36 ocwd=`pwd` || fatal_ "getting current working directory"
37
38 # An rm(1) wrapper that fails when invoked too many times.
39 mkdir rm-wrap
40 max_rm_invocations=6
41 count_file=$ocwd/rm-wrap/count
42 cat > rm-wrap/rm <<END
43 #!/bin/sh
44 set -e
45 count=\`cat '$count_file'\`
46 count=\`expr \$count + 1\`
47 if test \$count -le $max_rm_invocations; then :; else
48   echo "rm invoked more than $max_rm_invocations times" >&2
49   exit 1
50 fi
51 echo "\$count" > '$count_file'
52 PATH='$oPATH'; export PATH
53 exec rm "\$@"
54 END
55 chmod a+x rm-wrap/rm
56 echo "0" > rm-wrap/count
57
58 cat > Makefile.am <<'END'
59 .PHONY: sanity-check-rm
60 sanity-check-rm:
61         rm -f 1
62         rm -f 2
63         rm -f 3
64         rm -f 4
65         rm -f 5
66         rm -f 6
67         rm -f x && exit 1; :
68         echo "0" > rm-wrap/count
69
70 AUTOMAKE_OPTIONS = subdir-objects
71 lib_LTLIBRARIES = libfoo.la
72 libfoo_la_SOURCES = \
73   sub1/a.c \
74   sub1/b.c \
75   sub1/c.c \
76   sub1/d.c \
77   sub1/e.c \
78   sub1/f.c \
79   sub2/a.c \
80   sub2/b.c \
81   sub2/c.c \
82   sub2/d.c \
83   sub2/e.c \
84   sub2/f.c \
85   main.c
86 END
87
88 mkdir sub1 sub2
89 echo 'int libmain (void)' > main.c
90 echo '{' >> main.c
91 for i in 1 2; do
92   for j in a b c d e f; do
93     echo "void $j$i (void) { }" > sub$i/$j.c
94     echo "  $j$i ();" >> main.c
95   done
96 done
97 echo '  return 0;' >> main.c
98 echo '}' >> main.c
99 cat main.c # For debugging.
100
101 libtoolize
102 $ACLOCAL
103 $AUTOCONF
104 $AUTOMAKE -a
105
106 ./configure
107
108 # The use of this variable is only meant to keep us better in sync
109 # with the sister test 'subobj-clean-pr10697.sh'.
110 OBJEXT=lo
111
112 $MAKE
113
114 # This must go after configure, since that will invoke rm many times.
115 PATH=$ocwd/rm-wrap$PATH_SEPARATOR$PATH; export PATH
116 $MAKE sanity-check-rm || fatal_ "rm wrapper doesn't work as expected"
117
118 $MAKE mostlyclean
119 ls -l . sub1 sub2
120 for i in 1 2; do
121   for j in a b c d e f; do
122     test ! -f sub$i/$j.o
123     test ! -f sub$i/$j.obj
124     test ! -f sub$i/$j.lo
125     test -f sub$i/$j.c || Exit 99 # Sanity check
126   done
127 done
128
129 PATH=$oPATH; export PATH
130 rm -rf rm-wrap
131
132 $MAKE clean
133 $MAKE
134 test -f sub1/a.$OBJEXT
135 test -f sub2/d.$OBJEXT
136
137 $sleep
138
139 mv -f sub2/d.c sub2/x.c
140 rm -f sub1/a.c
141
142 sed -e '/ a1 ()/d' main.c > t
143 mv -f t main.c
144
145 sed -e '/sub1\/a\.c/d' -e 's|sub2/d\.c|sub2/x.c|' Makefile.am > t
146 mv -f t Makefile.am
147
148 using_gmake || $MAKE Makefile
149 $MAKE
150 test -f sub2/x.$OBJEXT
151
152 # The stale objects are still there after a mere "make all" ...
153 test -f sub1/a.$OBJEXT
154 test -f sub2/a.$OBJEXT
155
156 # ... but they get removed by "make mostlyclean" ...
157 $MAKE mostlyclean
158 test ! -f sub1/a.$OBJEXT
159 test ! -f sub2/d.$OBJEXT
160
161 # ... and do not get rebuilt ...
162 $MAKE clean
163 $MAKE all
164 test ! -f sub1/a.$OBJEXT
165 test ! -f sub2/d.$OBJEXT
166
167 # ... while the non-stale files do.
168 test -f sub1/b.$OBJEXT
169 test -f sub2/x.$OBJEXT
170
171 :