tests: expose automake bug#14560
[platform/upstream/automake.git] / t / remake-makefile-vpath.sh
1 #! /bin/sh
2 # Copyright (C) 2010-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 # Test basic remake rules for Makefiles, for a *VPATH build*.
18 # This testcase checks dependency of generated Makefile from Makefile.am,
19 # configure.ac, acinclude.m4, aclocal.m4, and extra m4 files considered
20 # by aclocal.
21 # Keep this in sync with sister test 'remake-makefile-instree.sh', which
22 # performs the same checks for a in-tree build.
23
24 . test-init.sh
25
26 mv -f configure.ac configure.stub
27
28 cat > Makefile.am <<'END'
29 all-local: foo
30 foo:
31         echo '!Foo!' >$@
32 check-local:
33         cat foo
34         grep '!Foo!' foo
35 CLEANFILES = foo
36 END
37
38 cat configure.stub - > configure.ac <<'END'
39 AC_OUTPUT
40 END
41
42 $ACLOCAL
43 $AUTOCONF
44 $AUTOMAKE
45
46 mkdir build
47 cd build
48 srcdir='..' # To make syncing with remake-makefile-intree.sh easier.
49
50 $srcdir/configure
51
52 $MAKE
53 cat foo
54 grep '!Foo!' foo
55 $MAKE distcheck
56
57 rm -f foo
58
59 # Modify just Makefile.am.
60
61 $sleep
62
63 cat > $srcdir/Makefile.am <<'END'
64 all-local: bar
65 bar:
66         echo '!Baz!' >$@
67 check-local:
68         cat bar
69         grep '!Baz!' bar
70         test ! -r $(srcdir)/foo
71         test ! -r foo
72 CLEANFILES = bar
73 END
74
75 using_gmake || $MAKE Makefile
76 $MAKE
77 cat bar
78 grep '!Baz!' bar
79 test ! -e foo
80 $MAKE distcheck
81
82 rm -f bar
83
84 # Modify Makefile.am and configure.ac.
85
86 $sleep
87
88 cat > $srcdir/Makefile.am <<'END'
89 check-local:
90         cat quux
91         grep '!Zardoz!' quux
92         test ! -r $(srcdir)/bar
93         test ! -r bar
94 END
95
96 cat $srcdir/configure.stub - > $srcdir/configure.ac <<'END'
97 AC_CONFIG_FILES([quux])
98 AC_SUBST([QUUX], [Zardoz])
99 AC_OUTPUT
100 END
101
102 cat > $srcdir/quux.in <<'END'
103 !@QUUX@!
104 END
105
106 using_gmake || $MAKE Makefile
107 $MAKE
108 cat quux
109 grep '!Zardoz!' quux
110 test ! -e bar
111 $MAKE distcheck
112
113 rm -f quux
114
115 # Modify configure.ac and aclocal.m4 to add a directory of extra m4
116 # files considered by aclocal.  Also update checks in Makefile.am.
117 # Note that we won't use this new directory of extra m4 files in the
118 # first rebuild below (but we will in the second).
119
120 $sleep
121
122 mkdir $srcdir/m4
123
124 cat > $srcdir/Makefile.am <<'END'
125 all-local: quux
126 check-local:
127         cat quux
128         grep '%Foo%' quux
129         test x'$(QUUX)' = x'%Foo%'
130 END
131
132 # Modify configure.ac and aclocal.m4.
133
134 $sleep
135
136 cat $srcdir/configure.stub - > $srcdir/configure.ac <<'END'
137 AC_CONFIG_MACRO_DIR([m4])
138 AC_CONFIG_FILES([quux])
139 MY_CUSTOM_MACRO
140 AC_OUTPUT
141 END
142
143 cat >> $srcdir/aclocal.m4 <<'END'
144 AC_DEFUN([MY_CUSTOM_MACRO], [AC_SUBST([QUUX], [%Foo%])])
145 END
146
147 $MAKE
148 cat quux
149 grep '%Foo%' quux
150 $MAKE distcheck
151
152 # Modify Makefile.am, remove aclocal.m4, and add a new m4 file to
153 # the directory of extra m4 files considered by aclocal.  This new
154 # file should now provide a macro required by configure.ac and that
155 # was previously provided by aclocal.m4.
156
157 $sleep
158
159 sed 's/%Foo%/%Bar%/g' $srcdir/Makefile.am > t
160 mv -f t $srcdir/Makefile.am
161 cat $srcdir/Makefile.am
162 rm -f $srcdir/aclocal.m4
163 cat > $srcdir/m4/blah.m4 <<'END'
164 AC_DEFUN([MY_CUSTOM_MACRO], [AC_SUBST([QUUX], [%Bar%])])
165 END
166
167 $MAKE
168 cat quux
169 grep '%Bar%' quux
170 $MAKE distcheck
171
172 # Modify Makefile.am, remove all the extra m4 files to considered
173 # by aclocal, and add an acinclude.m4 file.  This last file should
174 # now provide a macro required by configure.ac, and that was
175 # previously provided by the extra m4 files considered by aclocal.
176
177 $sleep
178
179 rm -f $srcdir/m4/*.m4
180 sed 's/%Bar%/%Quux%/g' $srcdir/Makefile.am > t
181 mv -f t $srcdir/Makefile.am
182 cat $srcdir/Makefile.am
183 cat > $srcdir/acinclude.m4 <<'END'
184 AC_DEFUN([MY_CUSTOM_MACRO], [AC_SUBST([QUUX], [%Quux%])])
185 END
186
187 $MAKE
188 cat quux
189 grep '%Quux%' quux
190 $MAKE distcheck
191
192 :