tests: remove remaining exec bits ('maint' branch)
[platform/upstream/automake.git] / t / subobj-clean-lt-pr10697.sh
1 #! /bin/sh
2 # Copyright (C) 1998-2013 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 . test-init.sh
26
27 cat >> configure.ac << 'END'
28 AM_PROG_AR
29 AC_PROG_LIBTOOL
30 AC_PROG_CC
31 AC_OUTPUT
32 END
33
34 oPATH=$PATH
35 ocwd=$(pwd) || fatal_ "getting current working directory"
36
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
47 fi
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
54
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
66
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
84
85 mkdir sub1 sub2
86 echo 'int libmain (void)' > main.c
87 echo '{' >> main.c
88 for i in 1 2; do
89   for j in a b c d e f; do
90     echo "void $j$i (void) { }" > sub$i/$j.c
91     echo "  $j$i ();" >> main.c
92   done
93 done
94 echo '  return 0;' >> main.c
95 echo '}' >> main.c
96 cat main.c # For debugging.
97
98 libtoolize
99 $ACLOCAL
100 $AUTOCONF
101 $AUTOMAKE -a
102
103 ./configure
104
105 # The use of this variable is only meant to keep us better in sync
106 # with the sister test 'subobj-clean-pr10697.sh'.
107 OBJEXT=lo
108
109 $MAKE
110
111 # This must go after configure, since that will invoke rm many times.
112 PATH=$ocwd/rm-wrap$PATH_SEPARATOR$PATH; export PATH
113 $MAKE sanity-check-rm || fatal_ "rm wrapper doesn't work as expected"
114
115 $MAKE mostlyclean
116 ls -l . sub1 sub2
117 for i in 1 2; do
118   for j in a b c d e f; do
119     test ! -e sub$i/$j.o
120     test ! -e sub$i/$j.obj
121     test ! -e sub$i/$j.lo
122     test -f sub$i/$j.c || exit 99 # Sanity check
123   done
124 done
125
126 PATH=$oPATH; export PATH
127 rm -rf rm-wrap
128
129 $MAKE clean
130 $MAKE
131 test -f sub1/a.$OBJEXT
132 test -f sub2/d.$OBJEXT
133
134 $sleep
135
136 mv -f sub2/d.c sub2/x.c
137 rm -f sub1/a.c
138
139 sed -e '/ a1 ()/d' main.c > t
140 mv -f t main.c
141
142 sed -e '/sub1\/a\.c/d' -e 's|sub2/d\.c|sub2/x.c|' Makefile.am > t
143 mv -f t Makefile.am
144
145 using_gmake || $MAKE Makefile
146 $MAKE
147 test -f sub2/x.$OBJEXT
148
149 # The stale objects are still there after a mere "make all" ...
150 test -f sub1/a.$OBJEXT
151 test -f sub2/a.$OBJEXT
152
153 # ... but they get removed by "make mostlyclean" ...
154 $MAKE mostlyclean
155 test ! -e sub1/a.$OBJEXT
156 test ! -e sub2/d.$OBJEXT
157
158 # ... and do not get rebuilt ...
159 $MAKE clean
160 $MAKE all
161 test ! -e sub1/a.$OBJEXT
162 test ! -e sub2/d.$OBJEXT
163
164 # ... while the non-stale files do.
165 test -f sub1/b.$OBJEXT
166 test -f sub2/x.$OBJEXT
167
168 :