automake-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Trace macros for aclocal options, deprecate ACLOCAL_AMFLAGS.


From: Stefano Lattarini
Subject: Re: [PATCH] Trace macros for aclocal options, deprecate ACLOCAL_AMFLAGS.
Date: Tue, 28 Dec 2010 21:56:35 +0100
User-agent: KMail/1.13.3 (Linux/2.6.30-2-686; KDE/4.4.4; i686; ; )

Hello automakers.

This is a follow-up on thread "Trace macros for aclocal options,
deprecate ACLOCAL_AMFLAGS":
 <http://lists.gnu.org/archive/html/automake-patches/2010-10/msg00045.html>

I've reworked the patch quite heavily, simplifying the API a little (as
showed by the decresed duplication in the testcases), extending the tests,
and adding a NEWS entry and some (hopefully decent) documentation for the
new feature.

IMHO the patch should be "ready to apply", even if it's not perfect (for 
example, AM_EXTRA_ACLOCAL_FLAGS could be enhanced to save the list of
extra aclocal flags it has seen in a m4 list, which could be used by other
m4 macros or by generated shell code; but such improvements can come later
if they're needed).

Tested with GNU make and Solaris make, with autoconf 2.68 and 2.62, on
Debian GNU/Linux and on Solaris 10.

OK for master?

Regards,
   Stefano
From b1f01adc6e96533a98d396cb1acfd07721380b1a Mon Sep 17 00:00:00 2001
From: Stefano Lattarini <address@hidden>
Date: Tue, 5 Oct 2010 17:14:00 +0200
Subject: [PATCH] Trace macros for aclocal options, deprecate ACLOCAL_AMFLAGS.

Maintaining ACLOCAL_AMFLAGS in Makefile.am to pass extra flags
to aclocal is (and have always been) quite of an hack.
For example, autoreconf is forced to grep Makefile.am to honour
those flags; and this is a bad obsolescent behaviour: in fact,
the autotools have moved consistently in the past years from
custom grepping of Makefile.am and/or configure.ac to tracing
of m4 macro calls, which is more consistent, more reliable and
more flexible.
And when autoreconf is not used, the developer is forced to add
*by hand* the flags specified by ACLOCAL_AMFLAGS to the aclocal
calls not triggered by make rebuild rules; here lie again more
duplication and more chances for errors.
Thus we now make aclocal trace some more macros, that it can use
to automatically find out extra flags -- for example, a call to
AC_CONFIG_MACRO_DIR([dir]) will cause aclocal to add `-I dir' to
its flags.
We also define two new macros, `AM_EXTRA_ACLOCAL_FLAGS' and
`AM_RESET_ACLOCAL_FLAGS', whose only purpose is to allow setting
of arbitrary aclocal flags in configure.ac.

* NEWS: Updated.
* doc/automake.texi (aclocal Options From macros): New node.
(Local Macros): Update.
(Serials): Update.
(Rebuilding): Remove references to ACLOCAL_AMFLAGS.
(Flag Variables Ordering): Likewise.
* lib/am/configure.am: Updated comments.
* aclocal.in: Implement processing of extra flags derived from
macro calls.
(@aclocal_flags): New global variable.
(trace_used_macros): Also trace macros `AC_CONFIG_MACRO_DIR',
`AM_RESET_ACLOCAL_FLAGS' and `_AM_EXTRA_ACLOCAL_FLAGS', and
collect extra aclocal flags derived from calls to those macros.
(parse_arguments): Now accept an array of parameters, and process
it instead of @ARGV.  Code for setup and normalization of system
include dirs moved ...
(setup_system_includes): ... into this new subroutine.
* m4/aclocal-flags.m4: New file, containing definitions of ...
(AM_EXTRA_ACLOCAL_FLAGS, AM_RESET_ACLOCAL_FLAGS): ... these new
public macros, and ...
(_AM_EXTRA_ACLOCAL_FLAGS): ... this new private macro.
* m4/Makefile.am (dist_m4data_DATA): Updated.
* tests/subpkg.test: Updated: add `AC_CONFIG_MACRO_DIR' call to
configure.in, remove setting of `ACLOCAL_AMFLAGS' in Makefile.am
and use of aclocal command line arguments.
* tests/subpkg2.test: Likewise.
* tests/subdir8.test: Likewise.
* tests/remake10c.test: Likewise.
* tests/remake8a.test: Likewise.
* tests/remake8b.test: Likewise.
* tests/aclocal4.test: Likewise.
* tests/aclocal6.test: Likewise.
* tests/acloca14.test: Likewise.
* tests/acloca22.test: Likewise.
* tests/aclocal5.test: Likewise, and do not not invade the
Automake namespace (this avoids spurious failures).
* tests/acloca14b.test: New test, identical to the previous
version of `acloca14.test'; it is kept to verify backwards
compatibility.
* tests/acloca22b.test: Likewise (but for `acloca22.test').
* tests/aclocal-amflags.test: New test, check for backwards
compatibility that ACLOCAL_AMFLAGS still works.
* tests/aclocalflags-cmdline-precedence.test: New test.
* tests/aclocalflags-empty.test: Likewise.
* tests/aclocalflags-install.test: Likewise.
* tests/aclocalflags-invalid.test: Likewise.
* tests/aclocalflags-left-to-right.test: Likewise.
* tests/aclocalflags-macrodir-precedence.test: Likewise.
* tests/aclocalflags-macrodir.test: Likewise.
* tests/aclocalflags-moreopts.test: Likewise.
* tests/aclocalflags-options-with-args.test: Likewise.
* tests/aclocalflags-rebuild.test: Likewise.
* tests/aclocalflags-reset.test: Likewise.
* tests/aclocalflags-indirections.test: Likewise.
* tests/aclocalflags-whitespaces.test: Likewise.
* tests/aclocalflags-advanced.sh: New helper script, sourced
by the last two new tests above.
* tests/aclocalflags-acdir.test: New test, currently xfailing
due to a testsuite weakness.
* tests/Makefile.am (TESTS, XFAIL_TESTS, EXTRA_DIST): Updated.
Define correct dependencies for the logs of tests that source
the new `aclocalflags-advanced.sh' helper script.
* tests/.gitignore: Updated.

From a suggestion by Eric Blake.
---
 ChangeLog                                   |   87 +++++++++++
 NEWS                                        |    4 +
 aclocal.in                                  |   79 ++++++++--
 doc/automake.texi                           |  141 +++++++++++++-----
 lib/am/configure.am                         |   10 +-
 m4/Makefile.am                              |    1 +
 m4/Makefile.in                              |    1 +
 m4/aclocal-flags.m4                         |   31 ++++
 tests/.gitignore                            |    4 +-
 tests/Makefile.am                           |   26 ++++
 tests/Makefile.in                           |   29 ++++-
 tests/acloca14.test                         |    2 +-
 tests/acloca14b.test                        |  123 +++++++++++++++
 tests/acloca22.test                         |   19 ++-
 tests/acloca22b.test                        |   51 +++++++
 tests/aclocal-amflags.test                  |   71 +++++++++
 tests/aclocal4.test                         |   10 +-
 tests/aclocal5.test                         |   18 +-
 tests/aclocal6.test                         |    6 +-
 tests/aclocalflags-acdir.test               |   46 ++++++
 tests/aclocalflags-advanced.sh              |   66 ++++++++
 tests/aclocalflags-cmdline-precedence.test  |   33 ++++
 tests/aclocalflags-empty.test               |   29 ++++
 tests/aclocalflags-indirections.test        |   40 +++++
 tests/aclocalflags-install.test             |   63 ++++++++
 tests/aclocalflags-invalid.test             |   61 ++++++++
 tests/aclocalflags-left-to-right.test       |   46 ++++++
 tests/aclocalflags-macrodir-precedence.test |   53 +++++++
 tests/aclocalflags-macrodir.test            |   69 +++++++++
 tests/aclocalflags-moreopts.test            |  104 +++++++++++++
 tests/aclocalflags-options-with-args.test   |   48 ++++++
 tests/aclocalflags-rebuild.test             |  215 +++++++++++++++++++++++++++
 tests/aclocalflags-reset.test               |   63 ++++++++
 tests/aclocalflags-whitespaces.test         |   36 +++++
 tests/aclocalflags.test                     |   81 ++++++++++
 tests/remake10c.test                        |    4 +-
 tests/remake8a.test                         |   15 +--
 tests/remake8b.test                         |   15 +--
 tests/subdir8.test                          |    4 +-
 tests/subpkg.test                           |   15 +-
 tests/subpkg2.test                          |   10 +-
 41 files changed, 1710 insertions(+), 119 deletions(-)
 create mode 100644 m4/aclocal-flags.m4
 create mode 100755 tests/acloca14b.test
 create mode 100755 tests/acloca22b.test
 create mode 100755 tests/aclocal-amflags.test
 create mode 100755 tests/aclocalflags-acdir.test
 create mode 100644 tests/aclocalflags-advanced.sh
 create mode 100755 tests/aclocalflags-cmdline-precedence.test
 create mode 100755 tests/aclocalflags-empty.test
 create mode 100755 tests/aclocalflags-indirections.test
 create mode 100755 tests/aclocalflags-install.test
 create mode 100755 tests/aclocalflags-invalid.test
 create mode 100755 tests/aclocalflags-left-to-right.test
 create mode 100755 tests/aclocalflags-macrodir-precedence.test
 create mode 100755 tests/aclocalflags-macrodir.test
 create mode 100755 tests/aclocalflags-moreopts.test
 create mode 100755 tests/aclocalflags-options-with-args.test
 create mode 100755 tests/aclocalflags-rebuild.test
 create mode 100755 tests/aclocalflags-reset.test
 create mode 100755 tests/aclocalflags-whitespaces.test
 create mode 100755 tests/aclocalflags.test

diff --git a/ChangeLog b/ChangeLog
index 0540fc8..35dcf06 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,90 @@
+2010-12-28  Stefano Lattarini  <address@hidden>
+
+       Trace macros for aclocal options, deprecate ACLOCAL_AMFLAGS.
+       Maintaining ACLOCAL_AMFLAGS in Makefile.am to pass extra flags
+       to aclocal is (and have always been) quite of an hack.
+       For example, autoreconf is forced to grep Makefile.am to honour
+       those flags; and this is a bad obsolescent behaviour: in fact,
+       the autotools have moved consistently in the past years from
+       custom grepping of Makefile.am and/or configure.ac to tracing
+       of m4 macro calls, which is more consistent, more reliable and
+       more flexible.
+       And when autoreconf is not used, the developer is forced to add
+       *by hand* the flags specified by ACLOCAL_AMFLAGS to the aclocal
+       calls not triggered by make rebuild rules; here lie again more
+       duplication and more chances for errors.
+       Thus we now make aclocal trace some more macros, that it can use
+       to automatically find out extra flags -- for example, a call to
+       AC_CONFIG_MACRO_DIR([dir]) will cause aclocal to add `-I dir' to
+       its flags.
+       We also define two new macros, `AM_EXTRA_ACLOCAL_FLAGS' and
+       `AM_RESET_ACLOCAL_FLAGS', whose only purpose is to allow setting
+       of arbitrary aclocal flags in configure.ac.
+       * NEWS: Updated.
+       * doc/automake.texi (aclocal Options From macros): New node.
+       (Local Macros): Update.
+       (Serials): Update.
+       (Rebuilding): Remove references to ACLOCAL_AMFLAGS.
+       (Flag Variables Ordering): Likewise.
+       * lib/am/configure.am: Updated comments.
+       * aclocal.in: Implement processing of extra flags derived from
+       macro calls.
+       (@aclocal_flags): New global variable.
+       (trace_used_macros): Also trace macros `AC_CONFIG_MACRO_DIR',
+       `AM_RESET_ACLOCAL_FLAGS' and `_AM_EXTRA_ACLOCAL_FLAGS', and
+       collect extra aclocal flags derived from calls to those macros.
+       (parse_arguments): Now accept an array of parameters, and process
+       it instead of @ARGV.  Code for setup and normalization of system
+       include dirs moved ...
+       (setup_system_includes): ... into this new subroutine.
+       * m4/aclocal-flags.m4: New file, containing definitions of ...
+       (AM_EXTRA_ACLOCAL_FLAGS, AM_RESET_ACLOCAL_FLAGS): ... these new
+       public macros, and ...
+       (_AM_EXTRA_ACLOCAL_FLAGS): ... this new private macro.
+       * m4/Makefile.am (dist_m4data_DATA): Updated.
+       * tests/subpkg.test: Updated: add `AC_CONFIG_MACRO_DIR' call to
+       configure.in, remove setting of `ACLOCAL_AMFLAGS' in Makefile.am
+       and use of aclocal command line arguments.
+       * tests/subpkg2.test: Likewise.
+       * tests/subdir8.test: Likewise.
+       * tests/remake10c.test: Likewise.
+       * tests/remake8a.test: Likewise.
+       * tests/remake8b.test: Likewise.
+       * tests/aclocal4.test: Likewise.
+       * tests/aclocal6.test: Likewise.
+       * tests/acloca14.test: Likewise.
+       * tests/acloca22.test: Likewise.
+       * tests/aclocal5.test: Likewise, and do not not invade the
+       Automake namespace (this avoids spurious failures).
+       * tests/acloca14b.test: New test, identical to the previous
+       version of `acloca14.test'; it is kept to verify backwards
+       compatibility.
+       * tests/acloca22b.test: Likewise (but for `acloca22.test').
+       * tests/aclocal-amflags.test: New test, check for backwards
+       compatibility that ACLOCAL_AMFLAGS still works.
+       * tests/aclocalflags-cmdline-precedence.test: New test.
+       * tests/aclocalflags-empty.test: Likewise.
+       * tests/aclocalflags-install.test: Likewise.
+       * tests/aclocalflags-invalid.test: Likewise.
+       * tests/aclocalflags-left-to-right.test: Likewise.
+       * tests/aclocalflags-macrodir-precedence.test: Likewise.
+       * tests/aclocalflags-macrodir.test: Likewise.
+       * tests/aclocalflags-moreopts.test: Likewise.
+       * tests/aclocalflags-options-with-args.test: Likewise.
+       * tests/aclocalflags-rebuild.test: Likewise.
+       * tests/aclocalflags-reset.test: Likewise.
+       * tests/aclocalflags-indirections.test: Likewise.
+       * tests/aclocalflags-whitespaces.test: Likewise.
+       * tests/aclocalflags-advanced.sh: New helper script, sourced
+       by the last two new tests above.
+       * tests/aclocalflags-acdir.test: New test, currently xfailing
+       due to a testsuite weakness.
+       * tests/Makefile.am (TESTS, XFAIL_TESTS, EXTRA_DIST): Updated.
+       Define correct dependencies for the logs of tests that source
+       the new `aclocalflags-advanced.sh' helper script.
+       * tests/.gitignore: Updated.
+       From a suggestion by Eric Blake.
+
 2010-12-22  Stefano Lattarini  <address@hidden>
 
        Add some tests on 'cygnus' mode.
diff --git a/NEWS b/NEWS
index 5e24313..f6274e2 100644
--- a/NEWS
+++ b/NEWS
@@ -40,6 +40,10 @@ New in 1.11a:
     adds them to the normal list of dependencies, but without overwriting the
     foo_DEPENDENCIES variable, which is normally computed by automake.
 
+  - Now aclocal traces macros AC_CONFIG_MACRO_DIR, AM_EXTRA_ACLOCAL_FLAGS and
+    AM_RESET_ACLOCAL_FLAGS to automatically find out options it has to honour.
+    This change has made the special ACLOCAL_AMFLAGS variable obsolete.
+
 Bugs fixed in 1.11a:
 
   - Lots of minor bugfixes.
diff --git a/aclocal.in b/aclocal.in
index 4c81a47..fb6fcfb 100644
--- a/aclocal.in
+++ b/aclocal.in
@@ -142,10 +142,13 @@ 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;
 
+# Arguments for aclocal invocation, extracted from call to macro
+# AM_ACLOCAL_FLAGS.  This variable is set by `trace_used_macros'.
+my @aclocal_flags;
+
 # If set, names a temporary file that must be erased on abnormal exit.
 my $erase_me;
 
@@ -667,13 +670,16 @@ 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',
+                    '_AM_EXTRA_ACLOCAL_FLAGS')),
                   # Do not trace $1 for all other macros as we do
                   # not need it and it might contains harmful
                   # characters (like newlines).
@@ -683,6 +689,14 @@ sub trace_used_macros ()
 
   my $tracefh = new Automake::XFile ("$traces $configure_ac |");
 
+  # Extra arguments for aclocal invocation, extracted from calls
+  # to macro AM_EXTRA_ACLOCAL_FLAGS.
+  my @extra_aclocal_flags;
+
+  # Directory containing extra m4 files for macros definition, as
+  # extracted from call to macro AC_CONFIG_MACRO_DIR.
+  my $ac_config_macro_dir;
+
   my %traced = ();
 
   while ($_ = $tracefh->getline)
@@ -692,14 +706,34 @@ 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;
+        }
+      elsif ($macro eq '_AM_EXTRA_ACLOCAL_FLAGS')
+        {
+          push @extra_aclocal_flags, split (' ', $arg1);
+        }
+      elsif ($macro eq 'AM_RESET_ACLOCAL_FLAGS')
+        {
+          @extra_aclocal_flags = ();
+          $ac_config_macro_dir = undef;
+        }
     }
 
+  @aclocal_flags = defined $ac_config_macro_dir ?
+                           ('-I', $ac_config_macro_dir) : ();
+  push @aclocal_flags, @extra_aclocal_flags;
+
   $tracefh->close;
 
   return %traced;
@@ -921,8 +955,9 @@ EOF
 }
 
 # Parse command line.
-sub parse_arguments ()
+sub parse_arguments (@)
 {
+  local @ARGV = @_;
   my $print_and_exit = 0;
   my $diff_command;
 
@@ -1013,7 +1048,10 @@ sub parse_arguments ()
       fatal ("--install should copy macros in the directory indicated by the"
             . "\nfirst -I option, but no -I was supplied");
     }
+}
 
+sub setup_system_includes()
+{
   if (! -d $system_includes[0])
     {
       # By default $(datadir)/aclocal doesn't exist.  We don't want to
@@ -1025,7 +1063,7 @@ sub parse_arguments ()
     }
   else
     {
-      # Finally, adds any directory listed in the `dirlist' file.
+      # Finally, add any directory listed in the `dirlist' file.
       if (open (DIRLIST, "$system_includes[0]/dirlist"))
        {
          while (<DIRLIST>)
@@ -1048,7 +1086,8 @@ sub parse_arguments ()
 ################################################################
 
 parse_WARNINGS;                    # Parse the WARNINGS environment variable.
-parse_arguments;
+parse_arguments @ARGV;
+setup_system_includes;
 $configure_ac = require_configure_ac;
 
 # We may have to rerun aclocal if some file have been installed, but
@@ -1059,16 +1098,30 @@ $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 $arguments_reparsed = 0;
 while (1)
   {
     ++$loop;
-    prog_error "too many loops" if $loop > 2;
+    prog_error "too many loops" if $loop > 2 + $arguments_reparsed;
 
     reset_maps;
     scan_m4_files;
     scan_configure;
     last if $exit_code;
     my %macro_traced = trace_used_macros;
+    if (@aclocal_flags && !$arguments_reparsed)
+      {
+        # The command line options should always take precedence, so
+        # process them later.
+        # The two calls to `parse_arguments' below are required to deal
+        # correctly with e.g. missing arguments for options specified
+        # in configure.ac.
+        parse_arguments @aclocal_flags;
+        parse_arguments @ARGV;
+        setup_system_includes;
+        $arguments_reparsed = 1;
+        next;
+      }
     last if write_aclocal ($output_file, keys %macro_traced);
     last if $dry_run;
   }
diff --git a/doc/automake.texi b/doc/automake.texi
index 38142ec..5afd1e4 100644
--- a/doc/automake.texi
+++ b/doc/automake.texi
@@ -184,6 +184,7 @@ Scanning @file{configure.ac}
 Auto-generating aclocal.m4
 
 * aclocal Options::             Options supported by aclocal
+* aclocal Options From Macros:: Enabling aclocal options from autoconf macros
 * Macro Search Path::           How aclocal finds .m4 files
 * Extending aclocal::           Writing your own aclocal macros
 * Local Macros::                Organizing local macros
@@ -3110,6 +3111,7 @@ overridden using the @env{AUTOM4TE} environment variable.
 
 @menu
 * aclocal Options::             Options supported by aclocal
+* aclocal Options From Macros:: Enabling aclocal options from autoconf macros
 * Macro Search Path::           How aclocal finds .m4 files
 * Extending aclocal::           Writing your own aclocal macros
 * Local Macros::                Organizing local macros
@@ -3221,6 +3223,85 @@ way as it is for @command{automake} (@pxref{Invoking 
Automake}).
 
 @end table
 
address@hidden aclocal Options From Macros
address@hidden Enabling aclocal options from autoconf macros
+
+Starting from Automake 1.12, @command{aclocal} traces some special macros
+to allow package authors declare a default set of @command{aclocal}
+options to be honoured in their package.
+
address@hidden
+These macros are:
+
address@hidden @code
+
address@hidden @code{AC_CONFIG_MACRO_DIR(address@hidden)}
address@hidden AC_CONFIG_MACRO_DIR
+It causes @command{aclocal} to add @var{macro-dir} to the list of local
+directories searched by @command{aclocal} for additional m4 macro
+definitions.  Roughly similar to specifying @samp{-I @var{macro-dir}}
+on the command line.
+
address@hidden @code{AM_EXTRA_ACLOCAL_FLAGS(address@hidden)}
address@hidden AM_EXTRA_ACLOCAL_FLAGS
+Extend with @var{list-of-options} the default set of @command{aclocal}
+options to be honored.  Multiple calls to this macro are cumulative.
+Here @var{list-of-options} is a whitespace separated list of valid
address@hidden command line options; if an aclocal option
address@hidden@var{opt}} takes an argument, it can be specified in
address@hidden as either @address@hidden@address@hidden
+or @address@hidden@var{opt}} @var{arg}}.
+
address@hidden @code{AM_RESET_ACLOCAL_FLAGS}
address@hidden AM_RESET_ACLOCAL_FLAGS
+Clobber the list of extra @command{aclocal} options derived
+through earlier calls to either @code{AM_EXTRA_ACLOCAL_FLAGS}
+or @code{AC_CONFIG_MACRO_DIR}.
+
address@hidden table
+
+Note that the directory specified in @code{AC_CONFIG_MACRO_DIR}
+always takes precedence over all the directories specified earlier
+or later through @code{AM_EXTRA_ACLOCAL_FLAGS} (with e.g.,
address@hidden @var{another-dir}}).
+
address@hidden
+Thus, the following:
+
address@hidden
+AM_EXTRA_ACLOCAL_FLAGS([-I foo-dir --install])
+AC_CONFIG_MACRO_DIR([macro-dir])
+AM_EXTRA_ACLOCAL_FLAGS([-I bar-dir])
address@hidden example
+
address@hidden
+will be (at least for what concerns @command{aclocal}) roughly
+equivalent to:
+
address@hidden
+AM_EXTRA_ACLOCAL_FLAGS([-I macro-dir -I foo-dir --install -I bar-dir])
address@hidden example
+
address@hidden
+If this precedence is undesirable, you'll have to resort to
address@hidden, as in e.g.:
+
address@hidden
+AC_CONFIG_MACRO_DIR([macro-dir])
+AM_RESET_ACLOCAL_FLAGS
+AM_EXTRA_ACLOCAL_FLAGS([-I foo-dir --install])
+AM_EXTRA_ACLOCAL_FLAGS([-I bar-dir])
address@hidden example
+
address@hidden
+which will be (mostly) equivalent to:
+
address@hidden
+AM_EXTRA_ACLOCAL_FLAGS([-I foo-dir --install -I bar-dir])
address@hidden example
+
address@hidden TODO: maybe add more examples?
+
 @node Macro Search Path
 @subsection Macro Search Path
 
@@ -3477,32 +3558,21 @@ 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.
 
address@hidden ACLOCAL_AMFLAGS
 The second possibility, which we do recommend, is to write each macro
 in its own file and gather all 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
+directory is usually called @file{m4/}.  Then it's enough to update
address@hidden by adding a proper call to @code{AC_CONFIG_MACRO_DIR}:
 
 @example
-ACLOCAL_AMFLAGS = -I m4
+AC_CONFIG_MACRO_DIR([m4])
 @end example
 
address@hidden 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
address@hidden 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
address@hidden
address@hidden will then take care of automatically adding @file{m4/}
+to its search path for m4 files (but remember that any later call to the
+macro @code{AM_RESET_ACLOCAL_FLAGS} would override this; @pxref{aclocal
+Options From Macros} for more information).
 
-When @samp{aclocal -I m4} is run, it will build an @file{aclocal.m4}
+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}.
@@ -3533,17 +3603,18 @@ 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:
+the above problem.  Simply add:
 
 @example
-ACLOCAL_AMFLAGS = -I m4 --install
+AM_EXTRA_ACLOCAL_FLAGS([--install])
 @end example
 
address@hidden
+to your @file{configure.ac}.
+
 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}
@@ -3624,11 +3695,12 @@ 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])
+AM_EXTRA_ACLOCAL_FLAGS([--install])
 @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
@@ -8889,15 +8961,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.
 
address@hidden ACLOCAL_AMFLAGS
-Sometimes you need to run @command{aclocal} with an argument like
address@hidden 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
address@hidden; this holds arguments that are passed verbatim
-to @command{aclocal}.  This variable is only useful in the top-level
address@hidden
-
 @vindex CONFIG_STATUS_DEPENDENCIES
 @vindex CONFIGURE_DEPENDENCIES
 @cindex @file{version.sh}, example
@@ -11165,10 +11228,8 @@ obeys this naming scheme.  The slight difference is 
that
 
 However you should not think that all variables ending with
 @code{FLAGS} follow this convention.  For instance,
address@hidden (@pxref{Checking the Distribution}) and
address@hidden (see @ref{Rebuilding} and @ref{Local Macros}),
-are two variables that are only useful to the maintainer and have no
-user counterpart.
address@hidden (@pxref{Checking the Distribution})
+is a variable 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 e9299d6..10fd52b 100644
--- a/lib/am/configure.am
+++ b/lib/am/configure.am
@@ -1,6 +1,6 @@
 ## automake - create Makefile.in from Makefile.am
-## Copyright (C) 2001, 2002, 2003, 2004, 2006, 2007, 2008, 2009  Free
-## Software Foundation, Inc.
+## Copyright (C) 2001, 2002, 2003, 2004, 2006, 2007, 2008, 2009, 2010
+## 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
@@ -110,13 +110,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 non-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/m4/Makefile.am b/m4/Makefile.am
index 0cf074b..3bc7515 100644
--- a/m4/Makefile.am
+++ b/m4/Makefile.am
@@ -22,6 +22,7 @@ m4datadir = $(datadir)/aclocal-$(APIVERSION)
 
 dist_m4data_DATA = \
 $(top_srcdir)/m4/amversion.m4 \
+aclocal-flags.m4 \
 as.m4 \
 auxdir.m4 \
 ccstdc.m4 \
diff --git a/m4/Makefile.in b/m4/Makefile.in
index e225dd4..a1d3f65 100644
--- a/m4/Makefile.in
+++ b/m4/Makefile.in
@@ -192,6 +192,7 @@ top_srcdir = @top_srcdir@
 m4datadir = $(datadir)/aclocal-$(APIVERSION)
 dist_m4data_DATA = \
 $(top_srcdir)/m4/amversion.m4 \
+aclocal-flags.m4 \
 as.m4 \
 auxdir.m4 \
 ccstdc.m4 \
diff --git a/m4/aclocal-flags.m4 b/m4/aclocal-flags.m4
new file mode 100644
index 0000000..427f3f9
--- /dev/null
+++ b/m4/aclocal-flags.m4
@@ -0,0 +1,31 @@
+# Define aclocal flags in configure.ac                      -*- Autoconf -*-
+
+# Copyright (C) 2010 Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# serial 1
+
+# AM_RESET_ACLOCAL_FLAGS([FLAGS])
+# -------------------------------
+# Clobber list of additional flags for aclocal derived from other
+# macros (e.g., AC_CONFIG_MACRO_DIR and AM_EXTRA_ACLOCAL_FLAGS).
+# This macro is here only to be traced by aclocal.
+AC_DEFUN([AM_RESET_ACLOCAL_FLAGS], [])
+
+# AM_EXTRA_ACLOCAL_FLAGS([FLAGS])
+# -------------------------
+# Define flags for aclocal, in addition to those specified on
+# the command line and/or derived from other macros (e.g.,
+# AC_CONFIG_MACRO_DIR).  This macro is here only to be traced
+# by aclocal, which doesn't like newlines in macro arguments,
+# so flatten them.
+AC_DEFUN([AM_EXTRA_ACLOCAL_FLAGS],
+         [_AM_EXTRA_ACLOCAL_FLAGS(m4_flatten([$1]))])
+
+# aclocal trace this macro to find the aclocal flags.  This is a
+# private macro.  Using m4_define simplifies the logic in aclocal,
+# which can simply ignore this definition.
+m4_define([_AM_EXTRA_ACLOCAL_FLAGS], [])
diff --git a/tests/.gitignore b/tests/.gitignore
index 026e261..8cd6ee3 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -1,5 +1,5 @@
-aclocal-*
-automake-*
+aclocal-1.*
+automake-1.*
 defs-static
 instspc-tests.am
 parallel-tests.am
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 05e15bc..068f606 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -20,6 +20,7 @@ MAINTAINERCLEANFILES =
 EXTRA_DIST = ChangeLog-old
 
 XFAIL_TESTS = \
+aclocalflags-acdir.test \
 all.test \
 auxdir2.test \
 cond17.test \
@@ -93,6 +94,13 @@ EXTRA_DIST += instspc-tests.sh
 XFAIL_TESTS += $(instspc_xfail_tests)
 
 
+# These tests work by sourcing an helper script; thus their testlogs
+# depend on it.
+aclocalflags-indirections.log: aclocalflags-advanced.sh
+aclocalflags-whitespaces.log: aclocalflags-advanced.sh
+EXTRA_DIST += aclocalflags-advanced.sh
+
+
 TESTS = \
 aclocal.test \
 aclocal3.test \
@@ -107,6 +115,7 @@ acloca11.test \
 acloca12.test \
 acloca13.test \
 acloca14.test \
+acloca14b.test \
 acloca15.test \
 acloca16.test \
 acloca17.test \
@@ -115,7 +124,24 @@ acloca19.test \
 acloca20.test \
 acloca21.test \
 acloca22.test \
+acloca22b.test \
 acloca23.test \
+aclocal-amflags.test \
+aclocalflags.test \
+aclocalflags-acdir.test \
+aclocalflags-cmdline-precedence.test \
+aclocalflags-empty.test \
+aclocalflags-indirections.test \
+aclocalflags-install.test \
+aclocalflags-invalid.test \
+aclocalflags-left-to-right.test \
+aclocalflags-macrodir-precedence.test \
+aclocalflags-macrodir.test \
+aclocalflags-moreopts.test \
+aclocalflags-options-with-args.test \
+aclocalflags-rebuild.test \
+aclocalflags-reset.test \
+aclocalflags-whitespaces.test \
 acoutnoq.test \
 acoutpt.test \
 acoutpt2.test \
diff --git a/tests/Makefile.in b/tests/Makefile.in
index d0e08a6..9af2236 100644
--- a/tests/Makefile.in
+++ b/tests/Makefile.in
@@ -283,9 +283,9 @@ top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
 MAINTAINERCLEANFILES = $(parallel_tests) $(instspc_tests)
 EXTRA_DIST = ChangeLog-old gen-parallel-tests instspc-tests.sh \
-       $(TESTS)
-XFAIL_TESTS = all.test auxdir2.test cond17.test gcj6.test \
-       override-conditional-2.test txinfo5.test \
+       aclocalflags-advanced.sh $(TESTS)
+XFAIL_TESTS = aclocalflags-acdir.test all.test auxdir2.test \
+       cond17.test gcj6.test override-conditional-2.test txinfo5.test \
        $(instspc_xfail_tests)
 parallel_tests = backcompat5-p.test check-p.test check10-p.test \
        check11-p.test check12-p.test check2-p.test check3-p.test \
@@ -370,6 +370,7 @@ acloca11.test \
 acloca12.test \
 acloca13.test \
 acloca14.test \
+acloca14b.test \
 acloca15.test \
 acloca16.test \
 acloca17.test \
@@ -378,7 +379,24 @@ acloca19.test \
 acloca20.test \
 acloca21.test \
 acloca22.test \
+acloca22b.test \
 acloca23.test \
+aclocal-amflags.test \
+aclocalflags.test \
+aclocalflags-acdir.test \
+aclocalflags-cmdline-precedence.test \
+aclocalflags-empty.test \
+aclocalflags-indirections.test \
+aclocalflags-install.test \
+aclocalflags-invalid.test \
+aclocalflags-left-to-right.test \
+aclocalflags-macrodir-precedence.test \
+aclocalflags-macrodir.test \
+aclocalflags-moreopts.test \
+aclocalflags-options-with-args.test \
+aclocalflags-rebuild.test \
+aclocalflags-reset.test \
+aclocalflags-whitespaces.test \
 acoutnoq.test \
 acoutpt.test \
 acoutpt2.test \
@@ -1611,6 +1629,11 @@ $(instspc_tests): Makefile.am
 # All instspc*.test tests work by sourcing the instspc-tests.sh script.
 $(instspc_tests:.test=.log): instspc-tests.sh
 
+# These tests work by sourcing an helper script; thus their testlogs
+# depend on it.
+aclocalflags-indirections.log: aclocalflags-advanced.sh
+aclocalflags-whitespaces.log: aclocalflags-advanced.sh
+
 # Each test case depends on defs, aclocal, and automake.
 $(TEST_LOGS): defs aclocal-$(APIVERSION) automake-$(APIVERSION)
 
diff --git a/tests/acloca14.test b/tests/acloca14.test
index 1bdf7c7..76cc868 100755
--- a/tests/acloca14.test
+++ b/tests/acloca14.test
@@ -23,6 +23,7 @@ required=GNUmake
 set -e
 
 cat >> configure.in << 'END'
+AC_CONFIG_MACRO_DIR([defs])
 AM_PROG_LIBTOOL
 AC_OUTPUT
 END
@@ -48,7 +49,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/tests/acloca14b.test b/tests/acloca14b.test
new file mode 100755
index 0000000..3a4bd5f
--- /dev/null
+++ b/tests/acloca14b.test
@@ -0,0 +1,123 @@
+#! /bin/sh
+# Copyright (C) 2004, 2008, 2010 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.
+# NOTE: this test works by using the obsolete `ACLOCAL_AMFLAGS' make
+# variable; see sister test `aclocal14.test' for a modern equivalent.
+
+required=GNUmake
+. ./defs || Exit 1
+
+set -e
+
+cat >> configure.in << '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
+
+$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 stamp
+$sleep
+
+cat >>c.m4 <<\EOF
+AC_DEFUN([FOO], [ANOTHER_MACRO])
+EOF
+
+$MAKE
+
+# Because c.m4 has changed, aclocal.m4 must have been rebuilt.
+test `ls -1t aclocal.m4 stamp | sed 1q` = aclocal.m4
+# 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 stamp
+
+# If FOO where to be used, that would be another story, of course.
+cat >>configure.in <<EOF
+FOO
+EOF
+
+cp aclocal.m4 stamp
+$sleep
+
+$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/tests/acloca22.test b/tests/acloca22.test
index 913e4d9..df724bc 100755
--- a/tests/acloca22.test
+++ b/tests/acloca22.test
@@ -1,5 +1,5 @@
 #! /bin/sh
-# Copyright (C) 2007  Free Software Foundation, Inc.
+# Copyright (C) 2007, 2010 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
@@ -22,28 +22,37 @@
 set -e
 
 cat >>configure.in <<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
+
 sed 's/FOO/BAR/' < configure.in > t
 mv -f t configure.in
 rm -f foo.m4
+
 $MAKE
 grep GREPFOO Makefile && Exit 1
 grep GREPBAR Makefile
+
+:
diff --git a/tests/acloca22b.test b/tests/acloca22b.test
new file mode 100755
index 0000000..d41d692
--- /dev/null
+++ b/tests/acloca22b.test
@@ -0,0 +1,51 @@
+#! /bin/sh
+# Copyright (C) 2007, 2010 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 `aclocal14.test' for a modern equivalent.
+
+. ./defs || Exit 1
+
+set -e
+
+cat >>configure.in <<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.in > t
+mv -f t configure.in
+rm -f foo.m4
+$MAKE
+grep GREPFOO Makefile && Exit 1
+grep GREPBAR Makefile
diff --git a/tests/aclocal-amflags.test b/tests/aclocal-amflags.test
new file mode 100755
index 0000000..9f7ee3e
--- /dev/null
+++ b/tests/aclocal-amflags.test
@@ -0,0 +1,71 @@
+#! /bin/sh
+# Copyright (C) 2010 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
+
+set -e
+
+cat >> configure.in <<'END'
+MACRO_FOO || { exit 1; (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 '^aclocal:.*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.in > t
+mv -f t configure.in
+
+$MAKE Makefile >output 2>&1 || { cat output; Exit 1; }
+cat output
+grep "^aclocal:.*found macro.*MACRO_BAR.*m4_2/bar\.m4" output
+grep "^aclocal:.*macro.*MACRO_FOO" output && Exit 1
+test ! -r foo
+test -f bar
+
+$MAKE distcheck
+
+:
diff --git a/tests/aclocal4.test b/tests/aclocal4.test
index 9fa96ec..cc09399 100755
--- a/tests/aclocal4.test
+++ b/tests/aclocal4.test
@@ -1,5 +1,5 @@
 #! /bin/sh
-# Copyright (C) 2003  Free Software Foundation, Inc.
+# Copyright (C) 2003, 2010 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
@@ -24,6 +24,7 @@ required=GNUmake
 set -e
 
 cat >>configure.in <<EOF
+AC_CONFIG_MACRO_DIR([m4])
 AC_PROG_RANLIB
 AC_PROG_CC
 MY_MACRO
@@ -48,7 +49,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
@@ -58,14 +58,14 @@ check-not-foo: distdir
        test -f $(distdir)/lib/bar.c
 EOF
 
-$ACLOCAL -I m4
+$ACLOCAL
 $AUTOCONF
 $AUTOMAKE
 ./configure
 $MAKE check-not-foo
 
 # Update one of the macros.  This should cause ./configure, Makefile.in,
-# Makefile, lib/Makefile.in, and lib/Makfile to be updated.  This assumes
+# Makefile, lib/Makefile.in, and lib/Makefile to be updated.  This assumes
 # GNU make.
 
 cat >m4/mymacro.m4 <<'EOF'
@@ -73,3 +73,5 @@ AC_DEFUN([MY_MACRO], [AC_LIBOBJ([foo])])
 EOF
 
 $MAKE check-foo
+
+:
diff --git a/tests/aclocal5.test b/tests/aclocal5.test
index b206587..e65ca02 100755
--- a/tests/aclocal5.test
+++ b/tests/aclocal5.test
@@ -1,5 +1,5 @@
 #! /bin/sh
-# Copyright (C) 2003, 2004, 2005  Free Software Foundation, Inc.
+# Copyright (C) 2003, 2004, 2005, 2010 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
@@ -25,23 +25,23 @@ required='GNUmake'
 set -e
 
 cat >> configure.in << '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 address@hidden)' > m4/moredefs.m4
+echo 'AC_DEFUN([FOO_TEST], [echo address@hidden)' > m4/moredefs.m4
 
-$ACLOCAL -I m4
+$ACLOCAL
 $AUTOCONF
 $AUTOMAKE --copy --add-missing
 ./configure
@@ -49,9 +49,9 @@ $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.
-echo 'AU_ALIAS([AM_TEST], [AC_SUBST])' > m4/moredefs.m4
+echo 'AU_ALIAS([FOO_TEST], [AC_SUBST])' > m4/moredefs.m4
 cd sub
 $MAKE
 cd ..
@@ -62,9 +62,9 @@ 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.
-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/tests/aclocal6.test b/tests/aclocal6.test
index ea6bac3..bce2b4e 100755
--- a/tests/aclocal6.test
+++ b/tests/aclocal6.test
@@ -1,5 +1,5 @@
 #! /bin/sh
-# Copyright (C) 2003  Free Software Foundation, Inc.
+# Copyright (C) 2003, 2010 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
@@ -25,12 +25,12 @@ set -e
 cat >> configure.in << '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
@@ -40,7 +40,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/tests/aclocalflags-acdir.test b/tests/aclocalflags-acdir.test
new file mode 100755
index 0000000..cec4b42
--- /dev/null
+++ b/tests/aclocalflags-acdir.test
@@ -0,0 +1,46 @@
+#! /bin/sh
+# Copyright (C) 2010 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 option `--acdir' is supported in
+# AM_EXTRA_ACLOCAL_FLAGS.
+#
+# FIXME: this test currently doesn't work, since the `aclocal'
+# wrapper script in `$(top_srcdir)/tests' pass its own `--acdir'
+# command line argument to the real aclocal, and such a command
+# line value for acdir obviously wins over the one set by
+# AM_EXTRA_ACLOCAL_FLAGS in configure.in.  We probably need
+# better wrapper scripts...
+
+. ./defs || Exit 1
+
+set -e
+
+mkdir s-m4 x-m4
+echo x-m4 > s-m4/dirlist
+echo 'AC_DEFUN([FOO], [%%-z-a-r-d-o-z-%%])' > s-m4/foo.m4
+echo 'AC_DEFUN([BAR], [//~Q~U~U~X~//])' > x-m4/baz.m4
+
+cat > configure.in <<'END'
+AM_EXTRA_ACLOCAL_FLAGS([--acdir ./none --acdir=./s-m4])
+FOO
+BAR
+END
+
+$ACLOCAL
+$FGREP '%%-z-a-r-d-o-z-%%' aclocal.m4
+$FGREP '//~Q~U~U~X~//' aclocal.m4
+
+:
diff --git a/tests/aclocalflags-advanced.sh b/tests/aclocalflags-advanced.sh
new file mode 100644
index 0000000..9923e89
--- /dev/null
+++ b/tests/aclocalflags-advanced.sh
@@ -0,0 +1,66 @@
+#! /bin/sh
+# Copyright (C) 2010 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/>.
+
+# Shared code for "advanced" tests on AM_ACLOCAL_FLAGS and
+# AM_EXTRA_ACLOCAL_FLAGS.
+# This file expects to be sourced after ./defs has been already
+# sourced, and a proper file `configure.append' has been set up.
+
+set -e
+
+# Sanity check, to avoid overriding random user files.
+case `test -f ../defs-static && echo OK`,`pwd` in
+  OK,*.dir);;
+  *) echo "$0: curdir is not safe, abort" >&2; Exit 99 || exit 99;;
+esac
+
+cat >> configure.in <<END
+FOO_MACRO || { (exit 1); exit 1; }
+BAR_MACRO || { (exit 1); exit 1; }
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+DISTCLEANFILES = foo bar
+END
+
+mkdir foo-macro-dir bar-macro-dir
+cat > foo-macro-dir/foo.m4 <<'END'
+AC_DEFUN([FOO_MACRO], [: > foo])
+END
+cat > bar-macro-dir/bar.m4 <<'END'
+AC_DEFUN([BAR_MACRO], [: > bar])
+END
+
+$ACLOCAL 2>stderr || { cat stderr >&2; Exit 1; }
+cat stderr >&2
+sed 20q quux.m4
+grep '^#.*generated.*by aclocal' quux.m4
+test ! -r aclocal.m4
+grep "^aclocal:.*found macro.*FOO_MACRO.*foo-macro-dir" stderr
+grep "^aclocal:.*found macro.*BAR_MACRO.*bar-macro-dir" stderr
+
+mv quux.m4 aclocal.m4
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+test -f foo
+test -f bar
+
+$MAKE distcheck
+
+:
diff --git a/tests/aclocalflags-cmdline-precedence.test 
b/tests/aclocalflags-cmdline-precedence.test
new file mode 100755
index 0000000..9ea8ac8
--- /dev/null
+++ b/tests/aclocalflags-cmdline-precedence.test
@@ -0,0 +1,33 @@
+#! /bin/sh
+# Copyright (C) 2010 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 command line flags "win" over AM_EXTRA_ACLOCAL_FLAGS.
+
+. ./defs || Exit 1
+
+set -e
+
+# The AC_INIT call is required by older autoconf (< 2.64)
+cat > configure.in <<END
+AC_INIT([$me], [1.0])
+AM_EXTRA_ACLOCAL_FLAGS([--output=bad.m4])
+END
+
+$ACLOCAL --output=good.m4
+test -f good.m4
+test ! -r bad.m4
+
+:
diff --git a/tests/aclocalflags-empty.test b/tests/aclocalflags-empty.test
new file mode 100755
index 0000000..5ee318a
--- /dev/null
+++ b/tests/aclocalflags-empty.test
@@ -0,0 +1,29 @@
+#! /bin/sh
+# Copyright (C) 2010 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 is ok to call AM_EXTRA_ACLOCAL_FLAGS  without arguments.
+
+. ./defs || Exit 1
+
+set -e
+
+for call in 'AM_EXTRA_ACLOCAL_FLAGS' 'AM_EXTRA_ACLOCAL_FLAGS([])'; do
+  # The AC_INIT call is required by older autoconf (< 2.64)
+  echo "AC_INIT([$me], [1.0]) $call" > configure.in
+  $ACLOCAL --force
+done
+
+:
diff --git a/tests/aclocalflags-indirections.test 
b/tests/aclocalflags-indirections.test
new file mode 100755
index 0000000..50a4849
--- /dev/null
+++ b/tests/aclocalflags-indirections.test
@@ -0,0 +1,40 @@
+#! /bin/sh
+# Copyright (C) 2010 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 AM_EXTRA_ACLOCAL_FLAGS is correctly traced when
+# indirections (macros as arguments, m4_include, ...) are involved.
+# This is admittedly a stress test.
+
+. ./defs || Exit 1
+
+set -e
+
+cat > extra-aclocal-flags.m4 <<'END'
+m4_define([add_aclocal_flags], [AM_EXTRA_ACLOCAL_FLAGS($@)])
+AM_EXTRA_ACLOCAL_FLAGS([-I bar-macro-dir])
+END
+
+cat >> configure.in <<'END'
+m4_define([FOODIR], [foo-macro-dir])
+m4_define([VERBOSEOPT], [--verbose])
+AM_EXTRA_ACLOCAL_FLAGS(-I FOODIR m4_defn([VERBOSEOPT]))
+m4_include([extra-aclocal-flags.m4])
+m4_pushdef([output], [invalid-option])
+add_aclocal_flags([--output=quux.m4])
+m4_popdef([output])
+END
+
+. "$testsrcdir"/aclocalflags-advanced.sh
diff --git a/tests/aclocalflags-install.test b/tests/aclocalflags-install.test
new file mode 100755
index 0000000..3c209ca
--- /dev/null
+++ b/tests/aclocalflags-install.test
@@ -0,0 +1,63 @@
+#! /bin/sh
+# Copyright (C) 2010 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 option `--install' is supported in
+# AM_EXTRA_ACLOCAL_FLAGS.
+# These checks are done in this standalone, separate testcase, rather
+# than in the `aclocaflags-moreopts.test' testcase, because they need
+# a proper hack to work with the aclocal wrapper script used by the
+# testsuite.
+# NOTE: This test relies on the file `$(top_srcdir)/m4/dirlist'.
+
+. ./defs || Exit 1
+
+set -e
+
+# Used by the wrapper script around aclocal.
+ACLOCAL_TESTSUITE_FLAGS='-I m4'
+export ACLOCAL_TESTSUITE_FLAGS
+
+mkdir m4 dirlist-test
+
+cat > dirlist-test/foobar.m4 <<'END'
+AC_DEFUN([FOO_BAR], [:])
+END
+
+# The AC_INIT call is required by older autoconf (< 2.64)
+cat > configure.in <<END
+AC_INIT([$me], [1.0])
+AM_EXTRA_ACLOCAL_FLAGS([--install])
+AM_WITH_DMALLOC
+FOO_BAR
+END
+
+$ACLOCAL --verbose 2>stderr || { cat stderr >&2; Exit 1; }
+cat stderr >&2
+
+# dmalloc.m4 should be injected by content, not m4_included
+$FGREP 'AM_WITH_DMALLOC' aclocal.m4
+grep 'm4_include.*dmalloc\.m4' aclocal.m4 && Exit 1
+test ! -r m4/dmalloc.m4
+
+# m4/foobar.m4 should be m4_included, not injected by content
+$FGREP 'FOO_BAR' aclocal.m4 && Exit 1
+$FGREP 'm4_include([m4/foobar.m4])' aclocal.m4
+diff dirlist-test/foobar.m4 m4/foobar.m4
+
+# aclocal should tell what file is installing in local include dir
+grep 'installing.*m4/foobar\.m4' stderr
+
+:
diff --git a/tests/aclocalflags-invalid.test b/tests/aclocalflags-invalid.test
new file mode 100755
index 0000000..9133225
--- /dev/null
+++ b/tests/aclocalflags-invalid.test
@@ -0,0 +1,61 @@
+#! /bin/sh
+# Copyright (C) 2010 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 invalid options and invalid option usages in
+# AM_EXTRA_ACLOCAL_AMFLAGS are diagnosed.
+
+. ./defs || Exit 1
+
+set -e
+
+prepare_input ()
+{
+  # The AC_INIT call is required by older autoconf (< 2.64)
+  cat > configure.in <<END
+AC_INIT([$me], [1.0])
+AM_EXTRA_ACLOCAL_FLAGS([$*])
+END
+}
+
+rm -rf autom4te*.cache
+prepare_input '--foobar'
+$ACLOCAL 2>stderr && { cat stderr >&2; Exit 1; }
+cat stderr >&2
+grep 'option.*--foobar' stderr
+test ! -r aclocal.m4
+
+rm -rf autom4te*.cache
+prepare_input 'foobar'
+$ACLOCAL 2>stderr && { cat stderr >&2; Exit 1; }
+cat stderr >&2
+grep 'option.*[^-]foobar' stderr
+test ! -r aclocal.m4
+
+rm -rf autom4te*.cache
+prepare_input '-I'
+$ACLOCAL 2>stderr && { cat stderr >&2; Exit 1; }
+cat stderr >&2
+grep 'option.*-I.*argument' stderr
+test ! -r aclocal.m4
+  
+rm -rf autom4te*.cache
+prepare_input '--output'
+$ACLOCAL 2>stderr && { cat stderr >&2; Exit 1; }
+cat stderr >&2
+grep 'option.*--output.*argument' stderr
+test ! -r aclocal.m4
+
+:
diff --git a/tests/aclocalflags-left-to-right.test 
b/tests/aclocalflags-left-to-right.test
new file mode 100755
index 0000000..6ad90d8
--- /dev/null
+++ b/tests/aclocalflags-left-to-right.test
@@ -0,0 +1,46 @@
+#! /bin/sh
+# Copyright (C) 2010 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 options in AM_EXTRA_ACLOCAL_FLAGS are read left-to-right.
+
+. ./defs || Exit 1
+
+set -e
+
+mkdir dir1 dir2
+
+cat > dir1/a.m4 <<'END'
+AC_DEFUN([MY_MACRO], [::success::])
+END
+
+cat > dir2/b.m4 <<'END'
+AC_DEFUN([MY_MACRO], [::failure::])
+END
+
+cat > configure.in <<END
+AC_INIT([$me], [1.0])
+AM_EXTRA_ACLOCAL_FLAGS([-Idir1 -Idir2])
+MY_MACRO
+END
+
+$ACLOCAL
+$AUTOCONF
+
+$FGREP 'MY_MACRO' configure && Exit 1
+$FGREP '::failure::' configure && Exit 1
+$FGREP '::success::' configure
+
+:
diff --git a/tests/aclocalflags-macrodir-precedence.test 
b/tests/aclocalflags-macrodir-precedence.test
new file mode 100755
index 0000000..2a4284c
--- /dev/null
+++ b/tests/aclocalflags-macrodir-precedence.test
@@ -0,0 +1,53 @@
+#! /bin/sh
+# Copyright (C) 2010 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 directory specified with AC_CONFIG_MACRO_DIR
+# takes precedence over those specified, earlier or later, with
+# AM_EXTRA_ACLOCAL_FLAGS.
+
+. ./defs || Exit 1
+
+set -e
+
+cat > configure.in <<END
+AC_INIT([$me], [1.0])
+AM_EXTRA_ACLOCAL_FLAGS([-I foo-dir])
+AC_CONFIG_MACRO_DIR([macro-dir])
+AM_EXTRA_ACLOCAL_FLAGS([-I bar-dir])
+MY_MACRO
+END
+
+mkdir macro-dir foo-dir bar-dir
+
+cat > macro-dir/file.m4 <<'END' 
+AC_DEFUN([MY_MACRO], [good--expansion])
+END
+
+cat > foo-dir/file.m4 <<'END' 
+AC_DEFUN([MY_MACRO], [bad--expansion--foo])
+END
+
+cat > bar-dir/file.m4 <<'END' 
+AC_DEFUN([MY_MACRO], [bad--expansion--bar])
+END
+
+$ACLOCAL
+$AUTOCONF
+
+$FGREP 'bad--expansion' configure && Exit 1
+$FGREP 'good--expansion' configure
+
+:
diff --git a/tests/aclocalflags-macrodir.test b/tests/aclocalflags-macrodir.test
new file mode 100755
index 0000000..18c8d22
--- /dev/null
+++ b/tests/aclocalflags-macrodir.test
@@ -0,0 +1,69 @@
+#! /bin/sh
+# Copyright (C) 2010 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 aclocal can determine a sensible default value for
+# aclocal flags from calls to AC_CONFIG_MACRO_DIR.  Also check
+# that this interacts nicely with rebuild rules.
+
+. ./defs || Exit 1
+
+set -e
+
+cat >> configure.in <<'END'
+AC_CONFIG_MACRO_DIR([macro-dir])
+my__FOO || { (exit 1); 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], [: > quux])
+END
+
+$MAKE Makefile
+test -f quux
+test ! -r bar
+
+$sleep
+
+cat > macro-dir/foo.m4 <<'END'
+AC_DEFUN([my__FOO], [[: my__FOO do nothing]])
+END
+
+$MAKE Makefile
+$FGREP ': my__FOO do nothing' configure
+
+$MAKE distcheck
+
+:
diff --git a/tests/aclocalflags-moreopts.test b/tests/aclocalflags-moreopts.test
new file mode 100755
index 0000000..9854b06
--- /dev/null
+++ b/tests/aclocalflags-moreopts.test
@@ -0,0 +1,104 @@
+#! /bin/sh
+# Copyright (C) 2010 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 all aclocal flags are supported in AM_EXTRA_ACLOCAL_FLAGS.
+# Do not check `--install' and `--acdir', since they have their own test
+# scripts.  Do not check `--diff', since it could be a little tricky,
+# and we are already being way too paranoid anyway.
+
+. ./defs || Exit 1
+
+set -e
+
+clean_cache ()
+{
+  rm -rf autom4te*.cache aclocal.m4
+}
+
+prepare_input ()
+{
+  # The AC_INIT call is required by older autoconf (< 2.64)
+  cat > configure.in <<END
+AC_INIT([$me], [1.0])
+AM_EXTRA_ACLOCAL_FLAGS([$*])
+END
+}
+
+# Remove extra options from aclocal calls, while keeping user override
+# for aclocal program.
+ACLOCAL=$original_ACLOCAL
+
+# To be compared with other aclocal outputs later.
+$ACLOCAL --help > help.txt
+$ACLOCAL --version > version.txt
+acdir=`$ACLOCAL --print-ac-dir` || Exit 1
+
+for opt in help version; do
+  clean_cache
+  prepare_input "--$opt"
+  $ACLOCAL > stdout || { cat stdout; Exit 1; }
+  cat stdout
+  diff $opt.txt stdout
+done
+rm -f stdout
+
+clean_cache
+prepare_input '--print-ac-dir'
+out=`$ACLOCAL` || Exit 1
+test x"$out" = x"$acdir"
+
+clean_cache
+prepare_input '--force'
+$ACLOCAL
+: > timestamp
+$sleep
+$ACLOCAL
+stat timestamp aclocal.m4 || : # for debugging
+test x"`ls -1t timestamp aclocal.m4 | sed 1q`" = x"aclocal.m4"
+rm -f timestamp
+
+clean_cache
+prepare_input '--output=quux.m4'
+$ACLOCAL
+grep  '^#.*generated.*by aclocal' quux.m4
+test ! -r aclocal.m4
+rm -f quux.m4
+
+clean_cache
+prepare_input '--verbose --dry'
+$ACLOCAL 2>stderr || { cat stderr >&2; Exit 1; }
+cat stderr >&2
+grep '^aclocal:.*found macro.*AM_EXTRA_ACLOCAL_FLAGS' stderr
+test ! -r aclocal.m4
+rm -f stderr
+
+mkdir m4
+# deliberately underquoted definition
+echo 'AC_DEFUN(FOOBAR, foo)' > m4/foo.m4
+
+clean_cache
+prepare_input '-Werror -I m4'
+$ACLOCAL 2>stderr && { cat stderr >&2; Exit 1; }
+cat stderr >&2
+grep 'underquoted definition.*FOOBAR' stderr
+
+clean_cache
+prepare_input '-Wno-syntax -I m4'
+$ACLOCAL 2>stderr || { cat stderr >&2; Exit 1; }
+cat stderr >&2
+test ! -s stderr
+
+:
diff --git a/tests/aclocalflags-options-with-args.test 
b/tests/aclocalflags-options-with-args.test
new file mode 100755
index 0000000..accdc51
--- /dev/null
+++ b/tests/aclocalflags-options-with-args.test
@@ -0,0 +1,48 @@
+#! /bin/sh
+# Copyright (C) 2010 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 aclocal flags with arguments can be specified in
+# AM_EXTRA_ACLOCAL_FLAGS, as either "-x arg", "-xarg", "--opt arg",
+# or "--opt=arg".
+
+. ./defs || Exit 1
+
+set -e
+
+mkdir m4
+cat > m4/foo.m4 <<'END'
+AC_DEFUN([FOO_MACRO], [:])
+END
+
+for opt_arg_short in '-I m4' '-Im4'; do
+  for opt_arg_long in '--output quux.m4' '--output=quux.m4'; do
+    rm -rf autom4te*.cache *.m4
+    # The AC_INIT call is required by older autoconf (< 2.64)
+    cat > configure.in <<END
+AC_INIT([$me], [1.0])
+AM_EXTRA_ACLOCAL_FLAGS([$opt_arg_short $opt_arg_long])
+FOO_MACRO
+END
+    $ACLOCAL
+    ls -l # for debugging
+    cat quux.m4
+    grep  '^#.*generated.*by aclocal' quux.m4
+    $FGREP 'm4_include([m4/foo.m4])' quux.m4
+    test ! -r aclocal.m4
+  done
+done
+
+:
diff --git a/tests/aclocalflags-rebuild.test b/tests/aclocalflags-rebuild.test
new file mode 100755
index 0000000..1dafd9d
--- /dev/null
+++ b/tests/aclocalflags-rebuild.test
@@ -0,0 +1,215 @@
+#! /bin/sh
+# Copyright (C) 2010 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/>.
+
+# Test interaction among AM_EXTRA_ACLOCAL_FLAGS, AC_CONFIG_MACRO_DIR,
+# AM_RESET_ACLOCAL_FLAGS, and rebuild rules.  This test is quite heavy
+# and complex, because we want to test for many possible usages, and
+# also some corner cases.
+
+. ./defs || Exit 1
+
+set -e
+
+update_configure_in()
+{
+  sed "s|.* dnl:EDIT-THIS|$1 dnl:EDIT-THIS|" configure.in > t
+  mv -f t configure.in
+}
+
+distdir=$me-1.0
+
+mkdir dummy
+cat > dummy/file.m4 <<'END'
+AC_DEFUN([MY_MACRO], [:])
+AC_DEFUN([MY_DISTCLEANFILES], [])
+END
+
+cat >> configure.in <<END
+AM_EXTRA_ACLOCAL_FLAGS([--output=quux.m4]) dnl:EDIT-THIS
+MY_MACRO || { exit 1; (exit 1); }
+AC_SUBST([extra_distcleanfiles], [MY_DISTCLEANFILES])
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+DISTCLEANFILES = $(extra_distcleanfiles)
+END
+
+$ACLOCAL -I dummy
+ls -l
+grep  '^#.*generated.*by aclocal' quux.m4
+test ! -r aclocal.m4
+mv quux.m4 aclocal.m4
+
+$AUTOCONF
+$AUTOMAKE
+
+$FGREP MY_MACRO configure && Exit 1
+
+./configure
+$MAKE
+
+$sleep
+
+mkdir dir1
+cat > dir1/macro.m4 <<'END'
+AC_DEFUN([MY_MACRO], [: > foo])
+END
+cat > dir1/clean.m4 <<'END'
+AC_DEFUN([MY_DISTCLEANFILES], [foo])
+END
+
+update_configure_in 'AM_EXTRA_ACLOCAL_FLAGS([-I dir1])'
+
+$MAKE Makefile
+ls -l
+$FGREP MY_MACRO configure && Exit 1
+grep  '^#.*generated.*by aclocal' aclocal.m4
+test ! -r quux.m4 # output file is no more quux.m4
+test -f foo
+$MAKE distcheck
+rm -rf foo dir1
+
+$sleep
+
+mkdir dir2
+cat > dir2/bar.m4 <<'END'
+AC_DEFUN([MY_MACRO], [echo bar-bar-bar > bar])
+AC_DEFUN([MY_DISTCLEANFILES], [bar])
+END
+
+update_configure_in 'AM_EXTRA_ACLOCAL_FLAGS([-I dir2 --verbose])'
+
+$MAKE Makefile >output 2>&1 || { cat output; Exit 1; }
+cat output
+ls -l
+$FGREP MY_MACRO configure && Exit 1
+# aclocal is verbose
+grep '^aclocal:.*found macro.*MY_MACRO.*dir2/bar\.m4' output
+$FGREP bar-bar-bar configure
+test -f bar
+test ! -r foo
+$MAKE distcheck
+rm -rf bar dir2
+
+$sleep
+
+mkdir dir3
+cat > dir3/1.m4 <<'END'
+AC_DEFUN([MY_MACRO], [AC_SUBST([MY_VAR], [G_R_E_P_M_E]):])
+END
+cat > dir3/2.m4 <<'END'
+AC_DEFUN([MY_DISTCLEANFILES], [])
+END
+
+update_configure_in 'AC_CONFIG_MACRO_DIR([dir3])'
+
+$MAKE Makefile >output 2>&1 || { cat output; Exit 1; }
+cat output
+ls -l
+$FGREP MY_MACRO configure && Exit 1
+$FGREP aclocal: output && Exit 1 # aclocal shouldn't be verbose anymore
+$FGREP bar-bar-bar configure && Exit 1
+test ! -r bar
+$FGREP G_R_E_P_M_E Makefile
+$MAKE distcheck
+
+rm -rf dir3
+
+$sleep
+
+update_configure_in 'm4_include([zardoz.m4])'
+echo 'm4_include([dummy/file.m4])' > zardoz.m4
+
+$MAKE Makefile
+$FGREP MY_MACRO configure && Exit 1
+$FGREP G_R_E_P_M_E Makefile && Exit 1
+$MAKE distcheck
+
+$sleep
+
+# NOTE: The following checks rely on the file `$(top_srcdir)/m4/dirlist'.
+
+# Used by the wrapper script around aclocal.
+ACLOCAL_TESTSUITE_FLAGS='-I m4'
+export ACLOCAL_TESTSUITE_FLAGS
+
+mkdir m4 dirlist-test dir4 dir5
+
+# Yes, these really are meant to be "dir4/a.m4" and "dir5/a.m4".
+cat > dir4/a.m4 <<'END'
+AC_DEFUN([MY_MACRO], [AC_SUBST([MY_VAR], [g-r-e-p-m-e]) : > baz])
+END
+cat > dir5/a.m4 <<'END'
+AC_DEFUN([MY_DISTCLEANFILES], [baz])
+END
+
+cat > dirlist-test/foobar.m4 <<'END'
+AC_DEFUN([FOO_BAR], [:])
+END
+
+cat > zardoz.m4 <<'END'
+AC_CONFIG_MACRO_DIR([dir4])
+AM_EXTRA_ACLOCAL_FLAGS([-I dir5 --install])
+FOO_BAR
+END
+
+$MAKE Makefile
+ls -l
+$FGREP MY_MACRO configure && Exit 1
+
+$FGREP g-r-e-p-m-e Makefile
+test -f baz
+
+# m4/foobar.m4 should be m4_included, not injected by content
+$FGREP FOO_BAR aclocal.m4 && Exit 1
+$FGREP 'm4_include([m4/foobar.m4])' aclocal.m4
+diff dirlist-test/foobar.m4 m4/foobar.m4
+
+$MAKE distdir
+ls -l $distdir/*
+# all files included directly or indirectly by configure.in
+# should be distributed
+test -f $distdir/zardoz.m4
+test -f $distdir/m4/foobar.m4
+test -f $distdir/dir4/a.m4
+test -f $distdir/dir5/a.m4
+
+$MAKE distcheck
+
+unset ACLOCAL_TESTSUITE_FLAGS
+rm -rf baz dir4 dir5 m4 dirlist-test
+
+$sleep
+
+cat >> configure.in <<'END'
+AM_RESET_ACLOCAL_FLAGS
+END
+
+sed 's/^FOO_BAR/MY_MACRO () { : > my-file; }/' zardoz.m4 > t
+echo 'm4_define([MY_DISTCLEANFILES], [my-file])' >> t
+mv -f t zardoz.m4
+
+$MAKE Makefile
+ls -l
+test -f my-file
+$FGREP g-r-e-p-m-e Makefile && Exit 1
+$FGREP MY_MACRO configure
+test `$FGREP -c MY_MACRO configure` -eq 2
+
+$MAKE distcheck
+
+:
diff --git a/tests/aclocalflags-reset.test b/tests/aclocalflags-reset.test
new file mode 100755
index 0000000..6905616
--- /dev/null
+++ b/tests/aclocalflags-reset.test
@@ -0,0 +1,63 @@
+#! /bin/sh
+# Copyright (C) 2010 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 if AM_RESET_ACLOCAL_FLAGS clobbers the flags defined through
+# previous calls to AM_EXTRA_ACLOCAL_FLAGS and AC_CONFIG_MACRO_DIR, but
+# not flags defined through following calls to those same macros.
+
+. ./defs || Exit 1
+
+set -e
+
+mkdir dir1 dir2
+
+cat > dir1/a.m4 <<END
+AC_DEFUN([MY_FOO_MACRO], [__foo-expansion__])
+END
+
+cat > dir2/b.m4 <<END
+AC_DEFUN([MY_BAR_MACRO], [__bar-expansion__])
+END
+
+cat > configure.stub <<END
+AC_INIT([$me], [1.0])
+dnl:EARLY call to AM_RESET_ACLOCAL_FLAGS
+AC_CONFIG_MACRO_DIR([dir1])
+AM_EXTRA_ACLOCAL_FLAGS([-I dir2])
+MY_FOO_MACRO
+MY_BAR_MACRO
+dnl:LATE call to AM_RESET_ACLOCAL_FLAGS
+END
+
+sed 's/^dnl:EARLY.*/AM_RESET_ACLOCAL_FLAGS/' configure.stub > configure.in
+$ACLOCAL
+$AUTOCONF
+$FGREP MY_FOO_MACRO configure && Exit 1
+$FGREP MY_BAR_MACRO configure && Exit 1
+$FGREP __foo-expansion__ configure
+$FGREP __bar-expansion__ configure
+
+rm -rf autom4te*.cache
+
+sed 's/^dnl:LATE.*/AM_RESET_ACLOCAL_FLAGS/' configure.stub > configure.in
+$ACLOCAL
+$AUTOCONF
+$FGREP MY_FOO_MACRO configure
+$FGREP MY_BAR_MACRO configure
+$FGREP __foo-expansion__ configure && Exit 1
+$FGREP __bar-expansion__ configure && Exit 1
+
+:
diff --git a/tests/aclocalflags-whitespaces.test 
b/tests/aclocalflags-whitespaces.test
new file mode 100755
index 0000000..ba5bcb3
--- /dev/null
+++ b/tests/aclocalflags-whitespaces.test
@@ -0,0 +1,36 @@
+#! /bin/sh
+# Copyright (C) 2010 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 AM_EXTRA_ACLOCAL_FLAGS can cope with extra white spaces
+# (and tabs, newlines, backslash-escaped newlines...).
+
+. ./defs || Exit 1
+
+set -e
+
+tab='  '
+cat >> configure.in <<END
+AM_EXTRA_ACLOCAL_FLAGS([${tab} -I \
+${tab}foo-macro-dir  ${tab}
+    --verbose\
+])
+AM_EXTRA_ACLOCAL_FLAGS([  -I${tab}bar-macro-dir
+--output=quux.m4 \
+$tab
+ ])
+END
+
+. "$testsrcdir"/aclocalflags-advanced.sh
diff --git a/tests/aclocalflags.test b/tests/aclocalflags.test
new file mode 100755
index 0000000..2f1e75d
--- /dev/null
+++ b/tests/aclocalflags.test
@@ -0,0 +1,81 @@
+#! /bin/sh
+# Copyright (C) 2010 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 AM_EXTRA_ACLOCAL_FLAGS can extend the list of aclocal
+# options derived from earlier calls to AC_CONFIG_MACRO_DIR and
+# AM_EXTRA_ACLOCAL_FLAGS itself.
+
+. ./defs || Exit 1
+
+set -e
+
+cat >> configure.in <<'END'
+AC_CONFIG_MACRO_DIR([foo-macro-dir])
+AM_EXTRA_ACLOCAL_FLAGS([-I bar-macro-dir --output=quux.m4])
+FOO_MACRO || { (exit 1); exit 1; }
+BAR_MACRO || { (exit 1); exit 1; }
+BAZ_MACRO || { (exit 1); exit 1; }
+AC_OUTPUT
+# This should work also when placed after AC_OUTPUT.
+AM_EXTRA_ACLOCAL_FLAGS([-I baz-macro-dir])
+END
+
+cat > Makefile.am <<'END'
+.PHONY: test
+test:
+       : aclocal must generate quux.m4
+       sed 20q $(top_srcdir)/quux.m4
+       grep '^#.*generated.*by aclocal' $(top_srcdir)/quux.m4
+       : aclocal must not touch aclocal.m4
+       cat $(top_srcdir)/aclocal.m4
+       grep '^m4_include(\[quux\.m4\])$$' $(top_srcdir)/aclocal.m4
+       test `wc -l <$(top_srcdir)/aclocal.m4` -eq 1
+       : configure must create these files
+       test -f foo
+       test -f bar
+       test -f baz
+check-local: test
+DISTCLEANFILES = foo bar baz
+END
+
+cat > aclocal.m4 <<'END'
+m4_include([quux.m4])
+END
+
+mkdir foo-macro-dir bar-macro-dir baz-macro-dir
+
+cat > foo-macro-dir/foo.m4 <<'END'
+AC_DEFUN([FOO_MACRO], [: > foo])
+END
+
+cat > bar-macro-dir/bar.m4 <<'END'
+AC_DEFUN([BAR_MACRO], [: > bar])
+END
+
+cat > baz-macro-dir/baz.m4 <<'END'
+AC_DEFUN([BAZ_MACRO], [: > baz])
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+$MAKE test
+$MAKE distcheck
+
+:
diff --git a/tests/remake10c.test b/tests/remake10c.test
index 96e2c0d..c4cd5de 100755
--- a/tests/remake10c.test
+++ b/tests/remake10c.test
@@ -28,13 +28,13 @@ magic2=__MagicStringTwo__
 magic3=%%MagicStringThree%%
 
 cat >> configure.in <<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.
@@ -48,7 +48,7 @@ mkdir m4
 echo 'AC_DEFUN([my_fingerprint], [BadBadBad])' > m4/foo.m4
 
 $sleep # so that generated autotools files will be newer than prerequisites
-$ACLOCAL -I m4
+$ACLOCAL
 $AUTOCONF
 $AUTOMAKE
 
diff --git a/tests/remake8a.test b/tests/remake8a.test
index 9e66540..913b59a 100755
--- a/tests/remake8a.test
+++ b/tests/remake8a.test
@@ -112,15 +112,16 @@ $MAKE distcheck
 
 rm -f quux
 
-# Modify Makefile.am to add a directory of extra m4 files
-# considered by aclocal.
+# Modify configure.in 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
@@ -128,14 +129,8 @@ check-local:
        test x'$(QUUX)' = x'%Foo%'
 END
 
-$MAKE # this should place aclocal flags in Makefile
-grep '.*-I m4' Makefile # sanity check
-
-# Modify configure.in and aclocal.m4.
-
-$sleep
-
 cat $srcdir/configure.stub - > $srcdir/configure.in <<'END'
+AC_CONFIG_MACRO_DIR([m4])
 AC_CONFIG_FILES([quux])
 MY_CUSTOM_MACRO
 AC_OUTPUT
diff --git a/tests/remake8b.test b/tests/remake8b.test
index 3773aac..9597377 100755
--- a/tests/remake8b.test
+++ b/tests/remake8b.test
@@ -114,15 +114,16 @@ $MAKE distcheck
 
 rm -f quux
 
-# Modify Makefile.am to add a directory of extra m4 files
-# considered by aclocal.
+# Modify configure.in 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
@@ -130,14 +131,8 @@ check-local:
        test x'$(QUUX)' = x'%Foo%'
 END
 
-$MAKE # this should place aclocal flags in Makefile
-grep '.*-I m4' Makefile # sanity check
-
-# Modify configure.in and aclocal.m4.
-
-$sleep
-
 cat $srcdir/configure.stub - > $srcdir/configure.in <<'END'
+AC_CONFIG_MACRO_DIR([m4])
 AC_CONFIG_FILES([quux])
 MY_CUSTOM_MACRO
 AC_OUTPUT
diff --git a/tests/subdir8.test b/tests/subdir8.test
index 093fac8..e87f0f1 100755
--- a/tests/subdir8.test
+++ b/tests/subdir8.test
@@ -28,6 +28,7 @@ required='GNUmake gcc'
 set -e
 
 cat >> configure.in << 'END'
+AC_CONFIG_MACRO_DIR([m4])
 AC_PROG_CC
 AM_PROG_CC_C_O
 m4_include([confiles.m4])
@@ -39,7 +40,6 @@ echo 'AC_CONFIG_FILES([sub/Makefile])' > confiles.m4
 
 cat > Makefile.am << 'END'
 SUBDIRS = sub
-ACLOCAL_AMFLAGS = -I m4
 END
 
 mkdir sub
@@ -61,7 +61,7 @@ END
 mkdir m4
 echo 'AC_DEFUN([MORE_DEFS], [])' > m4/moredefs.m4
 
-$ACLOCAL -I m4
+$ACLOCAL
 $AUTOCONF
 $AUTOMAKE --copy --add-missing
 ./configure
diff --git a/tests/subpkg.test b/tests/subpkg.test
index 3662937..ef7bbb4 100755
--- a/tests/subpkg.test
+++ b/tests/subpkg.test
@@ -1,5 +1,6 @@
 #! /bin/sh
-# Copyright (C) 2002, 2003, 2004, 2006  Free Software Foundation, Inc.
+# Copyright (C) 2002, 2003, 2004, 2006, 2010 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
@@ -31,6 +32,7 @@ AC_DEFUN([FOO],[
 EOF
 
 cat >>configure.in <<'END'
+AC_CONFIG_MACRO_DIR([m4])
 AC_CONFIG_SUBDIRS([lib])
 FOO
 END
@@ -48,8 +50,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'
@@ -68,6 +68,7 @@ mkdir lib/src
 cat >lib/configure.ac <<'EOF'
 AC_INIT([lib], [2.3])
 AM_INIT_AUTOMAKE
+AC_CONFIG_MACRO_DIR([../m4])
 AC_PROG_RANLIB
 AC_PROG_YACC
 AC_CONFIG_HEADERS([config.h:config.hin])
@@ -86,8 +87,6 @@ dist-hook:
        test -f $(distdir)/src/x.c
        test ! -f $(top_distdir)/src/x.c
        test -f $(YLWRAP)
-
-ACLOCAL_AMFLAGS = -I ../m4
 EOF
 
 cat > lib/foo.y << 'END'
@@ -109,12 +108,12 @@ int lib ()
 }
 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
@@ -126,3 +125,5 @@ $MAKE
 $MAKE distcheck
 test ! -d subpack-1            # make sure distcheck cleans up after itself
 test -f subpack-1.tar.gz
+
+:
diff --git a/tests/subpkg2.test b/tests/subpkg2.test
index ebbc69b..196f105 100755
--- a/tests/subpkg2.test
+++ b/tests/subpkg2.test
@@ -30,6 +30,7 @@ AC_DEFUN([FOO],[
 EOF
 
 cat >>configure.in <<'END'
+AC_CONFIG_MACRO_DIR([m4])
 AC_CONFIG_SUBDIRS([sub])
 AC_OUTPUT
 END
@@ -45,20 +46,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
@@ -66,3 +68,5 @@ cd ..
 
 ./configure
 $MAKE distcheck
+
+:
-- 
1.7.2.3


reply via email to

[Prev in Thread] Current Thread [Next in Thread]