automake
[Top][All Lists]
Advanced

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

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


From: Stefano Lattarini
Subject: [PATCH] Trace macros for aclocal options, deprecate ACLOCAL_AMFLAGS.
Date: Mon, 11 Oct 2010 17:49:45 +0200
User-agent: KMail/1.13.3 (Linux/2.6.30-2-686; KDE/4.4.4; i686; ; )

Hello automakers

This is a follow-up from threads "need to set ACLOCAL_AMFLAGS along
with AC_CONFIG_MACRO_DIR":
 <http://lists.gnu.org/archive/html/bug-autoconf/2010-09/msg00027.html>
 <http://lists.gnu.org/archive/html/bug-automake/2010-09/msg00029.html>

On Tuesday 05 October 2010, Stefano Lattarini wrote:
> Hello autoconfers and automakers.
> 
> I have two modest proposals about the issues discussed here.
> Not sure if they really make sense, though, so criticism is
> welcome.
> 
> On Wednesday 15 September 2010, Ralf Wildenhues wrote:
> > * Eric Blake wrote on Wed, Sep 15, 2010 at 10:11:17PM CEST:
> > > At any rate, it seems like maintaining ACLOCAL_AMFLAGS in
> > > Makefile.am is redundant
> > 
> > For simple setups, yes.  How common are non-simple setups?  I don't
> > know for sure, but I would guess any package with more than a
> > couple of configure scripts might need more than one m4 directory.
> >  The GCC and src trees have complex such setups at least. 

> [Proposal 1]
> 
> We can add a new `EXTRA_ACLOCAL_AMFLAGS' special variable for
> Makefile.am, whose value is to be *appended* to the automatically
> computed ACLOCAL_FLAGS from AC_CONFIG_MACRO_DIR.  I have prepared
> some test cases to show the behaviour I'd expect from such feature
> (see attachements).
Thinking again, this would still require autoreconf to grep Makefile.am,
which is a bad idea.  In fact, the autotools has moved consistently 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.  So...

> [Proposal 2]
> 
> We can to add a new autoconf macro (say `AM_EXTRA_ACLOCAL_FLAGS')
> which aclocal and automake would trace to fetch extra flags for
> aclocal runs (I think this would require the addition, for
> consistency, of a configure.ac counterpart for Makefile.am
> `ACLOCAL_AMFLAGS' -- maybe `AM_ACLOCAL_FLAGS'?).
... I've implemented this proposal instead (see attached patch, based
off maint).  *The testsuite still passes*.  Oh, and BTW, the addition
of AM_ACLOCAL_FLAGS turned out to be a good idea (IMHO not just for
consistency reasons).

Currently, setting of ACLOCAL_AMFLAGS in Makefile.am is still supported,
for backwards-compatibility reasons; no extra code was required to keep
this compatibility.

Also, even older autoreconf should work OOTB with the new way to set
aclocal flags (assuming that the aclocal they use is modern enough,
obviously).

This lefts only one open question: should we warn if the obsolescent
ACLOCAL_AMFLAGS is used?  Or should we just document that it is
deprecated?  A warning would be clearer and more consistent IMO, but
it might create problems for packages that insist to be compatible
with older autotools versions.  At the moment, I've *not* yet added
such a warning.  But I still think we should add it in the end.

These are the limits/TODOs of the attached patch:

  1. Documentation and NEWS entry are still missing.

  2. The error messages displayed in case of invalid options specified
     in AM_ACLOCAL_FLAGS or AM_EXTRA_ACLOCAL_FLAGS still miss indication
     of "FILE:LINENO"; this might be fixed in a follow-up patch IMHO.

> If we follow this second route, we could deprecate the user setting
> of `ACLOCAL_AMFLAGS' in Makefile.am starting from Automake 1.12,
> and remove support for it in Automake 1.13 (this is probably whishful
> thinking, though).
As noted before, whether we should do this is still an open question.

> [Ralf Wildenhues]
> > And there might be the odd package where you may *not* want the
> > macro directory automatically included in aclocal -I flags.  Or,
> > not at that position in the command line.
>
> [Stefano Lattarini]
> This could be done in various ways:
>   a. A new configure.ac macro akin to `AM_SUBST_NOTMAKE' (this could
>      work for both proposals [1] and [2] above).
>   b. A new automake option `no-auto-aclocal-flags' (this also could
>      work for both proposals [1] and [2] above).
>   c. If we go with proposal [2], a definition of special variable
>      `ACLOCAL_AMFLAGS' could simply override the default value that
>      would be have been computed from the call to the macro 
>      `AC_CONFIG_MACRO_DIR'
>   d. If we go with proposal [2], a call to macro `AM_ACLOCAL_FLAGS'
>      could simply override the default value that would be have been
>      computed from the call to macro `AC_CONFIG_MACRO_DIR'.
In the attached patch, I've gone for (d).  Simpler and more consistent.
  
> > > - how hard is it to teach automake to have aclocal _automatically_
> > >   include directories mentioned inside AC_CONFIG_MACRO_DIR, to 
> > >   avoid the dual file maintenance headache?
> > 
> > Probably not hard.  But duplication exists to also allow complex
> > things, and not make them impossible.
> Unless I'm missing something fundamental, the proposals above would
> remove the need of duplication, while preserving the possibility of
> having more complex setups.
This should still hold.  Please correct me if I'm wrong!
  
> > How common are packages with not all Makefile.in files generated by
> > automake?  More than a few, I'd say, so users need to both adjust
> > SUBDIRS and AC_CONFIG_FILES.  Also, it's really helpful for turning
> > a package to (or from) automake file by file.
> 
> > Likewise, merging two packages can be easier when ACLOCAL_AMFLAGS
> > can point to both packages' m4 directories during the process.
> This could be easily done with macro AM_ACLOCAL_FLAGS too, right?
Ditto.

-*-*-*-

Opinions and comments are welcome.

Regards,
   Stefano
From db567d3689065394f3b0df9c539d8b6f43a440c4 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.

---
 ChangeLog                           |   76 +++++++++++++++++++++
 aclocal.in                          |   80 +++++++++++++++++++----
 m4/Makefile.am                      |    1 +
 m4/Makefile.in                      |    1 +
 m4/aclocal-flags.m4                 |   34 ++++++++++
 tests/.gitignore                    |    4 +-
 tests/Makefile.am                   |   25 +++++++
 tests/Makefile.in                   |   25 +++++++
 tests/acloca14.test                 |    2 +-
 tests/acloca14b.test                |  123 +++++++++++++++++++++++++++++++++++
 tests/acloca22.test                 |   19 ++++--
 tests/acloca22b.test                |   51 ++++++++++++++
 tests/aclocal-amflags.test          |   71 ++++++++++++++++++++
 tests/aclocalflags-acdir.test       |   43 ++++++++++++
 tests/aclocalflags-empty.test       |   34 ++++++++++
 tests/aclocalflags-extra1.test      |   60 +++++++++++++++++
 tests/aclocalflags-extra2.test      |   60 +++++++++++++++++
 tests/aclocalflags-extra3.test      |   51 ++++++++++++++
 tests/aclocalflags-extra4.test      |   51 ++++++++++++++
 tests/aclocalflags-inst.test        |   55 ++++++++++++++++
 tests/aclocalflags-invalid.test     |   56 ++++++++++++++++
 tests/aclocalflags-macrodir.test    |   67 +++++++++++++++++++
 tests/aclocalflags-moreopts.test    |  100 ++++++++++++++++++++++++++++
 tests/aclocalflags-multi.test       |   33 +++++++++
 tests/aclocalflags-noam.test        |   59 +++++++++++++++++
 tests/aclocalflags-override1.test   |   61 +++++++++++++++++
 tests/aclocalflags-override2.test   |   61 +++++++++++++++++
 tests/aclocalflags-precedence1.test |   32 +++++++++
 tests/aclocalflags-precedence2.test |   31 +++++++++
 tests/aclocalflags-precedence3.test |   31 +++++++++
 tests/aclocalflags-rebuild.test     |   86 ++++++++++++++++++++++++
 tests/aclocalflags-simple1.test     |   51 ++++++++++++++
 tests/aclocalflags-simple2.test     |   51 ++++++++++++++
 tests/aclocalflags-whitespaces.test |   64 ++++++++++++++++++
 tests/subpkg.test                   |   15 ++--
 tests/subpkg2.test                  |   10 ++-
 36 files changed, 1644 insertions(+), 30 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 100755 tests/aclocalflags-empty.test
 create mode 100755 tests/aclocalflags-extra1.test
 create mode 100755 tests/aclocalflags-extra2.test
 create mode 100755 tests/aclocalflags-extra3.test
 create mode 100755 tests/aclocalflags-extra4.test
 create mode 100755 tests/aclocalflags-inst.test
 create mode 100755 tests/aclocalflags-invalid.test
 create mode 100755 tests/aclocalflags-macrodir.test
 create mode 100755 tests/aclocalflags-moreopts.test
 create mode 100755 tests/aclocalflags-multi.test
 create mode 100755 tests/aclocalflags-noam.test
 create mode 100755 tests/aclocalflags-override1.test
 create mode 100755 tests/aclocalflags-override2.test
 create mode 100755 tests/aclocalflags-precedence1.test
 create mode 100755 tests/aclocalflags-precedence2.test
 create mode 100755 tests/aclocalflags-precedence3.test
 create mode 100755 tests/aclocalflags-rebuild.test
 create mode 100755 tests/aclocalflags-simple1.test
 create mode 100755 tests/aclocalflags-simple2.test
 create mode 100755 tests/aclocalflags-whitespaces.test

diff --git a/ChangeLog b/ChangeLog
index 7883d5e..61b4fa7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,79 @@
+2010-10-11  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 (which 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 not using autoreconf, the developer
+       is forced to add *by hand* the flags specified by ACLOCAL_AMFLAGS
+       to the the aclocal calls not triggered by make rebuild rules --
+       again more duplication and more chances for errors.
+       Thus we now make aclocal trace some more macros, so that it can
+       automatically find out extra flags from calls to those macros --
+       for example, a call too AC_CONFIG_MACRO_DIR([foodir]) will cause
+       aclocal to add `-I foodir' to its flags.
+       We also define two new maros, `AM_EXTRA_ACLOCAL_FLAGS' and
+       `AM_ACLOCAL_FLAGS', whose only purpose is to allow setting of
+       arbitrary aclocal flags in configure.ac.
+       * NEWS: TODO!
+       * doc/automake.texi: TODO!
+       * aclocal.in: Implement processing of extra flags derived from
+       macro calls.
+       (@aclocal_flagd): New global variable.
+       (trace_used_macros): Also trace macros `AC_CONFIG_MACRO_DIR',
+       `_AM_ACLOCAL_FLAGS' and `_AM_EXTRA_ACLOCAL_FLAGS'.  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, contain definitions of public
+       macros `AM_ACLOCAL_FLAGS' and `AM_EXTRA_ACLOCAL_FLAGS', and of
+       private macros `_AM_ACLOCAL_FLAGS' and `_AM_EXTRA_ACLOCAL_FLAGS'.
+       * 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/acloca14.test: Likewise.
+       * tests/acloca22.test: Likewise.
+       * tests/acloca14b.test: New test, identical to the previous
+       version of `acloca14.test'; it is kept to verify backwards
+       compatibility.
+       * tests/acloca22b.test: New test, identical to the previous
+       version of `acloca22.test', it is kept to verify backwards
+       compatibility.
+       * tests/aclocal-amflags.test: New test, check for backwards
+       compatibility that ACLOCAL_AMFLAGS still works.
+       * tests/aclocalflags-empty.test: New test.
+       * tests/aclocalflags-extra1.test: Likewise.
+       * tests/aclocalflags-extra2.test: Likewise.
+       * tests/aclocalflags-extra3.test: Likewise.
+       * tests/aclocalflags-extra4.test: Likewise.
+       * tests/aclocalflags-inst.test: Likewise.
+       * tests/aclocalflags-invalid.test: Likewise.
+       * tests/aclocalflags-macrodir.test: Likewise.
+       * tests/aclocalflags-moreopts.test: Likewise.
+       * tests/aclocalflags-multi.test: Likewise.
+       * tests/aclocalflags-noam.test: Likewise.
+       * tests/aclocalflags-override1.test: Likewise.
+       * tests/aclocalflags-override2.test: Likewise.
+       * tests/aclocalflags-precedence1.test: Likewise.
+       * tests/aclocalflags-precedence2.test: Likewise.
+       * tests/aclocalflags-precedence3.test: Likewise.
+       * tests/aclocalflags-rebuild.test: Likewise.
+       * tests/aclocalflags-simple1.test: Likewise.
+       * tests/aclocalflags-simple2.test: Likewise.
+       * tests/aclocalflags-whitespaces.test: Likewise.
+       * tests/aclocalflags-acdir.test: New test, xfailing due to
+       a testsuite weakness.
+       * tests/Makefile.am (TESTS, XFAIL_TESTS): Updated.
+       * tests/.gitignore: Updated.
+
 2010-10-04  Stefano Lattarini  <address@hidden>
 
        Add support for newer python versions.
diff --git a/aclocal.in b/aclocal.in
index b5c2c41..5fe00d6 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;
 
@@ -668,13 +671,17 @@ 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',
+                    '_AM_ACLOCAL_FLAGS',
+                    '_AM_EXTRA_ACLOCAL_FLAGS' ,
+                    '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).
@@ -684,6 +691,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)
@@ -693,14 +708,36 @@ 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');
+      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_ACLOCAL_FLAGS')
+        {
+          @aclocal_flags = split (' ', $arg1);
+        }
+    }
 
-      $ac_version = $arg1 if $macro eq '_AM_AUTOCONF_VERSION';
+  if (defined $ac_config_macro_dir && address@hidden)
+    {
+      @aclocal_flags = ('-I', $ac_config_macro_dir);
     }
 
+  push @aclocal_flags, @extra_aclocal_flags;
+
   $tracefh->close;
 
   return %traced;
@@ -922,8 +959,9 @@ EOF
 }
 
 # Parse command line.
-sub parse_arguments ()
+sub parse_arguments (@)
 {
+  local @ARGV = @_;
   my $print_and_exit = 0;
   my $diff_command;
 
@@ -1014,7 +1052,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
@@ -1026,7 +1067,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>)
@@ -1049,7 +1090,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
@@ -1060,16 +1102,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/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 270ee91..7cdc7ba 100644
--- a/m4/Makefile.in
+++ b/m4/Makefile.in
@@ -185,6 +185,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..80bcfc0
--- /dev/null
+++ b/m4/aclocal-flags.m4
@@ -0,0 +1,34 @@
+# 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_ACLOCAL_FLAGS([FLAGS])
+# -------------------------
+# Define flags for aclocal, in addition to those specified on the
+# command line.  This macro is here only to be traced by aclocal,
+# which doesn't like newlines in the macros' arguments, so flatten
+# them.
+AC_DEFUN([AM_ACLOCAL_FLAGS],
+         [_AM_ACLOCAL_FLAGS(m4_flatten([$1]))])
+
+# AM_EXTRA_ACLOCAL_FLAGS([FLAGS])
+# -------------------------
+# Define flags for aclocal, in addition to those specified on the
+# command line, with AM_ACLOCAL_FLAGS, orerived by other macros
+# (e.g. AC_CONFIG_MACRO_DIR).  This macro is here only to be traced
+# by aclocal, which doesn't like newlines in the macros' arguments,
+# so flatten them.
+AC_DEFUN([AM_EXTRA_ACLOCAL_FLAGS],
+         [_AM_EXTRA_ACLOCAL_FLAGS(m4_flatten([$1]))])
+
+# aclocal traces these macro to find the aclocal flags.  These are
+# private macro.  Using m4_define simplifies the logic in aclocal,
+# which can simply ignore this definition.
+m4_define([_AM_ACLOCAL_FLAGS], [])
+m4_define([_AM_EXTRA_ACLOCAL_FLAGS], [])
diff --git a/tests/.gitignore b/tests/.gitignore
index 3c1f990..5e97c89 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -1,5 +1,5 @@
-aclocal-*
-automake-*
+aclocal-1.*
+automake-1.*
 defs
 parallel-tests.am
 *.dir
diff --git a/tests/Makefile.am b/tests/Makefile.am
index acc7640..aa11f18 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -17,6 +17,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 XFAIL_TESTS = \
+aclocalflags-acdir.test \
 all.test \
 auxdir2.test \
 cond17.test \
@@ -51,6 +52,7 @@ acloca11.test \
 acloca12.test \
 acloca13.test \
 acloca14.test \
+acloca14b.test \
 acloca15.test \
 acloca16.test \
 acloca17.test \
@@ -59,6 +61,29 @@ acloca19.test \
 acloca20.test \
 acloca21.test \
 acloca22.test \
+acloca22b.test \
+aclocal-amflags.test \
+aclocalflags-acdir.test \
+aclocalflags-empty.test \
+aclocalflags-extra1.test \
+aclocalflags-extra2.test \
+aclocalflags-extra3.test \
+aclocalflags-extra4.test \
+aclocalflags-inst.test \
+aclocalflags-invalid.test \
+aclocalflags-macrodir.test \
+aclocalflags-moreopts.test \
+aclocalflags-multi.test \
+aclocalflags-noam.test \
+aclocalflags-override1.test \
+aclocalflags-override2.test \
+aclocalflags-precedence1.test \
+aclocalflags-precedence2.test \
+aclocalflags-precedence3.test \
+aclocalflags-rebuild.test \
+aclocalflags-simple1.test \
+aclocalflags-simple2.test \
+aclocalflags-whitespaces.test \
 acoutnoq.test \
 acoutpt.test \
 acoutpt2.test \
diff --git a/tests/Makefile.in b/tests/Makefile.in
index 117f2ba..af258f7 100644
--- a/tests/Makefile.in
+++ b/tests/Makefile.in
@@ -273,6 +273,7 @@ top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
 XFAIL_TESTS = \
+aclocalflags-acdir.test \
 all.test \
 auxdir2.test \
 cond17.test \
@@ -318,6 +319,7 @@ acloca11.test \
 acloca12.test \
 acloca13.test \
 acloca14.test \
+acloca14b.test \
 acloca15.test \
 acloca16.test \
 acloca17.test \
@@ -326,6 +328,29 @@ acloca19.test \
 acloca20.test \
 acloca21.test \
 acloca22.test \
+acloca22b.test \
+aclocal-amflags.test \
+aclocalflags-acdir.test \
+aclocalflags-empty.test \
+aclocalflags-extra1.test \
+aclocalflags-extra2.test \
+aclocalflags-extra3.test \
+aclocalflags-extra4.test \
+aclocalflags-inst.test \
+aclocalflags-invalid.test \
+aclocalflags-macrodir.test \
+aclocalflags-moreopts.test \
+aclocalflags-multi.test \
+aclocalflags-noam.test \
+aclocalflags-override1.test \
+aclocalflags-override2.test \
+aclocalflags-precedence1.test \
+aclocalflags-precedence2.test \
+aclocalflags-precedence3.test \
+aclocalflags-rebuild.test \
+aclocalflags-simple1.test \
+aclocalflags-simple2.test \
+aclocalflags-whitespaces.test \
 acoutnoq.test \
 acoutpt.test \
 acoutpt2.test \
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..972381f
--- /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'
+AM_FOO || { exit 1; (exit 1); }
+AC_OUTPUT
+END
+
+mkdir m4_1 m4_2
+cat > m4_1/foo.m4 <<'END'
+AC_DEFUN([AM_FOO], [: > foo])
+END
+cat > m4_2/bar.m4 <<'END'
+AC_DEFUN([AM_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/AM_FOO/AM_BAR/' configure.in > t
+mv -f t configure.in
+
+$MAKE Makefile >output 2>&1 || { cat output; Exit 1; }
+cat output
+grep "^aclocal:.*found macro.*AM_BAR.*m4_2/bar\.m4" output
+grep "^aclocal:.*macro.*AM_FOO" output && Exit 1
+test ! -r foo
+test -f bar
+
+$MAKE distcheck
+
+:
diff --git a/tests/aclocalflags-acdir.test b/tests/aclocalflags-acdir.test
new file mode 100755
index 0000000..3f67f0b
--- /dev/null
+++ b/tests/aclocalflags-acdir.test
@@ -0,0 +1,43 @@
+#! /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 `--acdir' aclocal flag is supported in AM_ACLOCAL_FLAGS
+# AM_EXTRA_ACLOCAL_FLAGS.
+# FIXME: this test 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_ACLOCAL_FLAGS/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
+
+for macro in AM_ACLOCAL_FLAGS AM_EXTRA_ACLOCAL_FLAGS; do
+  echo "$macro([--acdir ./none --acdir=./s-m4]) FOO BAR" > configure.in
+  $ACLOCAL
+  $FGREP '%%-z-a-r-d-o-z-%%' aclocal.m4
+  $FGREP '//~Q~U~U~X~//' aclocal.m4
+  rm -rf aclocal.m4 autom4te*.cache
+done
+
+:
diff --git a/tests/aclocalflags-empty.test b/tests/aclocalflags-empty.test
new file mode 100755
index 0000000..00246d2
--- /dev/null
+++ b/tests/aclocalflags-empty.test
@@ -0,0 +1,34 @@
+#! /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 macros AM_ACLOCAL_FLAGS and
+# AM_EXTRA_ACLOCAL_FLAGS  without arguments.
+
+. ./defs || Exit 1
+
+set -e
+
+for call in \
+  'AM_ACLOCAL_FLAGS' \
+  'AM_ACLOCAL_FLAGS([])' \
+  'AM_EXTRA_ACLOCAL_FLAGS' \
+  'AM_EXTRA_ACLOCAL_FLAGS([])' \
+; do
+  echo "$call" >configure.in
+  $ACLOCAL --force
+done
+
+:
diff --git a/tests/aclocalflags-extra1.test b/tests/aclocalflags-extra1.test
new file mode 100755
index 0000000..1d4b879
--- /dev/null
+++ b/tests/aclocalflags-extra1.test
@@ -0,0 +1,60 @@
+#! /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 support for AM_EXTRA_ACLOCAL_AMFLAGS, when called to extend
+# flags derived from AC_CONFIG_MACRO_DIR.
+# Keep this in sync with sister test `aclocalflags-extra2.test'.
+
+. ./defs || Exit 1
+
+set -e
+
+cat >> configure.in <<'END'
+AC_CONFIG_MACRO_DIR([ac-macro-dir])
+am__AC_MACRO || { (exit 1); exit 1; }
+am__AM_MACRO || { (exit 1); exit 1; }
+dnl: Calls to AM_EXTRA_ACLOCAL_FLAGS should be cumulative.
+AM_EXTRA_ACLOCAL_FLAGS([-I am-macro-dir])
+AM_EXTRA_ACLOCAL_FLAGS([--output=quux.m4])
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+DISTCLEANFILES = foo-ac bar-am
+END
+
+mkdir ac-macro-dir am-macro-dir
+cat > ac-macro-dir/ac-foo.m4 <<'END'
+AC_DEFUN([am__AC_MACRO], [: > foo-ac])
+END
+cat > am-macro-dir/am-bar.m4 <<'END'
+AC_DEFUN([am__AM_MACRO], [: > bar-am])
+END
+
+$ACLOCAL
+grep '^#.*generated.*by aclocal' quux.m4
+test ! -r aclocal.m4
+mv quux.m4 aclocal.m4
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+test -f foo-ac
+test -f bar-am
+
+$MAKE distcheck
+
+:
diff --git a/tests/aclocalflags-extra2.test b/tests/aclocalflags-extra2.test
new file mode 100755
index 0000000..e627b7a
--- /dev/null
+++ b/tests/aclocalflags-extra2.test
@@ -0,0 +1,60 @@
+#! /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 support for AM_EXTRA_ACLOCAL_AMFLAGS, when called to extend
+# flags derived from AC_CONFIG_MACRO_DIR.
+# Keep this in sync with sister test `aclocalflags-extra2.test'.
+
+. ./defs || Exit 1
+
+set -e
+
+cat >> configure.in <<'END'
+AM_ACLOCAL_FLAGS([-I ac-macro-dir])
+am__AC_MACRO || { (exit 1); exit 1; }
+am__AM_MACRO || { (exit 1); exit 1; }
+dnl: Calls to AM_EXTRA_ACLOCAL_FLAGS should be cumulative.
+AM_EXTRA_ACLOCAL_FLAGS([-I am-macro-dir])
+AM_EXTRA_ACLOCAL_FLAGS([--output=quux.m4])
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+DISTCLEANFILES = foo-ac bar-am
+END
+
+mkdir ac-macro-dir am-macro-dir
+cat > ac-macro-dir/ac-foo.m4 <<'END'
+AC_DEFUN([am__AC_MACRO], [: > foo-ac])
+END
+cat > am-macro-dir/am-bar.m4 <<'END'
+AC_DEFUN([am__AM_MACRO], [: > bar-am])
+END
+
+$ACLOCAL
+grep '^#.*generated.*by aclocal' quux.m4
+test ! -r aclocal.m4
+mv quux.m4 aclocal.m4
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+test -f foo-ac
+test -f bar-am
+
+$MAKE distcheck
+
+:
diff --git a/tests/aclocalflags-extra3.test b/tests/aclocalflags-extra3.test
new file mode 100755
index 0000000..eed678b
--- /dev/null
+++ b/tests/aclocalflags-extra3.test
@@ -0,0 +1,51 @@
+#! /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 basic support for AM_EXTRA_ACLOCAL_FLAGS.
+# Keep this in sync with sister tests `aclocal-amflags-simple1.test',
+# `aclocal-amflags-simple2.test' and `aclocal-amflags-extra4.test'.
+
+. ./defs || Exit 1
+
+set -e
+
+cat >> configure.in <<END
+AM_EXTRA_ACLOCAL_FLAGS([--output=foo.m4])
+AC_OUTPUT
+END
+
+cat > aclocal.m4 <<'END'
+m4_include([foo.m4])
+END
+
+cat > Makefile.am <<'END'
+.PHONY: test
+test:
+       grep '^#.*generated.*by aclocal' $(top_srcdir)/foo.m4
+       grep '^m4_include(\[foo\.m4\])$$' $(top_srcdir)/aclocal.m4
+check-local: test
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+$MAKE test
+$MAKE distcheck
+
+:
diff --git a/tests/aclocalflags-extra4.test b/tests/aclocalflags-extra4.test
new file mode 100755
index 0000000..470b790
--- /dev/null
+++ b/tests/aclocalflags-extra4.test
@@ -0,0 +1,51 @@
+#! /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 basic support for AM_EXTRA_ACLOCAL_FLAGS used late.
+# Keep this in sync with sister tests `aclocal-amflags-simple1.test',
+# `aclocal-amflags-simple2.test' and `aclocal-amflags-extra3.test'.
+
+. ./defs || Exit 1
+
+set -e
+
+cat >> configure.in <<END
+AC_OUTPUT
+AM_EXTRA_ACLOCAL_FLAGS([--output=foo.m4])
+END
+
+cat > aclocal.m4 <<'END'
+m4_include([foo.m4])
+END
+
+cat > Makefile.am <<'END'
+.PHONY: test
+test:
+       grep '^#.*generated.*by aclocal' $(top_srcdir)/foo.m4
+       grep '^m4_include(\[foo\.m4\])$$' $(top_srcdir)/aclocal.m4
+check-local: test
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+$MAKE test
+$MAKE distcheck
+
+:
diff --git a/tests/aclocalflags-inst.test b/tests/aclocalflags-inst.test
new file mode 100755
index 0000000..818ba39
--- /dev/null
+++ b/tests/aclocalflags-inst.test
@@ -0,0 +1,55 @@
+#! /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 `--install' aclocal flag is supported in AM_ACLOCAL_FLAGS
+# and AM_EXTRA_ACLOCAL_FLAGS.  These checks are done in this standalone,
+# separate test, because they need a proper hack to work with the aclocal
+# wrapper script used by the testsuite.
+# This test relies on the file `$(top_srcdir)/m4/dirlist'.
+
+. ./defs || Exit 1
+
+set -e
+
+ACLOCAL_TESTSUITE_FLAGS='-I m4'
+export ACLOCAL_TESTSUITE_FLAGS
+
+for macro in AM_ACLOCAL_FLAGS AM_EXTRA_ACLOCAL_FLAGS; do
+
+  mkdir m4 dirlist-test
+  echo 'AC_DEFUN([FOO_BAR], [:])' > dirlist-test/foobar.m4
+  echo "$macro([--install]) AM_WITH_DMALLOC FOO_BAR" > configure.in
+
+  $ACLOCAL --verbose 2>stderr || { cat stderr >&2; Exit 1; }
+  cat stderr >&2
+
+  # dmalloc.m4 should be injected by contents, not m4_included
+  $FGREP 'AM_WITH_DMALLOC' aclocal.m4
+  test ! -r m4/dmalloc.m4
+
+  # m4/foobar.m4 should be m4_included, not injected by contents
+  $FGREP 'FOO_BAR' aclocal.m4 && Exit 1
+  $FGREP '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
+
+  rm -rf m4 dirlist-test
+
+done
+
+:
diff --git a/tests/aclocalflags-invalid.test b/tests/aclocalflags-invalid.test
new file mode 100755
index 0000000..364c859
--- /dev/null
+++ b/tests/aclocalflags-invalid.test
@@ -0,0 +1,56 @@
+#! /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 in AM_ACLOCAL_AMFLAGS and
+# AM_EXTRA_ACLOCAL_AMFLAGS are diagnosed.
+
+. ./defs || Exit 1
+
+set -e
+
+for macro in AM_ACLOCAL_FLAGS AM_EXTRA_ACLOCAL_FLAGS; do
+
+  rm -rf autom4te*.cache
+  echo "$macro([--foobar])" > configure.in
+  $ACLOCAL 2>stderr && { cat stderr >&2; Exit 1; }
+  cat stderr >&2
+  grep 'option.*--foobar' stderr
+  test ! -r aclocal.m4
+
+  rm -rf autom4te*.cache
+  echo "$macro([foobar])" > configure.in
+  $ACLOCAL 2>stderr && { cat stderr >&2; Exit 1; }
+  cat stderr >&2
+  grep 'option.*[^-]foobar' stderr
+  test ! -r aclocal.m4
+
+  rm -rf autom4te*.cache
+  echo "$macro([-I])" > configure.in
+  $ACLOCAL 2>stderr && { cat stderr >&2; Exit 1; }
+  cat stderr >&2
+  grep 'option.*-I.*argument' stderr
+  test ! -r aclocal.m4
+  
+  rm -rf autom4te*.cache
+  echo "$macro([--output])" > configure.in
+  $ACLOCAL 2>stderr && { cat stderr >&2; Exit 1; }
+  cat stderr >&2
+  grep 'option.*--output.*argument' stderr
+  test ! -r aclocal.m4
+
+done
+
+:
diff --git a/tests/aclocalflags-macrodir.test b/tests/aclocalflags-macrodir.test
new file mode 100755
index 0000000..b491834
--- /dev/null
+++ b/tests/aclocalflags-macrodir.test
@@ -0,0 +1,67 @@
+#! /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])
+am__FOO || { (exit 1); exit 1; }
+AC_OUTPUT
+END
+
+: > Makefile.am
+
+mkdir macro-dir
+cat > macro-dir/foo.m4 <<'END'
+AC_DEFUN([am__FOO], [: > bar])
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+test -f bar
+rm -f bar
+
+$sleep
+
+cat > macro-dir/foo.m4 <<'END'
+AC_DEFUN([am__FOO], [: > quux])
+END
+
+$MAKE Makefile
+test -f quux
+test ! -r bar
+
+$sleep
+
+cat > macro-dir/foo.m4 <<'END'
+AC_DEFUN([am__FOO], [[: am__FOO do nothing]])
+END
+
+$MAKE Makefile
+$FGREP ': am__FOO do nothing' configure
+
+$MAKE distcheck
+
+:
diff --git a/tests/aclocalflags-moreopts.test b/tests/aclocalflags-moreopts.test
new file mode 100755
index 0000000..71db5e6
--- /dev/null
+++ b/tests/aclocalflags-moreopts.test
@@ -0,0 +1,100 @@
+#! /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_ACLOCAL_FLAGS
+# AM_EXTRA_ACLOCAL_FLAGS.  Do not check `-I', since it's already
+# checked by other tests.  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; }
+
+# Remove all options from aclocal calls, while keeping user override
+# for aclocal program.
+ACLOCAL=`set x $ACLOCAL && echo $2`
+
+# To be compared with other aclocal outputs later.
+$ACLOCAL --help > help.txt
+$ACLOCAL --version > version.txt
+acdir=`$ACLOCAL --print-ac-dir` || Exit 1
+
+for macro in AM_ACLOCAL_FLAGS AM_EXTRA_ACLOCAL_FLAGS; do
+
+  for opt in help version; do
+    clean_cache
+    echo "$macro([--$opt])" > configure.in
+    $ACLOCAL > stdout || { cat stdout; Exit 1; }
+    cat stdout
+    diff $opt.txt stdout
+  done
+  rm -f stdout
+
+  clean_cache
+  echo "$macro([--print-ac-dir])" > configure.in
+  out=`$ACLOCAL` || Exit 1
+  test x"$out" = x"$acdir"
+
+  clean_cache
+  echo "$macro([--force])" > configure.in
+  $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
+  echo "$macro([--output=quux.m4])" > configure.in
+  $ACLOCAL
+  grep  '^#.*generated.*by aclocal' quux.m4
+  test ! -r aclocal.m4
+  rm -f quux.m4
+  
+  clean_cache
+  echo "$macro([--verbose --dry])" > configure.in
+  $ACLOCAL 2>stderr || { cat stderr >&2; Exit 1; }
+  cat stderr >&2
+  grep "^aclocal:.*found macro.*$macro" stderr
+  test ! -r aclocal.m4
+  rm -f stderr
+
+  mkdir m4
+  # deliberately underquoted definition
+  echo 'AC_DEFUN(FOO, foo)' > m4/foo.m4
+
+  clean_cache
+  echo "$macro([-Werror -I m4])" > configure.in
+  $ACLOCAL 2>stderr && { cat stderr >&2; Exit 1; }
+  cat stderr >&2
+  grep 'underquoted definition.*FOO' stderr
+
+  clean_cache
+  echo "$macro([-Wno-syntax -I m4])" > configure.in
+  $ACLOCAL 2>stderr || { cat stderr >&2; Exit 1; }
+  cat stderr >&2
+  test ! -s stderr
+
+  rm -rf m4
+
+done
+
+:
diff --git a/tests/aclocalflags-multi.test b/tests/aclocalflags-multi.test
new file mode 100755
index 0000000..f9f6636
--- /dev/null
+++ b/tests/aclocalflags-multi.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 that when AM_ACLOCAL_AMFLAGS is called multiple times, the last
+# call wins.
+
+. ./defs || Exit 1
+
+set -e
+
+cat > configure.in <<'END'
+AM_ACLOCAL_FLAGS([--help])
+AM_ACLOCAL_FLAGS([--output=foo.m4])
+END
+
+$ACLOCAL
+test ! -r aclocal.m4
+test -f foo.m4
+
+:
diff --git a/tests/aclocalflags-noam.test b/tests/aclocalflags-noam.test
new file mode 100755
index 0000000..4a16f2f
--- /dev/null
+++ b/tests/aclocalflags-noam.test
@@ -0,0 +1,59 @@
+#! /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 can be correctly derived from calls to
+# AM_ACLOCAL_FLAGS, AM_EXTRA_ACLOCAL_FLAGS and AC_CONFIG_MACRO_DIR,
+# even when automake is not involved.
+
+. ./defs || Exit 1
+
+set -e
+
+cat > configure.in <<END
+AC_INIT([$me], [1.0])
+AC_CONFIG_MACRO_DIR([macro-dir])
+FOO__BAR__QUUX
+END
+
+mkdir macro-dir
+cat > macro-dir/foo.m4 <<'END'
+AC_DEFUN([FOO__BAR__QUUX], [foo--bar--quux])
+END
+
+$ACLOCAL
+$AUTOCONF
+$FGREP foo--bar--quux configure
+
+rm -f configure aclocal.m4
+rm -rf autom4te*.cache # just to be sure
+
+cat > configure.in <<END
+AM_ACLOCAL_FLAGS([-I macro-dir])
+AM_EXTRA_ACLOCAL_FLAGS([--output=bar.m4])
+FOO__BAR__QUUX
+END
+
+$ACLOCAL
+test ! -r aclocal.m4
+grep '^#.*generated.*by aclocal' bar.m4
+
+mv -f bar.m4 aclocal.m4
+(echo "AC_INIT([$me], [1.0])" && cat configure.in) > t
+mv -f t configure.in
+$AUTOCONF
+$FGREP  foo--bar--quux configure
+
+:
diff --git a/tests/aclocalflags-override1.test 
b/tests/aclocalflags-override1.test
new file mode 100755
index 0000000..0826703
--- /dev/null
+++ b/tests/aclocalflags-override1.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 aclocal prefers, for the aclocal flags, the value from
+# AM_ACLOCAL_FLAGS to the default value that would be computed from
+# the call to AC_CONFIG_MACRO_DIR.
+# Keep this in sync with sister test `aclocalflags-override2.test'.
+
+. ./defs || Exit 1
+
+set -e
+
+cat >> configure.in <<'END'
+dnl: Call AM_ACLOCAL_FLAGS *before* AC_CONFIG_MACRO_DIR
+dnl: The sister test `aclocalflags-override2.test' does
+dnl: it the other way around.
+AM_ACLOCAL_FLAGS([-I good-dir])
+AC_CONFIG_MACRO_DIR([bad-dir])
+am__FOO || { (exit 1); exit 1; }
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+check-local:
+       test -f good.cfg
+       test ! -r bad.cfg
+DISTCLEANFILES = good.cfg
+END
+
+mkdir bad-dir good-dir
+cat > bad-dir/bad.m4 <<'END'
+AC_DEFUN([am__FOO], [: > bad.cfg])
+END
+cat > good-dir/good.m4 <<'END'
+AC_DEFUN([am__FOO], [: > good.cfg])
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+test -f good.cfg
+test ! -r bad.cfg
+
+$MAKE distcheck
+
+:
diff --git a/tests/aclocalflags-override2.test 
b/tests/aclocalflags-override2.test
new file mode 100755
index 0000000..de1b1c9
--- /dev/null
+++ b/tests/aclocalflags-override2.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 aclocal prefers, for the aclocal flags, the value from
+# AM_ACLOCAL_FLAGS to the default value that would be computed from
+# the call to AC_CONFIG_MACRO_DIR.
+# Keep this in sync with sister test `aclocalflags-override1.test'.
+
+. ./defs || Exit 1
+
+set -e
+
+cat >> configure.in <<'END'
+dnl: Call AM_ACLOCAL_FLAGS *after* AC_CONFIG_MACRO_DIR
+dnl: The sister test `aclocalflags-override1.test' does
+dnl: it the other way around.
+AC_CONFIG_MACRO_DIR([bad-dir])
+AM_ACLOCAL_FLAGS([-I good-dir])
+am__FOO || { (exit 1); exit 1; }
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+check-local:
+       test -f good.cfg
+       test ! -r bad.cfg
+DISTCLEANFILES = good.cfg
+END
+
+mkdir bad-dir good-dir
+cat > bad-dir/bad.m4 <<'END'
+AC_DEFUN([am__FOO], [: > bad.cfg])
+END
+cat > good-dir/good.m4 <<'END'
+AC_DEFUN([am__FOO], [: > good.cfg])
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+test -f good.cfg
+test ! -r bad.cfg
+
+$MAKE distcheck
+
+:
diff --git a/tests/aclocalflags-precedence1.test 
b/tests/aclocalflags-precedence1.test
new file mode 100755
index 0000000..3fff0b3
--- /dev/null
+++ b/tests/aclocalflags-precedence1.test
@@ -0,0 +1,32 @@
+#! /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 AM_EXTRA_ACLOCAL_FLAGS wins over AM_ACLOCAL_FLAGS.
+
+. ./defs || Exit 1
+
+set -e
+
+cat > configure.in <<'END'
+AM_EXTRA_ACLOCAL_FLAGS([--output=good.m4])
+AM_ACLOCAL_FLAGS([--output=bad.m4])
+END
+
+$ACLOCAL
+test -f good.m4
+test ! -r bad.m4
+
+:
diff --git a/tests/aclocalflags-precedence2.test 
b/tests/aclocalflags-precedence2.test
new file mode 100755
index 0000000..d4ef2d1
--- /dev/null
+++ b/tests/aclocalflags-precedence2.test
@@ -0,0 +1,31 @@
+#! /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_ACLOCAL_FLAGS.
+
+. ./defs || Exit 1
+
+set -e
+
+cat > configure.in <<'END'
+AM_ACLOCAL_FLAGS([--output=bad.m4])
+END
+
+$ACLOCAL --output=good.m4
+test -f good.m4
+test ! -r bad.m4
+
+:
diff --git a/tests/aclocalflags-precedence3.test 
b/tests/aclocalflags-precedence3.test
new file mode 100755
index 0000000..8843ada
--- /dev/null
+++ b/tests/aclocalflags-precedence3.test
@@ -0,0 +1,31 @@
+#! /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
+
+cat > configure.in <<'END'
+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-rebuild.test b/tests/aclocalflags-rebuild.test
new file mode 100755
index 0000000..9b0fba4
--- /dev/null
+++ b/tests/aclocalflags-rebuild.test
@@ -0,0 +1,86 @@
+#! /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_ACLOCAL_FLAGS, AM_EXTRA_ACLOCAL_FLAGS, and
+# rebuild rules.
+
+. ./defs || Exit 1
+
+set -e
+
+cat >> configure.in <<END
+AM_ACLOCAL_FLAGS([-I macro-dir-1 --output=quux.m4])
+AM_EXTRA_ACLOCAL_FLAGS([-I macro-dir-2])
+dnl!! AM_EXTRA_ACLOCAL_FLAGS([--verbose]) # activated later
+MACRO_1 || { (exit 1); exit 1; }
+MACRO_2 || { (exit 1); exit 1; }
+AC_OUTPUT
+END
+
+: > Makefile.am
+
+mkdir macro-dir-1 macro-dir-2
+
+cat > macro-dir-1/foo.m4 <<'END'
+AC_DEFUN([MACRO_1], [: > foo-1])
+END
+cat > macro-dir-2/bar.m4 <<'END'
+AC_DEFUN([MACRO_2], [: > bar-1])
+END
+
+$ACLOCAL >output 2>&1 || { cat output; Exit 1; }
+cat output >&2
+grep 'aclocal:.*found macro' stderr && Exit 1 # sanity check
+test -f quux.m4
+test ! -r aclocal.m4
+mv quux.m4 aclocal.m4
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+test -f foo-1
+test -f bar-1
+rm -f foo-1 bar-1
+
+$sleep
+
+sed -e 's/ *--output=quux\.m4//' -e 's/^dnl!! *//' configure.in > t
+mv -f t configure.in
+
+cat >> Makefile.am <<'END'
+DISTCLEANFILES = foo-2 bar-2  ## for distcheck below
+END
+
+cat > macro-dir-1/foo.m4 <<'END'
+AC_DEFUN([MACRO_1], [: > foo-2])
+END
+cat > macro-dir-2/bar.m4 <<'END'
+AC_DEFUN([MACRO_2], [: > bar-2])
+END
+
+$MAKE Makefile >output 2>&1 || { cat output; Exit 1; }
+cat output
+test ! -r quux.m4
+test -f foo-2
+test -f bar-2
+test ! -r foo-1
+test ! -r bar-1
+grep "^aclocal:.*found macro.*MACRO_1.*macro-dir-1" output
+grep "^aclocal:.*found macro.*MACRO_2.*macro-dir-2" output
+
+$MAKE distcheck
+
+:
diff --git a/tests/aclocalflags-simple1.test b/tests/aclocalflags-simple1.test
new file mode 100755
index 0000000..1c301f3
--- /dev/null
+++ b/tests/aclocalflags-simple1.test
@@ -0,0 +1,51 @@
+#! /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 basic support for AM_ACLOCAL_AMFLAGS.
+# Keep this in sync with sister tests `aclocalflags-simple2.test',
+# `aclocalflags-extra3.test' and `aclocalflags-extra4.test'.
+
+. ./defs || Exit 1
+
+set -e
+
+cat >> configure.in <<END
+AM_ACLOCAL_FLAGS([--output=foo.m4])
+AC_OUTPUT
+END
+
+cat > aclocal.m4 <<'END'
+m4_include([foo.m4])
+END
+
+cat > Makefile.am <<'END'
+.PHONY: test
+test:
+       grep '^#.*generated.*by aclocal' $(top_srcdir)/foo.m4
+       grep '^m4_include(\[foo\.m4\])$$' $(top_srcdir)/aclocal.m4
+check-local: test
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+$MAKE test
+$MAKE distcheck
+
+:
diff --git a/tests/aclocalflags-simple2.test b/tests/aclocalflags-simple2.test
new file mode 100755
index 0000000..812f937
--- /dev/null
+++ b/tests/aclocalflags-simple2.test
@@ -0,0 +1,51 @@
+#! /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 basic support for AM_ACLOCAL_AMFLAGS used late.
+# Keep this in sync with sister tests `aclocalflags-simple1.test',
+# `aclocalflags-extra3.test' and `aclocalflags-extra4.test'.
+
+. ./defs || Exit 1
+
+set -e
+
+cat >> configure.in <<END
+AC_OUTPUT
+AM_ACLOCAL_FLAGS([--output=foo.m4])
+END
+
+cat > aclocal.m4 <<'END'
+m4_include([foo.m4])
+END
+
+cat > Makefile.am <<'END'
+.PHONY: test
+test:
+       grep '^#.*generated.*by aclocal' $(top_srcdir)/foo.m4
+       grep '^m4_include(\[foo\.m4\])$$' $(top_srcdir)/aclocal.m4
+check-local: test
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+$MAKE test
+$MAKE distcheck
+
+:
diff --git a/tests/aclocalflags-whitespaces.test 
b/tests/aclocalflags-whitespaces.test
new file mode 100755
index 0000000..9104f4b
--- /dev/null
+++ b/tests/aclocalflags-whitespaces.test
@@ -0,0 +1,64 @@
+#! /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_ACLOCAL_AMFLAGS and AM_EXTRA_ACLOCAL_AMFLAGS can cope with
+# extra white spaces (tabs, newlines, backslash-escaped newlines...).
+
+. ./defs || Exit 1
+
+set -e
+
+tab='  '
+cat >> configure.in <<END
+AM_ACLOCAL_FLAGS([${tab} -I \
+${tab}ac-macro-dir  ${tab}
+    --verbose\
+])
+AM_EXTRA_ACLOCAL_FLAGS([  -I${tab}am-macro-dir
+--output=quux.m4 \
+$tab
+ ])
+am__AC_MACRO || { (exit 1); exit 1; }
+am__AM_MACRO || { (exit 1); exit 1; }
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+DISTCLEANFILES = foo-ac bar-am
+END
+
+mkdir ac-macro-dir am-macro-dir
+cat > ac-macro-dir/ac-foo.m4 <<'END'
+AC_DEFUN([am__AC_MACRO], [: > foo-ac])
+END
+cat > am-macro-dir/am-bar.m4 <<'END'
+AC_DEFUN([am__AM_MACRO], [: > bar-am])
+END
+
+$ACLOCAL
+grep '^#.*generated.*by aclocal' quux.m4
+test ! -r aclocal.m4
+mv quux.m4 aclocal.m4
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+test -f foo-ac
+test -f bar-am
+
+$MAKE distcheck
+
+:
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.1


reply via email to

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