2 # Copyright (C) 2012 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)
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 <http://www.gnu.org/licenses/>.
17 # Several tests on the use of the m4 macro AC_CONFIG_MACRO_DIRS with
18 # aclocal. See also related test 'aclocal-macrodir.tap'.
20 am_create_testdir=empty
25 ocwd=$(pwd) || fatal_ "getting current working directory"
26 ACLOCAL_PATH=; unset ACLOCAL_PATH
29 # General utility functions and variables.
31 # TODO: These should maybe be refactored, generalized and
32 # moved into 't/ax/tap-functions.sh' ...
42 if test -n "$description"; then
43 fatal_ "'test_begin' called, but another test seems active already"
48 echo "$description" > README.txt
51 tcount=$(($tcount + 1)) && test $tcount -gt 0 \
52 || fatal_ "failed to bump the test count"
59 if test -z "$description"; then
60 fatal_ "'test_end' called, but no test seems active"
62 cd "$ocwd" || fatal_ "cannot chdir back to top-level directory"
63 result_ "$r" -D "$directive" -- "$description"
64 # Don't leave directories for successful subtests hanging around.
65 if test -z "$directive" && test "$r" = ok; then
66 rm -rf "$tcount.d" || fatal_ "removing subdir $tcount.d"
68 r=invalid directive= description=
72 #---------------------------------------------------------------------------
74 test_begin "AC_CONFIG_MACRO_DIRS is honored"
76 cat > configure.ac <<'END'
78 AC_CONFIG_MACRO_DIRS([macro-dir])
83 echo 'AC_DEFUN([MY_FOO], [::my::foo::])' > macro-dir/foo.m4
86 && $FGREP 'm4_include([macro-dir/foo.m4])' aclocal.m4 \
88 && not $FGREP 'MY_FOO' configure \
89 && $FGREP '::my::foo::' configure \
94 #---------------------------------------------------------------------------
99 echo 'AC_DEFUN([MY_FOO], [::my::foo::])' > dir1/foo.m4
100 echo 'AC_DEFUN([MY_BAR], [!!my!!bar!!])' > dir2/zap.m4
101 echo 'AC_DEFUN([MY_BAZ], [==my==baz==])' > dir3/0.m4
103 && $FGREP 'm4_include([dir1/foo.m4])' aclocal.m4 \
104 && $FGREP 'm4_include([dir2/zap.m4])' aclocal.m4 \
105 && $FGREP 'm4_include([dir3/0.m4])' aclocal.m4 \
107 && not $EGREP 'MY_(FOO|BAR|BAZ)' configure \
108 && $FGREP '::my::foo::' configure \
109 && $FGREP '!!my!!bar!!' configure \
110 && $FGREP '==my==baz==' configure \
114 #---------------------------------------------------------------------------
116 test_begin "AC_CONFIG_MACRO_DIRS several arguments"
118 cat > configure.ac <<'END'
119 AC_INIT([more-args], [0.2])
120 AC_CONFIG_MACRO_DIRS([dir1 dir2 dir3])
130 #---------------------------------------------------------------------------
132 test_begin "AC_CONFIG_MACRO_DIRS several calls"
134 cat > configure.ac <<'END'
135 AC_INIT([more-calls], [2.0])
136 AC_CONFIG_MACRO_DIRS([dir1])
137 AC_CONFIG_MACRO_DIRS([dir2 dir3])
147 #---------------------------------------------------------------------------
149 test_begin "AC_CONFIG_MACRO_DIRS extra whitespace"
153 cat > configure.ac <<END
154 AC_INIT([more-args], [0.2])
155 AC_CONFIG_MACRO_DIRS([ dir1${bslash}
156 ${tab} dir2 ${tab}${tab}dir3
169 #---------------------------------------------------------------------------
171 test_begin "AC_CONFIG_MACRO_DIRS precedence"
173 cat > configure.ac <<'END'
174 AC_INIT([more-calls], [2.0])
175 AC_CONFIG_MACRO_DIRS([dir1])
176 AC_CONFIG_MACRO_DIRS([dir2 dir3])
183 echo 'AC_DEFUN([MY_FOO], [OK-Foo])' > dir1/b.m4
184 echo 'AC_DEFUN([MY_FOO], [KO-Foo])' > dir2/a.m4
185 echo 'AC_DEFUN([MY_BAR], [OK-Bar])' > dir2/1.m4
186 echo 'AC_DEFUN([MY_BAR], [KO-Bar])' > dir3/0.m4
187 echo 'AC_DEFUN([MY_BAZ], [OK-Baz])' > dir3/x.m4
190 && $FGREP 'm4_include([dir1/b.m4])' aclocal.m4 \
191 && $FGREP 'm4_include([dir2/1.m4])' aclocal.m4 \
192 && $FGREP 'm4_include([dir3/x.m4])' aclocal.m4 \
193 && test $($FGREP -c 'm4_include([dir1' aclocal.m4) -eq 1 \
194 && test $($FGREP -c 'm4_include([dir2' aclocal.m4) -eq 1 \
195 && test $($FGREP -c 'm4_include([dir3' aclocal.m4) -eq 1 \
197 && not $EGREP 'MY_(FOO|BAR|BAZ)' configure \
198 && $FGREP 'OK-Foo' configure \
199 && $FGREP 'OK-Bar' configure \
200 && $FGREP 'OK-Baz' configure \
201 && not $FGREP 'KO-' configure \
206 #---------------------------------------------------------------------------
208 test_begin "AC_CONFIG_MACRO_DIRS interaction with --install"
210 cat > configure.ac << 'END'
211 AC_INIT([inst], [1.0])
212 AC_CONFIG_MACRO_DIRS([the-dir])
216 mkdir sys-dir the-dir
217 echo 'AC_DEFUN([THE_MACRO], [:])' > sys-dir/my.m4
219 test ! -r the-dir/my.m4 \
220 && $ACLOCAL --install --system-acdir ./sys-dir \
221 && diff sys-dir/my.m4 the-dir/my.m4 \
226 #---------------------------------------------------------------------------
228 two_dirs_install_check ()
230 mkdir sys-dir dir1 dir2
231 echo 'AC_DEFUN([THE_MACRO], [:])' > sys-dir/my.m4
232 echo 'AC_DEFUN([AX_FOO], [:])' > dir2/zap.m4
233 test ! -r dir1/my.m4 \
234 && $ACLOCAL --install --system-acdir ./sys-dir \
235 && diff sys-dir/my.m4 dir1/my.m4 \
236 && test ! -e dir2/my.m4 \
237 && $FGREP 'm4_include([dir1/my.m4])' aclocal.m4 \
238 && $FGREP 'm4_include([dir2/zap.m4])' aclocal.m4 \
242 #---------------------------------------------------------------------------
244 test_begin "several AC_CONFIG_MACRO_DIRS arguments and --install"
246 cat > configure.ac << 'END'
247 AC_INIT([inst2a], [1.0])
248 AC_CONFIG_MACRO_DIRS([dir1 dir2])
253 two_dirs_install_check
257 #---------------------------------------------------------------------------
260 test_begin "several AC_CONFIG_MACRO_DIRS calls and --install"
262 cat > configure.ac << 'END'
263 AC_INIT([inst2b], [1.0])
264 AC_CONFIG_MACRO_DIRS([dir1])
265 AC_CONFIG_MACRO_DIRS([dir2])
270 two_dirs_install_check
274 #---------------------------------------------------------------------------
276 test_begin "'-I' option wins over AC_CONFIG_MACRO_DIRS"
278 cat > configure.ac <<'END'
280 AC_CONFIG_MACRO_DIRS([dir1])
285 echo 'AC_DEFUN([MY_FOO], [::ko::ko::])' > dir1/1.m4
286 echo 'AC_DEFUN([MY_FOO], [::ok::ok::])' > dir2/2.m4
289 && $FGREP 'm4_include([dir2/2.m4])' aclocal.m4 \
290 && not $FGREP 'm4_include([dir1/1.m4])' aclocal.m4 \
292 && not $FGREP '::ko::ko::' configure \
293 && $FGREP '::ok::ok::' configure \
298 #---------------------------------------------------------------------------
300 test_begin "AC_CONFIG_MACRO_DIRS([foo]) can create directory 'foo'"
302 cat > configure.ac << 'END'
304 AC_CONFIG_MACRO_DIRS([foo])
309 echo 'AC_DEFUN([MY_MACRO], [:])' > acdir/bar.m4
312 && $ACLOCAL --install --system-acdir ./acdir \
313 && diff acdir/bar.m4 foo/bar.m4 \
318 #---------------------------------------------------------------------------
320 test_begin "AC_CONFIG_MACRO_DIRS([non-existent]) errors out (1)"
322 cat > configure.ac << 'END'
323 AC_INIT([oops], [1.0])
324 AC_CONFIG_MACRO_DIRS([non-existent])
327 not $ACLOCAL 2>stderr \
329 && grep "couldn't open directory 'non-existent'" stderr \
334 #---------------------------------------------------------------------------
336 test_begin "AC_CONFIG_MACRO_DIRS([non-existent]) errors out (2)"
338 cat > configure.ac << 'END'
339 AC_INIT([oops], [1.0])
340 AC_CONFIG_MACRO_DIRS([dir-ok])
341 AC_CONFIG_MACRO_DIRS([dir-ko])
345 not $ACLOCAL 2>stderr \
347 && grep "couldn't open directory 'dir-ko'" stderr \
348 && not grep "dir-ok" stderr \
353 #---------------------------------------------------------------------------
355 test_begin "AC_CONFIG_MACRO_DIRS([non-existent]) errors out (tricky setup)"
357 cat > configure.ac << 'END'
358 AC_INIT([oops], [1.0])
359 AC_CONFIG_MACRO_DIRS([dir-ok])
360 AC_CONFIG_MACRO_DIRS([dir-ko])
365 not $ACLOCAL -Wnone --install 2>stderr \
367 && grep "couldn't open directory 'dir-ko'" stderr \
368 && test ! -e dir-ko \
373 #---------------------------------------------------------------------------
375 # Avoid spurious failures with pre-2.70 autoconf.
376 # FIXME: remove this in automake 1.14, once we require Autoconf 2.70.
377 if echo 'AC_INIT AC_CONFIG_MACRO_DIRS' | $AUTOCONF -o/dev/null -; then
379 test_begin "AC_CONFIG_MACRO_DIRS interaction with AC_REQUIRE"
381 unindent > configure.ac <<'END'
382 AC_INIT([req], [1.0])
383 AC_CONFIG_MACRO_DIRS([m1 m2])
392 echo 'AC_DEFUN([MY_BAR], [^^my^^bar^^])' > m1/x.m4
393 echo 'AC_DEFUN([MY_BAZ], [~~my~~baz~~])' > m2/x.m4
395 st=0; $ACLOCAL 2>stderr || st=$?
399 && test ! -s stderr \
400 && $FGREP 'm4_include([m1/x.m4])' aclocal.m4 \
401 && $FGREP 'm4_include([m2/x.m4])' aclocal.m4 \
403 && not $EGREP 'MY_(FOO|BAR|BAZ)' configure \
404 && $FGREP '^^my^^bar^^' configure \
405 && $FGREP '~~my~~baz~~' configure \
412 skip_ -r "autoconf is too old (AC_CONFIG_MACRO_DIRS not defined)"