maintcheck: fix failures, both real and spurious
[platform/upstream/automake.git] / t / subobj-clean-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 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.
23
24 required=cc
25 . ./defs || Exit 1
26
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
33
34 echo "OBJEXT='@OBJEXT@'" > get-objext.in
35
36 oPATH=$PATH
37 ocwd=`pwd` || fatal_ "getting current working directory"
38
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 #!/bin/sh
45 set -e
46 count=\`cat '$count_file'\`
47 count=\`expr \$count + 1\`
48 if test \$count -le $max_rm_invocations; then :; else
49   echo "rm invoked more than $max_rm_invocations times" >&2
50   exit 1
51 fi
52 echo "\$count" > '$count_file'
53 PATH='$oPATH'; export PATH
54 exec rm "\$@"
55 END
56 chmod a+x rm-wrap/rm
57 echo "0" > rm-wrap/count
58
59 cat > Makefile.am <<'END'
60 .PHONY: sanity-check-rm
61 sanity-check-rm:
62         rm -f 1
63         rm -f 2
64         rm -f 3
65         rm -f x && exit 1; :
66         echo "0" > rm-wrap/count
67
68 AUTOMAKE_OPTIONS = subdir-objects
69 bin_PROGRAMS = foo
70 foo_SOURCES = \
71   sub1/a.c \
72   sub1/b.c \
73   sub1/c.c \
74   sub1/d.c \
75   sub1/e.c \
76   sub1/f.c \
77   sub2/a.c \
78   sub2/b.c \
79   sub2/c.c \
80   sub2/d.c \
81   sub2/e.c \
82   sub2/f.c \
83   main.c
84 END
85
86 mkdir sub1 sub2
87 echo 'int main (void)' > main.c
88 echo '{' >> main.c
89 for i in 1 2; do
90   for j in a b c d e f; do
91     echo "void $j$i (void) { }" > sub$i/$j.c
92     echo "  $j$i ();" >> main.c
93   done
94 done
95 echo '  return 0;' >> main.c
96 echo '}' >> main.c
97 cat main.c # For debugging.
98
99 $ACLOCAL
100 $AUTOCONF
101 $AUTOMAKE -a
102
103 ./configure
104
105 test -f get-objext.sh
106 . ./get-objext.sh
107
108 $MAKE
109
110 # This must go after configure, since that will invoke rm many times.
111 PATH=$ocwd/rm-wrap$PATH_SEPARATOR$PATH; export PATH
112 $MAKE sanity-check-rm || fatal_ "rm wrapper doesn't work as expected"
113
114 $MAKE mostlyclean
115 ls -l . sub1 sub2
116 for i in 1 2; do
117   for j in a b c d e f; do
118     test ! -f sub$i/$j.o
119     test ! -f sub$i/$j.obj
120     test -f sub$i/$j.c || Exit 99 # Sanity check
121   done
122 done
123
124 PATH=$oPATH; export PATH
125 rm -rf rm-wrap
126
127 $MAKE clean
128 $MAKE
129 test -f sub1/a.$OBJEXT
130 test -f sub2/d.$OBJEXT
131
132 $sleep
133
134 mv -f sub2/d.c sub2/x.c
135 rm -f sub1/a.c
136
137 sed -e '/ a1 ()/d' main.c > t
138 mv -f t main.c
139
140 sed -e '/sub1\/a\.c/d' -e 's|sub2/d\.c|sub2/x.c|' Makefile.am > t
141 mv -f t Makefile.am
142
143 using_gmake || $MAKE Makefile
144 $MAKE
145 test -f sub2/x.$OBJEXT
146
147 # The stale objects are still there after a mere "make all" ...
148 test -f sub1/a.$OBJEXT
149 test -f sub2/a.$OBJEXT
150
151 # ... but they get removed by "make mostlyclean" ...
152 $MAKE mostlyclean
153 test ! -f sub1/a.$OBJEXT
154 test ! -f sub2/d.$OBJEXT
155
156 # ... and do not get rebuilt ...
157 $MAKE clean
158 $MAKE all
159 test ! -f sub1/a.$OBJEXT
160 test ! -f sub2/d.$OBJEXT
161
162 # ... while the non-stale files do.
163 test -f sub1/b.$OBJEXT
164 test -f sub2/x.$OBJEXT
165
166 :