summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefano Lattarini <stefano.lattarini@gmail.com>2012-07-03 21:15:33 +0200
committerStefano Lattarini <stefano.lattarini@gmail.com>2012-07-03 21:15:33 +0200
commit5e0539a3cc36e426e315ebf55df95b78f4822235 (patch)
tree1e619ff0b8ef692d274238d17dd93e21bafeabd0
parent67abae49732991b596e6fa6d9d93a925720abe64 (diff)
parentcd1a9ccc1bd0248d2c504f367089f2481d364324 (diff)
downloadautomake-5e0539a3cc36e426e315ebf55df95b78f4822235.tar.gz
Merge branch 'aclocal-trace-macrodir'
* aclocal-trace-macrodir: aclocal: deprecate ACLOCAL_AMFLAGS, trace AC_CONFIG_MACRO_DIR instead Signed-off-by: Stefano Lattarini <stefano.lattarini@gmail.com>
-rw-r--r--NEWS11
-rw-r--r--aclocal.in63
-rw-r--r--doc/automake.texi93
-rw-r--r--lib/am/configure.am6
-rwxr-xr-xt/acloca14.sh2
-rwxr-xr-xt/acloca14b.sh108
-rwxr-xr-xt/acloca22.sh12
-rwxr-xr-xt/acloca22b.sh59
-rwxr-xr-xt/aclocal-amflags.sh69
-rw-r--r--t/aclocal-macrodir.tap161
-rwxr-xr-xt/aclocal-path-install.sh2
-rwxr-xr-xt/aclocal4.sh4
-rwxr-xr-xt/aclocal5.sh16
-rwxr-xr-xt/aclocal6.sh4
-rw-r--r--t/list-of-tests.mk5
-rwxr-xr-xt/remake-macrodir.sh83
-rwxr-xr-xt/remake10c.sh4
-rwxr-xr-xt/remake8a.sh12
-rwxr-xr-xt/remake8b.sh12
-rwxr-xr-xt/subdir-add2-pr46.sh4
-rwxr-xr-xt/subpkg.sh10
-rwxr-xr-xt/subpkg2.sh10
22 files changed, 623 insertions, 127 deletions
diff --git a/NEWS b/NEWS
index 292f628e5..dc2fdb3d1 100644
--- a/NEWS
+++ b/NEWS
@@ -88,6 +88,17 @@ New in 1.13:
specifying the name of such targets in invocations of the new
'AM_EXTRA_RECURSIVE_TARGETS' m4 macro.
+* Improvements to aclocal and related rebuilds rules:
+
+ - The Autoconf-provided macro AC_CONFIG_MACRO_DIR is now traced by
+ aclocal, and can be used to declare the local m4 include directory.
+ Formerly, one had to specify it with an explicit '-I' option to the
+ 'aclocal' invocation.
+
+ - The special make variable ACLOCAL_AMFLAGS is deprecated; future
+ Automake versions will warn about its use, and later version will
+ remove support for it altogether.
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
New in 1.12.2:
diff --git a/aclocal.in b/aclocal.in
index c7cde7d6d..e2e953626 100644
--- a/aclocal.in
+++ b/aclocal.in
@@ -52,7 +52,7 @@ $perl_threads = 0;
# 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.
+# @user_includes can be augmented with -I or AC_CONFIG_MACRO_DIR.
# @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'
@@ -143,10 +143,14 @@ my $m4_include_rx = "(m4_|m4_s|s)include\\((?:\\[([^]]+)\\]|([^],)\n]+))\\)";
my $serial_line_rx = '^#\s*serial\s+(\S*)';
my $serial_number_rx = '^\d+(?:\.\d+)*$';
-# Autoconf version
-# Set by trace_used_macros.
+# 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;
+
# If set, names a temporary file that must be erased on abnormal exit.
my $erase_me;
@@ -719,13 +723,15 @@ sub trace_used_macros ()
$traces .= join (' ',
(map { "'$_'" }
(grep { exists $files{$_} } @file_order))) . " ";
+
# All candidate macros.
$traces .= join (' ',
(map { "--trace='$_:\$f::\$n::\$1'" }
('AC_DEFUN',
'AC_DEFUN_ONCE',
'AU_DEFUN',
- '_AM_AUTOCONF_VERSION')),
+ '_AM_AUTOCONF_VERSION',
+ 'AC_CONFIG_MACRO_DIR')),
# Do not trace $1 for all other macros as we do
# not need it and it might contains harmful
# characters (like newlines).
@@ -735,6 +741,8 @@ sub trace_used_macros ()
my $tracefh = new Automake::XFile ("$traces $configure_ac |");
+ $ac_config_macro_dir = undef;
+
my %traced = ();
while ($_ = $tracefh->getline)
@@ -744,12 +752,19 @@ sub trace_used_macros ()
$traced{$macro} = 1 if exists $macro_seen{$macro};
- $map_traced_defs{$arg1} = $file
- if ($macro eq 'AC_DEFUN'
- || $macro eq 'AC_DEFUN_ONCE'
- || $macro eq 'AU_DEFUN');
-
- $ac_version = $arg1 if $macro eq '_AM_AUTOCONF_VERSION';
+ if ($macro eq 'AC_DEFUN' || $macro eq 'AC_DEFUN_ONCE'
+ || $macro eq 'AU_DEFUN')
+ {
+ $map_traced_defs{$arg1} = $file;
+ }
+ elsif ($macro eq '_AM_AUTOCONF_VERSION')
+ {
+ $ac_version = $arg1;
+ }
+ elsif ($macro eq 'AC_CONFIG_MACRO_DIR')
+ {
+ $ac_config_macro_dir = $arg1;
+ }
}
$tracefh->close;
@@ -1018,12 +1033,6 @@ sub parse_arguments ()
$dry_run = 1;
}
- if ($install && !@user_includes)
- {
- fatal ("--install should copy macros in the directory indicated by the"
- . "\nfirst -I option, but no -I was supplied");
- }
-
# Finally, adds any directory listed in the 'dirlist' file.
if (open (DIRLIST, "$system_includes[0]/dirlist"))
{
@@ -1073,16 +1082,36 @@ $configure_ac = require_configure_ac;
# we did not rerun aclocal, the next run of aclocal would produce a
# different aclocal.m4.
my $loop = 0;
+my $rerun_due_to_macrodir = 0;
while (1)
{
++$loop;
- prog_error "too many loops" if $loop > 2;
+ prog_error "too many loops" if $loop > 2 + $rerun_due_to_macrodir;
reset_maps;
scan_m4_files;
scan_configure;
last if $exit_code;
my %macro_traced = trace_used_macros;
+
+ if (!$rerun_due_to_macrodir && defined $ac_config_macro_dir)
+ {
+ # 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;
+ # 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";
+ }
+
last if write_aclocal ($output_file, keys %macro_traced);
last if $dry_run;
}
diff --git a/doc/automake.texi b/doc/automake.texi
index 38f91593f..9ef7e9fed 100644
--- a/doc/automake.texi
+++ b/doc/automake.texi
@@ -3605,32 +3605,19 @@ henceforth be visible to @command{autoconf}. However if it contains
numerous macros, it will rapidly become difficult to maintain, and it
will be almost impossible to share macros between packages.
-@vindex ACLOCAL_AMFLAGS
The second possibility, which we do recommend, is to write each macro
-in its own file and gather all of these files in a directory. This
-directory is usually called @file{m4/}. To build @file{aclocal.m4},
-one should therefore instruct @command{aclocal} to scan @file{m4/}.
-From the command line, this is done with @samp{aclocal -I m4}. The
-top-level @file{Makefile.am} should also be updated to define
-
-@example
-ACLOCAL_AMFLAGS = -I m4
-@end example
-
-@code{ACLOCAL_AMFLAGS} contains options to pass to @command{aclocal}
-when @file{aclocal.m4} is to be rebuilt by @command{make}. This line is
-also used by @command{autoreconf} (@pxref{autoreconf Invocation, ,
-Using @command{autoreconf} to Update @file{configure} Scripts,
-autoconf, The Autoconf Manual}) to run @command{aclocal} with suitable
-options, or by @command{autopoint} (@pxref{autopoint Invocation, ,
-Invoking the @command{autopoint} Program, gettext, GNU gettext tools})
-and @command{gettextize} (@pxref{gettextize Invocation, , Invoking the
-@command{gettextize} Program, gettext, GNU gettext tools}) to locate
-the place where Gettext's macros should be installed. So even if you
-do not really care about the rebuild rules, you should define
-@code{ACLOCAL_AMFLAGS}.
-
-When @samp{aclocal -I m4} is run, it will build an @file{aclocal.m4}
+in its own file and gather all these files in a directory. This
+directory is usually called @file{m4/}. Then it's enough to update
+@file{configure.ac} by adding a proper call to @code{AC_CONFIG_MACRO_DIR}:
+
+@example
+AC_CONFIG_MACRO_DIR([m4])
+@end example
+
+@command{aclocal} will then take care of automatically adding @file{m4/}
+to its search path for m4 files.
+
+When @samp{aclocal} is run, it will build an @file{aclocal.m4}
that @code{m4_include}s any file from @file{m4/} that defines a
required macro. Macros not found locally will still be searched in
system-wide directories, as explained in @ref{Macro Search Path}.
@@ -3659,19 +3646,14 @@ this requirement will hinder development. An easy solution is to copy
such third-party macros in your local @file{m4/} directory so they get
distributed.
-Since Automake 1.10, @command{aclocal} offers an option to copy these
-system-wide third-party macros in your local macro directory, solving
-the above problem. Simply use:
-
-@example
-ACLOCAL_AMFLAGS = -I m4 --install
-@end example
+Since Automake 1.10, @command{aclocal} offers the option @code{--install}
+to copy these system-wide third-party macros in your local macro directory,
+helping to solve the above problem.
-@noindent
With this setup, system-wide macros will be copied to @file{m4/}
-the first time you run @command{autoreconf}. Then the locally
-installed macros will have precedence over the system-wide installed
-macros each time @command{aclocal} is run again.
+the first time you run @command{aclocal}. Then the locally installed
+macros will have precedence over the system-wide installed macros
+each time @command{aclocal} is run again.
One reason why you should keep @option{--install} in the flags even
after the first run is that when you later edit @file{configure.ac}
@@ -3752,16 +3734,14 @@ MyPackage uses an @file{m4/} directory to store local macros as
explained in @ref{Local Macros}, and has
@example
-ACLOCAL_AMFLAGS = -I m4 --install
+AC_CONFIG_MACRO_DIR([m4])
@end example
@noindent
-in its top-level @file{Makefile.am}.
+in its @file{configure.ac}.
Initially the @file{m4/} directory is empty. The first time we run
-@command{autoreconf}, it will fetch the options to pass to
-@command{aclocal} in @file{Makefile.am}, and run @samp{aclocal -I m4
---install}. @command{aclocal} will notice that
+@command{aclocal --install}, it will notice that
@itemize @bullet
@item
@@ -3779,9 +3759,8 @@ and @command{aclocal} was given the @option{--install} option, it will
copy this file in @file{m4/thirdparty.m4}, and output an
@file{aclocal.m4} that contains @samp{m4_include([m4/thirdparty.m4])}.
-The next time @samp{aclocal -I m4 --install} is run (either via
-@command{autoreconf}, by hand, or from the @file{Makefile} rebuild
-rules) something different happens. @command{aclocal} notices that
+The next time @samp{aclocal --install} is run, something different
+happens. @command{aclocal} notices that
@itemize @bullet
@item
@@ -3807,8 +3786,8 @@ the system-wide file in case of equal serial numbers.
Now suppose the system-wide third-party macro is changed. This can
happen if the package installing this macro is updated. Let's suppose
-the new macro has serial number 2. The next time @samp{aclocal -I m4
---install} is run the situation is the following:
+the new macro has serial number 2. The next time @samp{aclocal --install}
+is run the situation is the following:
@itemize @bullet
@item
@@ -3834,16 +3813,16 @@ macro in @file{m4/thirdparty.m4}, in this case overriding the old
version. MyPackage just had its macro updated as a side effect of
running @command{aclocal}.
-If you are leery of letting @command{aclocal} update your local macro,
-you can run @samp{aclocal -I m4 --diff} to review the changes
-@samp{aclocal -I m4 --install} would perform on these macros.
+If you are leery of letting @command{aclocal} update your local
+macro, you can run @samp{aclocal --diff} to review the changes
+@samp{aclocal --install} would perform on these macros.
Finally, note that the @option{--force} option of @command{aclocal} has
absolutely no effect on the files installed by @option{--install}. For
instance, if you have modified your local macros, do not expect
@option{--install --force} to replace the local macros by their
system-wide versions. If you want to do so, simply erase the local
-macros you want to revert, and run @samp{aclocal -I m4 --install}.
+macros you want to revert, and run @samp{aclocal --install}.
@node Future of aclocal
@@ -9853,15 +9832,6 @@ Automake generates rules to automatically rebuild @file{Makefile}s,
If you are using @code{AM_MAINTAINER_MODE} in @file{configure.ac}, then
these automatic rebuilding rules are only enabled in maintainer mode.
-@vindex ACLOCAL_AMFLAGS
-Sometimes you need to run @command{aclocal} with an argument like
-@option{-I} to tell it where to find @file{.m4} files. Since
-sometimes @command{make} will automatically run @command{aclocal}, you
-need a way to specify these arguments. You can do this by defining
-@code{ACLOCAL_AMFLAGS}; this holds arguments that are passed verbatim
-to @command{aclocal}. This variable is only useful in the top-level
-@file{Makefile.am}.
-
@vindex CONFIG_STATUS_DEPENDENCIES
@vindex CONFIGURE_DEPENDENCIES
@cindex @file{version.sh}, example
@@ -12313,11 +12283,6 @@ obeys this naming scheme. The slight difference is that
@code{MAKEFLAGS} is passed to sub-@command{make}s implicitly by
@command{make} itself.
-However you should not think that all variables ending with @code{FLAGS}
-follow this convention. For instance, @code{ACLOCAL_AMFLAGS} (see
-@ref{Rebuilding} and @ref{Local Macros}) is a variable that is only
-useful to the maintainer and has no user counterpart.
-
@code{ARFLAGS} (@pxref{A Library}) is usually defined by Automake and
has neither @code{AM_} nor per-target cousin.
diff --git a/lib/am/configure.am b/lib/am/configure.am
index 20534c7be..95332fae9 100644
--- a/lib/am/configure.am
+++ b/lib/am/configure.am
@@ -113,13 +113,13 @@ $(top_srcdir)/configure: %MAINTAINER-MODE% $(am__configure_deps)
## aclocal.m4. ##
## ------------ ##
-## aclocal.m4 must be built by the top-level Makefile, because this is
-## where the user is expected to define $(ACLOCAL_AMFLAGS).
-##
## Whenever a configure dependency changes we need to rebuild
## aclocal.m4 too. Changing configure.ac, or any file included by
## aclocal.m4 might require adding more files to aclocal.m4. Hence
## the $(am__configure_deps) dependency.
+## We still need $(ACLOCAL_AMFLAGS) for sake of backward-compatibility;
+## we should hopefully be able to get rid of it in a not-so-distant
+## future.
if %?REGEN-ACLOCAL-M4%
$(ACLOCAL_M4): %MAINTAINER-MODE% $(am__aclocal_m4_deps)
?TOPDIR_P? $(am__cd) $(srcdir) && $(ACLOCAL) $(ACLOCAL_AMFLAGS)
diff --git a/t/acloca14.sh b/t/acloca14.sh
index eb9105dde..cc6521441 100755
--- a/t/acloca14.sh
+++ b/t/acloca14.sh
@@ -20,6 +20,7 @@
. ./defs || exit 1
cat >> configure.ac << 'END'
+AC_CONFIG_MACRO_DIR([defs])
AM_PROG_LIBTOOL
AC_OUTPUT
END
@@ -45,7 +46,6 @@ echo 'AC_DEFUN([SOMETHING_ELSE])' >defs/e.m4
echo 'AC_DEFUN([ANOTHER_MACRO])' >defs/f.m4
cat >>Makefile.am<<\EOF
-ACLOCAL_AMFLAGS = -I defs
testdist1: distdir
test -f $(distdir)/acinclude.m4
test -f $(distdir)/a.m4
diff --git a/t/acloca14b.sh b/t/acloca14b.sh
new file mode 100755
index 000000000..eb9105dde
--- /dev/null
+++ b/t/acloca14b.sh
@@ -0,0 +1,108 @@
+#! /bin/sh
+# Copyright (C) 2004-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/>.
+
+# Make sure m4_included files are also scanned for definitions.
+# Report from Phil Edwards.
+
+. ./defs || exit 1
+
+cat >> configure.ac << 'END'
+AM_PROG_LIBTOOL
+AC_OUTPUT
+END
+
+echo 'm4_include([a.m4])' > acinclude.m4
+echo 'm4_include([b.m4])' > a.m4
+
+cat >b.m4 <<EOF
+m4_include([c.m4])
+AC_DEFUN([AM_PROG_LIBTOOL],
+[AC_REQUIRE([SOMETHING])dnl
+AC_REQUIRE([SOMETHING_ELSE])dnl
+])
+
+AC_DEFUN([SOMETHING])
+EOF
+
+echo 'm4_include([d.m4])' > c.m4
+echo 'AC_DEFUN([SOMETHING_ELSE])' >d.m4
+
+mkdir defs
+echo 'AC_DEFUN([SOMETHING_ELSE])' >defs/e.m4
+echo 'AC_DEFUN([ANOTHER_MACRO])' >defs/f.m4
+
+cat >>Makefile.am<<\EOF
+ACLOCAL_AMFLAGS = -I defs
+testdist1: distdir
+ test -f $(distdir)/acinclude.m4
+ test -f $(distdir)/a.m4
+ test -f $(distdir)/b.m4
+ test -f $(distdir)/c.m4
+ test -f $(distdir)/d.m4
+ test ! -d $(distdir)/defs
+testdist2: distdir
+ test -f $(distdir)/acinclude.m4
+ test -f $(distdir)/a.m4
+ test -f $(distdir)/b.m4
+ test -f $(distdir)/c.m4
+ test -f $(distdir)/d.m4
+ test ! -f $(distdir)/defs/e.m4
+ test -f $(distdir)/defs/f.m4
+EOF
+
+$ACLOCAL -I defs
+
+$FGREP acinclude.m4 aclocal.m4
+# None of the following macro should be included. acinclude.m4
+# includes the first four, and the last two are not needed at all.
+$FGREP a.m4 aclocal.m4 && exit 1
+$FGREP b.m4 aclocal.m4 && exit 1
+$FGREP c.m4 aclocal.m4 && exit 1
+$FGREP d.m4 aclocal.m4 && exit 1
+$FGREP defs/e.m4 aclocal.m4 && exit 1
+$FGREP defs/f.m4 aclocal.m4 && exit 1
+
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+$MAKE testdist1
+
+cp aclocal.m4 aclocal.old
+$sleep
+echo 'AC_DEFUN([FOO], [ANOTHER_MACRO])' >> c.m4
+$MAKE
+# Because c.m4 has changed, aclocal.m4 must have been rebuilt.
+is_newest aclocal.m4 aclocal.old
+# However, since FOO is not used, f.m4 should not be included
+# and the contents of aclocal.m4 should remain the same
+diff aclocal.m4 aclocal.old
+
+# If FOO where to be used, that would be another story, of course:
+# f.m4 should be included
+$sleep
+echo FOO >> configure.ac
+$MAKE
+$FGREP defs/f.m4 aclocal.m4
+$MAKE testdist2
+
+# Make sure aclocal diagnose missing included files with correct 'file:line:'.
+rm -f b.m4
+$ACLOCAL 2>stderr && { cat stderr >&2; exit 1; }
+cat stderr >&2
+grep 'a\.m4:1: .*b\.m4.*does not exist' stderr
+
+:
diff --git a/t/acloca22.sh b/t/acloca22.sh
index c8f83075a..c23a7cb21 100755
--- a/t/acloca22.sh
+++ b/t/acloca22.sh
@@ -21,24 +21,27 @@
. ./defs || exit 1
cat >>configure.ac <<EOF
+AC_CONFIG_MACRO_DIR([.])
FOO
AC_OUTPUT
EOF
+
cat >foo.m4 <<EOF
AC_DEFUN([FOO], [AC_SUBST([GREPFOO])])
EOF
+
cat >bar.m4 <<EOF
AC_DEFUN([BAR], [AC_SUBST([GREPBAR])])
EOF
-cat >Makefile.am <<EOF
-ACLOCAL_AMFLAGS = -I .
-EOF
-$ACLOCAL -I .
+: >Makefile.am
+
+$ACLOCAL
$AUTOMAKE
$AUTOCONF
./configure
+
$MAKE
grep GREPFOO Makefile
grep GREPBAR Makefile && exit 1
@@ -46,6 +49,7 @@ grep GREPBAR Makefile && exit 1
sed 's/FOO/BAR/' < configure.ac > t
mv -f t configure.ac
rm -f foo.m4
+
$MAKE
grep GREPFOO Makefile && exit 1
grep GREPBAR Makefile
diff --git a/t/acloca22b.sh b/t/acloca22b.sh
new file mode 100755
index 000000000..0317b120c
--- /dev/null
+++ b/t/acloca22b.sh
@@ -0,0 +1,59 @@
+#! /bin/sh
+# Copyright (C) 2007-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/>.
+
+# Make sure the "deleted header file" issue is fixed wrt. aclocal.m4
+# dependencies.
+# NOTE: this test works by using the obsolete 'ACLOCAL_AMFLAGS' make
+# variable; see sister test 'acloca22.test' for a modern equivalent.
+
+. ./defs || exit 1
+
+cat >>configure.ac <<EOF
+FOO
+AC_OUTPUT
+EOF
+
+cat >foo.m4 <<EOF
+AC_DEFUN([FOO], [AC_SUBST([GREPFOO])])
+EOF
+
+cat >bar.m4 <<EOF
+AC_DEFUN([BAR], [AC_SUBST([GREPBAR])])
+EOF
+
+cat >Makefile.am <<EOF
+ACLOCAL_AMFLAGS = -I .
+EOF
+
+$ACLOCAL -I .
+$AUTOMAKE
+$AUTOCONF
+
+./configure
+
+$MAKE
+grep GREPFOO Makefile
+grep GREPBAR Makefile && exit 1
+
+sed 's/FOO/BAR/' < configure.ac > t
+mv -f t configure.ac
+rm -f foo.m4
+
+$MAKE
+grep GREPFOO Makefile && exit 1
+grep GREPBAR Makefile
+
+:
diff --git a/t/aclocal-amflags.sh b/t/aclocal-amflags.sh
new file mode 100755
index 000000000..47bf1351a
--- /dev/null
+++ b/t/aclocal-amflags.sh
@@ -0,0 +1,69 @@
+#! /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/>.
+
+# Check that the obsolescent idiom of setting $(ACLOCAL_AMFLAGS) in
+# Makefile.am still works. Remove this test once support for this
+# obsolescent idiom is removed.
+
+. ./defs || exit 1
+
+cat >> configure.ac <<'END'
+MACRO_FOO || AS_EXIT([1])
+AC_OUTPUT
+END
+
+mkdir m4_1 m4_2
+cat > m4_1/foo.m4 <<'END'
+AC_DEFUN([MACRO_FOO], [: > foo])
+END
+cat > m4_2/bar.m4 <<'END'
+AC_DEFUN([MACRO_BAR], [: > bar])
+END
+
+cat > Makefile.am <<'END'
+ACLOCAL_AMFLAGS = -I m4_2 --verbose
+check-local:
+ test ! -r foo
+ test -f bar
+DISTCLEANFILES = bar
+END
+
+$ACLOCAL -I m4_1 >output 2>&1 || { cat output; exit 1; }
+cat output
+grep 'found macro' output && exit 1 # Sanity check.
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+test -f foo
+rm -f foo
+
+# ACLOCAL_AMFLAGS is used in rebuild rules, so trigger them.
+$sleep
+
+sed 's/MACRO_FOO/MACRO_BAR/' configure.ac > t
+mv -f t configure.ac
+
+$MAKE Makefile >output 2>&1 || { cat output; exit 1; }
+cat output
+grep "^aclocal.*:.*found macro.*MACRO_BAR.*m4_2/bar\.m4" output
+grep "macro.*MACRO_FOO" output && exit 1
+test ! -r foo
+test -f bar
+
+$MAKE distcheck
+
+:
diff --git a/t/aclocal-macrodir.tap b/t/aclocal-macrodir.tap
new file mode 100644
index 000000000..c35d9e002
--- /dev/null
+++ b/t/aclocal-macrodir.tap
@@ -0,0 +1,161 @@
+#! /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_DIR with
+# aclocal.
+
+am_create_testdir=empty
+. ./defs || exit 1
+
+plan_ later
+
+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
+ 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_todo () { directive=TODO; }
+
+#---------------------------------------------------------------------------
+
+test_begin "AC_CONFIG_MACRO_DIR is honored"
+
+cat > configure.ac <<'END'
+AC_INIT([md], [10.0])
+AC_CONFIG_MACRO_DIR([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
+
+#---------------------------------------------------------------------------
+
+test_begin "AC_CONFIG_MACRO_DIR([foo]) interaction with --install"
+
+cat > configure.ac << 'END'
+AC_INIT([inst], [1.0])
+AC_CONFIG_MACRO_DIR([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
+
+#---------------------------------------------------------------------------
+
+test_begin "'-I' option wins over AC_CONFIG_MACRO_DIR"
+
+cat > configure.ac <<'END'
+AC_INIT([md], [4.6])
+AC_CONFIG_MACRO_DIR([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_DIR([foo]) can create directory 'foo'"
+
+cat > configure.ac << 'END'
+AC_INIT([x], [1.0])
+AC_CONFIG_MACRO_DIR([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
+
+#---------------------------------------------------------------------------
+
+:
diff --git a/t/aclocal-path-install.sh b/t/aclocal-path-install.sh
index 4ed1a2c27..ccad30b20 100755
--- a/t/aclocal-path-install.sh
+++ b/t/aclocal-path-install.sh
@@ -41,7 +41,7 @@ END
# in a directory specified in ACLOCAL_PATH.
$ACLOCAL --install 2>stderr && { cat stderr >&2; exit 1; }
cat stderr >&2
-grep ' no -I was supplied' stderr
+grep 'impossible without -I .* nor AC_CONFIG_MACRO_DIR' stderr
test ! -e pdir/foo.m4
# The '--install' option should cause a required macro found in a
diff --git a/t/aclocal4.sh b/t/aclocal4.sh
index feae3ec17..e542c5326 100755
--- a/t/aclocal4.sh
+++ b/t/aclocal4.sh
@@ -21,6 +21,7 @@ required=cc
. ./defs || exit 1
cat >>configure.ac <<EOF
+AC_CONFIG_MACRO_DIR([m4])
AC_PROG_RANLIB
AM_PROG_AR
AC_PROG_CC
@@ -46,7 +47,6 @@ EOF
cat >Makefile.am <<'EOF'
SUBDIRS = lib
EXTRA_DIST = m4/mymacro.m4
-ACLOCAL_AMFLAGS = -I m4
check-foo: distdir
test -f $(distdir)/lib/foo.c
test -f $(distdir)/lib/bar.c
@@ -56,7 +56,7 @@ check-not-foo: distdir
test -f $(distdir)/lib/bar.c
EOF
-$ACLOCAL -I m4
+$ACLOCAL
$AUTOCONF
$AUTOMAKE --add-missing
./configure
diff --git a/t/aclocal5.sh b/t/aclocal5.sh
index 4d3730a31..cf0006d0a 100755
--- a/t/aclocal5.sh
+++ b/t/aclocal5.sh
@@ -20,23 +20,23 @@
. ./defs || exit 1
cat >> configure.ac << 'END'
-AM_TEST([GREPME])
+AC_CONFIG_MACRO_DIR([m4])
+FOO_TEST([GREPME])
AC_CONFIG_FILES([sub/Makefile])
AC_OUTPUT
END
cat > Makefile.am << 'END'
SUBDIRS = sub
-ACLOCAL_AMFLAGS = -I m4
END
mkdir sub
: > sub/Makefile.am
mkdir m4
-echo 'AC_DEFUN([AM_TEST], [echo $@])' > m4/moredefs.m4
+echo 'AC_DEFUN([FOO_TEST], [echo $@])' > m4/moredefs.m4
-$ACLOCAL -I m4
+$ACLOCAL
$AUTOCONF
$AUTOMAKE --copy --add-missing
./configure
@@ -44,10 +44,10 @@ $MAKE
# Update an aclocal.m4 dependency, then make sure all Makefiles are
# updated, even from a sub-directory. Check that AU_ALIAS is
-# recognized. Change the definition of AM_TEST to check that its new
+# recognized. Change the definition of FOO_TEST to check that its new
# definition is used.
$sleep # Modified configure dependencies must be newer than config.status.
-echo 'AU_ALIAS([AM_TEST], [AC_SUBST])' > m4/moredefs.m4
+echo 'AU_ALIAS([FOO_TEST], [AC_SUBST])' > m4/moredefs.m4
cd sub
$MAKE
cd ..
@@ -58,10 +58,10 @@ grep GREPME sub/Makefile
$MAKE distdir
test -f $me-1.0/m4/moredefs.m4
-# Change the definition of AM_TEST to check that its new definition is
+# Change the definition of FOO_TEST to check that its new definition is
# used. Check that AC_DEFUN_ONCE is caught.
$sleep # Modified configure dependencies must be newer than config.status.
-echo 'AC_DEFUN_ONCE([AM_TEST], [AC_SUBST(__$1__)])' > m4/moredefs.m4
+echo 'AC_DEFUN_ONCE([FOO_TEST], [AC_SUBST(__$1__)])' > m4/moredefs.m4
$MAKE
grep 'm4/moredefs\.m4' aclocal.m4
grep '__GREPME__' configure
diff --git a/t/aclocal6.sh b/t/aclocal6.sh
index dc6b38db3..80c918a85 100755
--- a/t/aclocal6.sh
+++ b/t/aclocal6.sh
@@ -22,12 +22,12 @@
cat >> configure.ac << 'END'
SOME_DEFS
AC_CONFIG_FILES([sub/Makefile])
+AC_CONFIG_MACRO_DIR([m4])
AC_OUTPUT
END
cat > Makefile.am << 'END'
SUBDIRS = sub
-ACLOCAL_AMFLAGS = -I m4
END
mkdir sub
@@ -37,7 +37,7 @@ mkdir m4
echo 'AC_DEFUN([SOME_DEFS], [])' > m4/somedefs.m4
echo 'AC_DEFUN([MORE_DEFS], [AC_SUBST([GREPME])])' > m4/moredefs.m4
-$ACLOCAL -I m4
+$ACLOCAL
$AUTOCONF
$AUTOMAKE --copy --add-missing
diff --git a/t/list-of-tests.mk b/t/list-of-tests.mk
index 08919da8f..fdb48788a 100644
--- a/t/list-of-tests.mk
+++ b/t/list-of-tests.mk
@@ -88,6 +88,7 @@ t/acloca11.sh \
t/acloca12.sh \
t/acloca13.sh \
t/acloca14.sh \
+t/acloca14b.sh \
t/acloca15.sh \
t/acloca16.sh \
t/acloca17.sh \
@@ -96,9 +97,12 @@ t/acloca19.sh \
t/acloca20.sh \
t/acloca21.sh \
t/acloca22.sh \
+t/acloca22b.sh \
t/acloca23.sh \
t/aclocal-acdir.sh \
t/aclocal-install-absdir.sh \
+t/aclocal-macrodir.tap \
+t/aclocal-amflags.sh \
t/aclocal-print-acdir.sh \
t/aclocal-path.sh \
t/aclocal-path-install.sh \
@@ -937,6 +941,7 @@ t/remake-deleted-am-subdir.sh \
t/remake-deleted-am.sh \
t/remake-renamed-am.sh \
t/remake-aclocal-version-mismatch.sh \
+t/remake-macrodir.sh \
t/pr8365-remake-timing.sh \
t/req.sh \
t/reqd.sh \
diff --git a/t/remake-macrodir.sh b/t/remake-macrodir.sh
new file mode 100755
index 000000000..61ac1979c
--- /dev/null
+++ b/t/remake-macrodir.sh
@@ -0,0 +1,83 @@
+#! /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/>.
+
+# Check that the aclocal honouring of AC_CONFIG_MACRO_DIR interacts
+# nicely with automatic rebuild rules.
+
+. ./defs || exit 1
+
+cat >> configure.ac <<'END'
+AC_CONFIG_MACRO_DIR([macro-dir])
+my__FOO || AS_EXIT([1])
+AC_OUTPUT
+END
+
+: > Makefile.am
+
+mkdir macro-dir
+cat > macro-dir/foo.m4 <<'END'
+AC_DEFUN([my__FOO], [: > bar])
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+$FGREP my__FOO configure && exit 1
+
+./configure
+test -f bar
+rm -f bar
+
+$sleep
+
+cat > macro-dir/foo.m4 <<'END'
+AC_DEFUN([my__FOO], [: > baz])
+END
+
+$MAKE Makefile
+test -f baz
+test ! -r bar
+rm -f baz
+
+$sleep
+
+rm -f macro-dir/foo.m4
+cat > macro-dir/quux.m4 <<'END'
+AC_DEFUN([my__FOO], [: > quux])
+END
+
+$MAKE Makefile
+test -f quux
+test ! -r baz
+rm -f quux
+
+$sleep
+
+sed 's/^AC_CONFIG_MACRO_DIR/&([newdir])/' configure.ac > t
+mv -f t configure.ac
+
+mkdir newdir
+cat > newdir/mu.m4 <<'END'
+AC_DEFUN([my__FOO], [[: my__FOO do nothing]])
+END
+
+$MAKE Makefile
+$FGREP ': my__FOO do nothing' configure
+
+$MAKE distcheck
+
+:
diff --git a/t/remake10c.sh b/t/remake10c.sh
index e88c31c27..97c8745c0 100755
--- a/t/remake10c.sh
+++ b/t/remake10c.sh
@@ -31,13 +31,13 @@ else
fi
cat >> configure.ac <<END
+AC_CONFIG_MACRO_DIR([m4])
FINGERPRINT='my_fingerprint'
AC_SUBST([FINGERPRINT])
AC_OUTPUT
END
cat > Makefile.am <<'END'
-ACLOCAL_AMFLAGS = -I m4
.PHONY: nil
nil:
## Used by "make distcheck" later.
@@ -50,7 +50,7 @@ END
mkdir m4
echo 'AC_DEFUN([my_fingerprint], [BadBadBad])' > m4/foo.m4
-$ACLOCAL -I m4
+$ACLOCAL
$AUTOCONF
$AUTOMAKE
diff --git a/t/remake8a.sh b/t/remake8a.sh
index 9a9765c2c..b720bd26c 100755
--- a/t/remake8a.sh
+++ b/t/remake8a.sh
@@ -110,29 +110,29 @@ $MAKE distcheck
rm -f quux
-# Modify Makefile.am to add a directory of extra m4 files
-# considered by aclocal.
+# Modify configure.ac and aclocal.m4 to add a directory of extra m4
+# files considered by aclocal. Also update checks in Makefile.am.
+# Note that we won't use this new directory of extra m4 files in the
+# first rebuild below (but we will in the second).
$sleep
mkdir $srcdir/m4
cat > $srcdir/Makefile.am <<'END'
-ACLOCAL_AMFLAGS = -I m4
+all-local: quux
check-local:
cat quux
grep '%Foo%' quux
test x'$(QUUX)' = x'%Foo%'
END
-$MAKE # This should place aclocal flags in Makefile.
-grep '.*-I m4' Makefile # Sanity check.
-
# Modify configure.ac and aclocal.m4.
$sleep
cat $srcdir/configure.stub - > $srcdir/configure.ac <<'END'
+AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_FILES([quux])
MY_CUSTOM_MACRO
AC_OUTPUT
diff --git a/t/remake8b.sh b/t/remake8b.sh
index 850347aa2..19fb9857a 100755
--- a/t/remake8b.sh
+++ b/t/remake8b.sh
@@ -112,29 +112,29 @@ $MAKE distcheck
rm -f quux
-# Modify Makefile.am to add a directory of extra m4 files
-# considered by aclocal.
+# Modify configure.ac and aclocal.m4 to add a directory of extra m4
+# files considered by aclocal. Also update checks in Makefile.am.
+# Note that we won't use this new directory of extra m4 files in the
+# first rebuild below (but we will in the second).
$sleep
mkdir $srcdir/m4
cat > $srcdir/Makefile.am <<'END'
-ACLOCAL_AMFLAGS = -I m4
+all-local: quux
check-local:
cat quux
grep '%Foo%' quux
test x'$(QUUX)' = x'%Foo%'
END
-$MAKE # This should place aclocal flags in Makefile.
-grep '.*-I m4' Makefile # Sanity check.
-
# Modify configure.ac and aclocal.m4.
$sleep
cat $srcdir/configure.stub - > $srcdir/configure.ac <<'END'
+AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_FILES([quux])
MY_CUSTOM_MACRO
AC_OUTPUT
diff --git a/t/subdir-add2-pr46.sh b/t/subdir-add2-pr46.sh
index a4dca9030..b226a09f2 100755
--- a/t/subdir-add2-pr46.sh
+++ b/t/subdir-add2-pr46.sh
@@ -22,6 +22,7 @@
. ./defs || exit 1
cat >> configure.ac << 'END'
+AC_CONFIG_MACRO_DIR([m4])
m4_include([confiles.m4])
MORE_DEFS
AC_OUTPUT
@@ -31,7 +32,6 @@ echo 'AC_CONFIG_FILES([sub/Makefile])' > confiles.m4
cat > Makefile.am << 'END'
SUBDIRS = sub
-ACLOCAL_AMFLAGS = -I m4
END
mkdir sub
@@ -41,7 +41,7 @@ mkdir sub
mkdir m4
echo 'AC_DEFUN([MORE_DEFS], [])' > m4/moredefs.m4
-$ACLOCAL -I m4
+$ACLOCAL
$AUTOCONF
$AUTOMAKE
./configure
diff --git a/t/subpkg.sh b/t/subpkg.sh
index c8ce125b6..d1c5ed3b6 100755
--- a/t/subpkg.sh
+++ b/t/subpkg.sh
@@ -29,6 +29,7 @@ AC_DEFUN([FOO],[
EOF
cat >>configure.ac <<'END'
+AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_SUBDIRS([lib])
FOO
END
@@ -46,8 +47,6 @@ distdir = subpack-1
dist-hook:
test -f $(distdir)/LDADD.c
test -f $(top_distdir)/LDADD.c
-
-ACLOCAL_AMFLAGS = -I m4
EOF
cat >LDADD.c <<'EOF'
@@ -64,6 +63,7 @@ mkdir lib/src
cat >lib/configure.ac <<'EOF'
AC_INIT([lib], [2.3])
AM_INIT_AUTOMAKE
+AC_CONFIG_MACRO_DIR([../m4])
AM_PROG_AR
AC_PROG_RANLIB
AC_CONFIG_HEADERS([config.h:config.hin])
@@ -80,8 +80,6 @@ dist-hook:
test -f $(top_distdir)/LDADD.c
test -f $(distdir)/src/x.c
test ! -f $(top_distdir)/src/x.c
-
-ACLOCAL_AMFLAGS = -I ../m4
EOF
cat >lib/src/x.c <<'EOF'
@@ -92,12 +90,12 @@ int lib (void)
}
EOF
-$ACLOCAL -I m4
+$ACLOCAL
$AUTOCONF
$AUTOMAKE -Wno-override
cd lib
-$ACLOCAL -I ../m4
+$ACLOCAL
$FGREP 'm4_include([../m4/foo.m4])' aclocal.m4
$AUTOCONF
$AUTOHEADER
diff --git a/t/subpkg2.sh b/t/subpkg2.sh
index 8afcc5af9..ea95d5f01 100755
--- a/t/subpkg2.sh
+++ b/t/subpkg2.sh
@@ -28,6 +28,7 @@ AC_DEFUN([FOO],[
EOF
cat >>configure.ac <<'END'
+AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_SUBDIRS([sub])
AC_OUTPUT
END
@@ -43,20 +44,21 @@ mkdir sub
cat >sub/configure.ac <<'EOF'
AC_INIT([sub], [2.3])
AM_INIT_AUTOMAKE
+AC_CONFIG_MACRO_DIR([../m4])
AC_CONFIG_FILES([Makefile])
AC_CONFIG_FILES([script])
FOO
EOF
: >sub/script.in
-echo ACLOCAL_AMFLAGS = -I ../m4 > sub/Makefile.am
+: >sub/Makefile.am
-$ACLOCAL -I m4
+$ACLOCAL
$AUTOCONF
$AUTOMAKE
cd sub
-$ACLOCAL -I ../m4
+$ACLOCAL
$FGREP 'm4_include([../m4/foo.m4])' aclocal.m4
$AUTOCONF
$AUTOMAKE -Wno-override
@@ -64,3 +66,5 @@ cd ..
./configure
$MAKE distcheck
+
+: