# user-supplied directories first, then the directory containing the
# automake macros, and finally the system-wide directories for
# third-party macros.
-# @user_includes can be augmented with -I or AC_CONFIG_MACRO_DIR.
+# @user_includes can be augmented with -I or AC_CONFIG_MACRO_DIRS.
# @automake_includes can be reset with the '--automake-acdir' option.
# @system_includes can be augmented with the 'dirlist' file or the
# ACLOCAL_PATH environment variable, and reset with the '--system-acdir'
# Autoconf version. This variable is set by 'trace_used_macros'.
my $ac_version;
-# Primary user directory containing extra m4 files for macros
-# definition, as extracted from call to macro AC_CONFIG_MACRO_DIR.
-# This variable is set by 'trace_used_macros'.
-my $ac_config_macro_dir;
+# User directory containing extra m4 files for macros definition,
+# as extracted from calls to the macro AC_CONFIG_MACRO_DIRS.
+# This variable is updated by 'trace_used_macros'.
+my @ac_config_macro_dirs;
# If set, names a temporary file that must be erased on abnormal exit.
my $erase_me;
'AC_DEFUN_ONCE',
'AU_DEFUN',
'_AM_AUTOCONF_VERSION',
- 'AC_CONFIG_MACRO_DIR')),
+ 'AC_CONFIG_MACRO_DIR',
+ 'AC_CONFIG_MACRO_DIRS')),
# Do not trace $1 for all other macros as we do
# not need it and it might contains harmful
# characters (like newlines).
my $tracefh = new Automake::XFile ("$traces $configure_ac |");
- $ac_config_macro_dir = undef;
+ @ac_config_macro_dirs = ();
my %traced = ();
}
elsif ($macro eq 'AC_CONFIG_MACRO_DIR')
{
- $ac_config_macro_dir = $arg1;
+ @ac_config_macro_dirs = ($arg1);
+ }
+ elsif ($macro eq 'AC_CONFIG_MACRO_DIRS')
+ {
+ push @ac_config_macro_dirs, split (/\s+/, $arg1);
}
}
last if $exit_code;
my %macro_traced = trace_used_macros;
- if (!$rerun_due_to_macrodir && defined $ac_config_macro_dir)
+ if (!$rerun_due_to_macrodir && @ac_config_macro_dirs)
{
- # The directory specified by the AC_CONFIG_MACRO_DIR m4 macro
- # (if any) must after the user includes specified explicitly
- # with the '-I' option.
- push @user_includes, $ac_config_macro_dir
- if defined $ac_config_macro_dir;
+ # The directory specified in calls to the AC_CONFIG_MACRO_DIRS
+ # m4 macro (if any) must go after the user includes specified
+ # explicitly with the '-I' option.
+ push @user_includes, @ac_config_macro_dirs;
# We might have to scan some new directory of .m4 files.
$rerun_due_to_macrodir++;
next;
if ($install && !@user_includes)
{
fatal "installation of third-party macros impossible without " .
- "-I options nor AC_CONFIG_MACRO_DIR m4 macro";
+ "-I options nor AC_CONFIG_MACRO_DIR{,S} m4 macro(s)";
}
last if write_aclocal ($output_file, keys %macro_traced);
--- /dev/null
+#! /bin/sh
+# Copyright (C) 2012 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Several tests on the use of the m4 macro AC_CONFIG_MACRO_DIRS with
+# aclocal. See also related test 'aclocal-macrodir.tap'.
+
+am_create_testdir=empty
+. test-init.sh
+
+{ $AUTOCONF -o /dev/null - <<END
+ AC_INIT([x], [0])
+ AC_CONFIG_MACRO_DIRS([.])
+END
+} || skip_all_ "autoconf doesn't define the AC_CONFIG_MACRO_DIRS macro"
+
+plan_ 11
+
+ocwd=$(pwd) || fatal_ "getting current working directory"
+ACLOCAL_PATH=; unset ACLOCAL_PATH
+
+#
+# General utility functions and variables.
+#
+# TODO: These should maybe be refactored, generalized and
+# moved into 't/ax/tap-functions.sh' ...
+#
+
+tcount=0
+r=invalid
+description=''
+directive=''
+
+test_begin ()
+{
+ if test -n "$description"; then
+ fatal_ "'test_begin' called, but another test seems active already"
+ else
+ r=ok
+ description=$1
+ directive=${2-}
+ echo "$description" > README.txt
+ shift
+ fi
+ tcount=$(($tcount + 1)) && test $tcount -gt 0 \
+ || fatal_ "failed to bump the test count"
+ mkdir $tcount.d
+ cd $tcount.d
+}
+
+test_end ()
+{
+ if test -z "$description"; then
+ fatal_ "'test_end' called, but no test seems active"
+ else
+ cd "$ocwd" || fatal_ "cannot chdir back to top-level directory"
+ result_ "$r" -D "$directive" -- "$description"
+ # Don't leave directories for successful subtests hanging around.
+ if test -z "$directive" && test "$r" = ok; then
+ rm -rf "$tcount.d" || fatal_ "removing subdir $tcount.d"
+ fi
+ r=invalid directive= description=
+ fi
+}
+
+#---------------------------------------------------------------------------
+
+test_begin "AC_CONFIG_MACRO_DIRS is honored"
+
+cat > configure.ac <<'END'
+AC_INIT([md], [10.0])
+AC_CONFIG_MACRO_DIRS([macro-dir])
+MY_FOO
+END
+
+mkdir macro-dir
+echo 'AC_DEFUN([MY_FOO], [::my::foo::])' > macro-dir/foo.m4
+
+$ACLOCAL \
+ && $FGREP 'm4_include([macro-dir/foo.m4])' aclocal.m4 \
+ && $AUTOCONF \
+ && not $FGREP 'MY_FOO' configure \
+ && $FGREP '::my::foo::' configure \
+ || r='not ok'
+
+test_end
+
+#---------------------------------------------------------------------------
+
+two_dirs_check ()
+{
+ mkdir dir1 dir2
+ echo 'AC_DEFUN([MY_FOO], [::my::foo::])' > dir1/foo.m4
+ echo 'AC_DEFUN([MY_BAR], [!!my!!bar!!])' > dir2/zap.m4
+ $ACLOCAL \
+ && $FGREP 'm4_include([dir1/foo.m4])' aclocal.m4 \
+ && $FGREP 'm4_include([dir2/zap.m4])' aclocal.m4 \
+ && $AUTOCONF \
+ && not $EGREP 'MY_(FOO|BAR)' configure \
+ && $FGREP '::my::foo::' configure \
+ && $FGREP '!!my!!bar!!' configure \
+ || r='not ok'
+}
+
+#---------------------------------------------------------------------------
+
+test_begin "AC_CONFIG_MACRO_DIRS: several arguments"
+
+cat > configure.ac <<'END'
+AC_INIT([more-args], [0.2])
+AC_CONFIG_MACRO_DIRS([dir1 dir2])
+MY_FOO
+MY_BAR
+END
+
+two_dirs_check
+
+test_end
+
+#---------------------------------------------------------------------------
+
+test_begin "AC_CONFIG_MACRO_DIRS: several calls"
+
+cat > configure.ac <<'END'
+AC_INIT([more-calls], [2.0])
+AC_CONFIG_MACRO_DIRS([dir1])
+AC_CONFIG_MACRO_DIRS([dir2])
+MY_FOO
+MY_BAR
+END
+
+two_dirs_check
+
+test_end
+
+#---------------------------------------------------------------------------
+
+test_begin "AC_CONFIG_MACRO_DIRS interaction with --install"
+
+cat > configure.ac << 'END'
+AC_INIT([inst], [1.0])
+AC_CONFIG_MACRO_DIRS([the-dir])
+THE_MACRO
+END
+
+mkdir sys-dir the-dir
+echo 'AC_DEFUN([THE_MACRO], [:])' > sys-dir/my.m4
+
+test ! -r the-dir/my.m4 \
+ && $ACLOCAL --install --system-acdir ./sys-dir \
+ && diff sys-dir/my.m4 the-dir/my.m4 \
+ || r='not ok'
+
+test_end
+
+#---------------------------------------------------------------------------
+
+two_dirs_install_check ()
+{
+ mkdir sys-dir dir1 dir2
+ echo 'AC_DEFUN([THE_MACRO], [:])' > sys-dir/my.m4
+ echo 'AC_DEFUN([AX_FOO], [:])' > dir2/zap.m4
+ test ! -r dir1/my.m4 \
+ && $ACLOCAL --install --system-acdir ./sys-dir \
+ && diff sys-dir/my.m4 dir1/my.m4 \
+ && test ! -e dir2/my.m4 \
+ && $FGREP 'm4_include([dir1/my.m4])' aclocal.m4 \
+ && $FGREP 'm4_include([dir2/zap.m4])' aclocal.m4 \
+ || r='not ok'
+}
+
+#---------------------------------------------------------------------------
+
+test_begin "several AC_CONFIG_MACRO_DIRS arguments and --install"
+
+cat > configure.ac << 'END'
+AC_INIT([inst2a], [1.0])
+AC_CONFIG_MACRO_DIRS([dir1 dir2])
+THE_MACRO
+AX_FOO
+END
+
+two_dirs_install_check
+
+test_end
+
+#---------------------------------------------------------------------------
+
+
+test_begin "several AC_CONFIG_MACRO_DIRS calls and --install"
+
+cat > configure.ac << 'END'
+AC_INIT([inst2b], [1.0])
+AC_CONFIG_MACRO_DIRS([dir1])
+AC_CONFIG_MACRO_DIRS([dir2])
+THE_MACRO
+AX_FOO
+END
+
+two_dirs_install_check
+
+test_end
+
+#---------------------------------------------------------------------------
+
+test_begin "'-I' option wins over AC_CONFIG_MACRO_DIRS"
+
+cat > configure.ac <<'END'
+AC_INIT([md], [4.6])
+AC_CONFIG_MACRO_DIRS([dir1])
+MY_FOO
+END
+
+mkdir dir1 dir2
+echo 'AC_DEFUN([MY_FOO], [::ko::ko::])' > dir1/1.m4
+echo 'AC_DEFUN([MY_FOO], [::ok::ok::])' > dir2/2.m4
+
+$ACLOCAL -I dir2 \
+ && $FGREP 'm4_include([dir2/2.m4])' aclocal.m4 \
+ && not $FGREP 'm4_include([dir1/1.m4])' aclocal.m4 \
+ && $AUTOCONF \
+ && not $FGREP '::ko::ko::' configure \
+ && $FGREP '::ok::ok::' configure \
+ || r='not ok'
+
+test_end
+
+#---------------------------------------------------------------------------
+
+test_begin "AC_CONFIG_MACRO_DIRS([foo]) can create directory 'foo'"
+
+cat > configure.ac << 'END'
+AC_INIT([x], [1.0])
+AC_CONFIG_MACRO_DIRS([foo])
+MY_MACRO
+END
+
+mkdir acdir
+echo 'AC_DEFUN([MY_MACRO], [:])' > acdir/bar.m4
+
+test ! -d foo \
+ && $ACLOCAL --install --system-acdir ./acdir \
+ && diff acdir/bar.m4 foo/bar.m4 \
+ || r='not ok'
+
+test_end
+
+#---------------------------------------------------------------------------
+
+test_begin "AC_CONFIG_MACRO_DIRS([non-existent]) errors out (1)"
+
+cat > configure.ac << 'END'
+AC_INIT([oops], [1.0])
+AC_CONFIG_MACRO_DIRS([non-existent])
+END
+
+not $ACLOCAL 2>stderr \
+ && cat stderr >&2 \
+ && grep "couldn't open directory 'non-existent'" stderr \
+ || r='not ok'
+
+test_end
+
+#---------------------------------------------------------------------------
+
+test_begin "AC_CONFIG_MACRO_DIRS([non-existent]) errors out (2)"
+
+cat > configure.ac << 'END'
+AC_INIT([oops], [1.0])
+AC_CONFIG_MACRO_DIRS([dir-ok])
+AC_CONFIG_MACRO_DIRS([dir-ko])
+END
+
+mkdir dir-ok
+not $ACLOCAL 2>stderr \
+ && cat stderr >&2 \
+ && grep "couldn't open directory 'dir-ko'" stderr \
+ && not grep "dir-ok" stderr \
+ || r='not ok'
+
+test_end
+
+#---------------------------------------------------------------------------
+
+test_begin "AC_CONFIG_MACRO_DIRS([non-existent]) errors out (tricky setup)" \
+ TODO
+
+cat > configure.ac << 'END'
+AC_INIT([oops], [1.0])
+AC_CONFIG_MACRO_DIRS([dir-ok])
+AC_CONFIG_MACRO_DIRS([dir-ko])
+END
+
+mkdir dir-ok
+
+not $ACLOCAL --install 2>stderr \
+ && cat stderr >&2 \
+ && grep "couldn't open directory 'dir-ko'" stderr \
+ && test ! -e dir-ko \
+ || r='not ok'
+
+test_end
+
+#---------------------------------------------------------------------------
+
+:
--- /dev/null
+#! /bin/sh
+# Copyright (C) 2002-2012 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Subpackages that want to use m4 macros from their superpackages,
+# with AC_CONFIG_MACRO_DIRS.
+
+. test-init.sh
+
+{ $AUTOCONF -o /dev/null - <<END
+ AC_INIT([x], [0])
+ AC_CONFIG_MACRO_DIRS([.])
+END
+} || skip_ "autoconf doesn't define the AC_CONFIG_MACRO_DIRS macro"
+
+cat > configure.ac <<'END'
+AC_INIT([super], [1.0])
+AM_INIT_AUTOMAKE
+AC_CONFIG_MACRO_DIR([m4])
+AC_CONFIG_SUBDIRS([pkg])
+AX_BAR
+AX_FOO
+END
+
+mkdir m4
+
+cat > m4/foo.m4 <<'EOF'
+AC_DEFUN([AX_FOO], [
+ AC_CONFIG_FILES([Makefile])
+ AC_OUTPUT
+])
+EOF
+
+cat > m4/bar.m4 <<'EOF'
+AC_DEFUN([AX_BAR], [AC_SUBST([WHOMAI], [SuperPkg])])
+EOF
+
+cat > Makefile.am << 'END'
+test-whomai:
+ test '$(WHOAMI)' = SuperPkg
+check-local: test
+.PHONY: test
+END
+
+mkdir pkg
+
+cat > pkg/configure.ac <<'END'
+AC_INIT([super], [1.0])
+AM_INIT_AUTOMAKE
+AC_CONFIG_MACRO_DIRS([macros ../m4])
+AX_BAR
+AX_FOO
+END
+
+mkdir pkg/macros
+cat > pkg/macros/zardoz.m4 << 'END'
+AC_DEFUN([AX_BAR], [AC_SUBST([WHOMAI], [sub-pkg])])
+END
+
+cat > pkg/Makefile.am << 'END'
+test-whomai:
+ test '$(WHOAMI)' = sub-pkg
+check-local: test
+.PHONY: test
+END
+
+AUTOMAKE=$AUTOMAKE ACLOCAL=$ACLOCAL AUTOCONF=$AUTOCONF $AUTORECONF -vi
+
+$FGREP 'm4_include([m4/foo.m4])' aclocal.m4
+$FGREP 'm4_include([m4/bar.m4])' aclocal.m4
+$FGREP 'm4_include([../m4/foo.m4])' pkg/aclocal.m4
+$FGREP 'm4_include([macros/zardoz.m4])' pkg/aclocal.m4
+
+./configure
+
+$MAKE test
+(cd pkg && $MAKE test) || exit 1
+
+$MAKE distcheck
+
+: