automake
[Top][All Lists]
Advanced

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

[RFC] {maint} Add support for user-defined recursive targets.


From: Stefano Lattarini
Subject: [RFC] {maint} Add support for user-defined recursive targets.
Date: Fri, 8 Oct 2010 18:09:29 +0200
User-agent: KMail/1.13.3 (Linux/2.6.30-2-686; KDE/4.4.4; i686; ; )

Hello automakers.

Here is the promised patch (based off "maint") which adds support
for user-defined recursive targets in automake.  It still lacks a
NEWS entry, proper documentation, and the error checking in macro
AM_EXTRA_RECURSIVE_TARGETS.

The documentation should hopefully be distillable from the relevant
thread on the automake mailing list.  Help is welcome ;-)

There are also two cosmetic patches giving a better name to a couple of
pre-existent test scripts (and tweaking them a little in the process; I
just couldn't resist...).

More details about the design of the new feature are give below.  As
usual, comments are welcome.

On Thursday 07 October 2010, Ralf Wildenhues wrote:
> Hi Stefano,
> 
> * Stefano Lattarini wrote on Wed, Oct 06, 2010 at 11:01:35PM CEST:
> > After some experimenting, I've refined my ideas a bit (they're still
> > somewhat muddy and rough at the edges, though).  Below are the details.
> > Comments welcome.
> 
> Thank you for providing design ideas, that is much easier to parse (and
> to verify testsuite additions against).  Ideally the design ends up
> being a patch against automake.texi.  ;-)
> 
> > Expected features of user recursive targets in Automake:
> > 
> >  + User recursive targets can be defined through the use of a new make
> >    variable `EXTRA_RECURSIVE_TARGETS'.
This is still true.  But now they can also be defined through a new autoconf
macro "AM_EXTRA_RECURSIVE_TARGETS" (as suggested by Ralf; see below), so
that the definition don't need to be repeated in all the Makefile.am.  Also,
defining EXTRA_RECURSIVE_TARGETS "locally" in a Makefile.am overrides the
"global" definition provided by AM_EXTRA_RECURSIVE_TARGETS.

The argument of AM_EXTRA_RECURSIVE_TARGETS should be a whitespace-separated
list of *literal* strings (names of the recursive user targets).  Currently,
this is not strictly enforced, since I'd like to allow also make macro in
addition to true literal strings.

> >    We should hopefully be able to support automake conditionals in its
> >    definition;
Unfortunately, this doesn't work yet.  And while this is not a harsh
limitation, it would be nice to lift it anyway; maybe someone more
confortable with the automake internals than I am could help here.

> >    but apart from that, the variable's content will probably have to
> >    be literal
Not entirely true anymore.  See below.
> >    i.e. no AC_SUBST'd stuff
This limitation still holds (but it's not an harsh one, given the presence
of the new macro AM_EXTRA_RECURSIVE_TARGETS), but ...
> >    and no make macros:
... this limitation has been lifted (thanks to Ralf for pointing out the
existence of the `value_as_list_recursive' Automake subroutine, which
helped in this).
 
> >  + Definition of `EXTRA_RECURSIVE_TARGETS' in a Makefile.am with SUBDIRS
> >    defined should be *recursively* propageted into all Makefiles in all
> >    the $(SUBDIRS).  Thus, if `Makefile.am' contains:
> >      SUBDIRS = sub
> >      EXTRA_RECURSIVE_TARGETS = foo
> >    then the generated `sub/Makefile.in' should contain the definition
> >    `EXTRA_RECURSIVE_TARGETS = foo' too, even if such definition is *not*
> >    in `sub/Makefile.am'.
This requirement has been dropped ...

> This violates the current dependency tree.  An update of toplevel
> Makefile.am will not trigger sub/Makefile.in to be regenerated.
> Thus this is fairly much impossible to realize without considerable
> (and not welcome) changes to the architecture.
... given these very sensible objections advanced by Ralf.  BTW, now that
we have AM_EXTRA_RECURSIVE_TARGETS, such a "recursively sub-propagation"
feature would be quite superfluous anyway.

> On the other hand, if we require from the user to specify
> EXTRA_RECURSIVE_TARGETS in each Makefile.am (either as being the same
> everywhere, or as being a superset in sub Makefile.am files), that might
> be a fairly heavy burden for the user.  Basically, as a user the only
> way to achieve this efficiently would be to add
>   AC_SUBST([EXTRA_RECURSIVE_TARGETS], [foo])
> to configure.ac; but you've disallowed that above.
> 
> Maybe we can lessen the limitation: allow to AC_SUBST the variable,
> but only with literal strings from configure.ac (rather than shell
> $vars).
I went for a new autoconf macro altogheter (AM_EXTRA_RECURSIVE_TARGETS),
which seemed cleaner, and easier to implement.

> Then we can still get at a superset of the set of recursive
> targets.  Shell conditional additions might still be a problem though.
And they still are, even with my approach.
 
> The only other way to do it is to include a fragment.am in each
> Makefile.am, and define the variable there.
This too is supported (and tested).
 
> Consider that projects can be huge.  My pet example, OpenMPI, has way
> over 100 makefiles for one configure, and also has sub configures.
> Adding new recursive targets should not require 100 changes.
 
> Maybe we can employ another strategy altogether here.  Let's assume the
> set of extra recursive targets is pretty small, and static.  Then the
> user could just call a macro
>   AM_EXTRA_RECURSIVE_TARGETS([target ...])
> 
> in configure.ac, to define such an extra target.  That would work fine,
> allow us easy checks for literal values.  And it would allow us an
> efficient implementation.
I've followed this road, and it's apparently working quite well.
 
> >  + "Leaf" Makefiles (which don't define SUBDIRS) should not contain the
> >    recursion code (like the one in `lib/subdirs.am'), but should still be
> >    able to properly cope with `foo-local' targets, if they have inherited
> >    `foo' in `EXTRA_RECURSIVE_TARGETS' from their upper-level Makefiles. 
> This is a requirement on the implementation, not the user.
Yes; and is satisfied by the current implementation.
 
> >  + It should be possible to define `EXTRA_RECURSIVE_TARGETS' to unrelated
> >    and inconsistent values in Makefiles that do not share a "parent"
> >    Makefile through `SUBDIRS'.  This would be a very unusual setup, though,
> >    and thus supporting it is quite low-priority.
> 
> Basically only with subdirs that are in DIST_SUBDIRS but not in SUBDIRS.
I've not added tests for this yet; but it should work (... famous last words).
 
> >  + All the `foo' recursive targets and their associated `foo-local' targets
> >    should proably be declared as .PHONY. 
> Yep.
Done (and tested for).
 
> > Unresolved questions:
> > 
> >  + How to cope with explicit definition of `EXTRA_RECURSIVE_TARGETS' in
> >    sub-Makefiles?  Should we add the contents of this definition to the
> >    contents inherited from upper-level Makefile, and then propagate this
> >    combined content to the lower-level Makefiles?  And if yes, do we need
> >    to properly remove duplicates?  Or it would be better to just error out,
> >    thus reserving the `EXTRA_RECURSIVE_TARGETS' for the top-level (or
> >    isolated) Makefiles? (For simplicitly's sake, I'd go with this last
> >    behaviour). 
> See above, for why this question needs to be reformulated and rethought.
Now this is a moot point for EXTRA_RECURSIVE_TARGETS definitions; and as
for AM_EXTRA_RECURSIVE_TARGETS, assignements to EXTRA_RECURSIVE_TARGETS
in Makefile.am wins over arguments of AM_EXTRA_RECURSIVE_TARGETS.  This is
the most sensible behaviour IMO.
 
> >  + What would be the best plan to improve consistency between the recursive
> >    targets defined by the user and those defined automatically/internally
> >    by automake?  Should we even care about consistency here?
> 
> The general idea is that if the user overrides targets, she wins.
This is what happens with the propsed implementation (proper testcases
verify that this really happen).

As for consistency, well, the make code implementing user-defined recursive
targets is shared 100% with the implementation of automake-defined recursive
targets.

> That makes her responsible for playing by the rules of course, but
> automake assumes that the developer is smarter.
> 
> Generally, the assumption on semantics is that the user is smarter than
> the developer, and the developer is smarter than the automake author.
> That way, things can be overridden on systems where they don't work.
> 
> > Comments welcome!
> 
> Before we look at test cases, we need to find a way that is feasible to
> implement yet still usable for the user, I think.
What about the attached? ;-)

Thanks,
   Stefano
From 5b557f2fcb51bba1cf510e3e230963443fb700f5 Mon Sep 17 00:00:00 2001
From: Stefano Lattarini <address@hidden>
Date: Tue, 5 Oct 2010 22:19:46 +0200
Subject: [PATCH 1/3] Minor improvements to tests recurs*.test

* tests/recurs.test: Removed useless calls to AM_CONDITIONAL in
the generated configure.in.
* tests/recurs2.test: Add trailing `:' command.
---
 tests/recurs.test  |    2 --
 tests/recurs2.test |    2 ++
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/tests/recurs.test b/tests/recurs.test
index 4937f4f..3660718 100755
--- a/tests/recurs.test
+++ b/tests/recurs.test
@@ -23,8 +23,6 @@ set -e
 
 cat >> configure.in << 'END'
 AC_PROG_CC
-AM_CONDITIONAL(ONE, true)
-AM_CONDITIONAL(TWO, false)
 END
 
 cat > Makefile.am << 'END'
diff --git a/tests/recurs2.test b/tests/recurs2.test
index c025984..652d7d6 100755
--- a/tests/recurs2.test
+++ b/tests/recurs2.test
@@ -29,3 +29,5 @@ END
 
 $ACLOCAL
 $AUTOMAKE
+
+:
-- 
1.7.1

From 265b96c8461c70e350be680766aa82a927f6216f Mon Sep 17 00:00:00 2001
From: Stefano Lattarini <address@hidden>
Date: Tue, 5 Oct 2010 22:24:12 +0200
Subject: [PATCH 2/3] Rename tests recurs*.test to var-recurs*.test

* tests/recurs.test: Renamed to ...
* tests/var-recurs.test: ... this.
* tests/recurs2.test: Renamed to ...
* tests/var-recurs2.test: ... this.
* tests/Makefile.am (TESTS): Updated
---
 tests/Makefile.am                        |    4 ++--
 tests/Makefile.in                        |    4 ++--
 tests/{recurs.test => var-recurs.test}   |    0
 tests/{recurs2.test => var-recurs2.test} |    0
 4 files changed, 4 insertions(+), 4 deletions(-)
 rename tests/{recurs.test => var-recurs.test} (100%)
 rename tests/{recurs2.test => var-recurs2.test} (100%)

diff --git a/tests/Makefile.am b/tests/Makefile.am
index acc7640..2755253 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -608,8 +608,6 @@ python9.test \
 python10.test \
 python11.test \
 python12.test \
-recurs.test \
-recurs2.test \
 remake.test \
 remake2.test \
 remake3.test \
@@ -762,6 +760,8 @@ vala4.test \
 vala5.test \
 vars.test \
 vars3.test \
+var-recurs.test \
+var-recurs2.test \
 vartar.test \
 version.test \
 version2.test \
diff --git a/tests/Makefile.in b/tests/Makefile.in
index 117f2ba..2699f0a 100644
--- a/tests/Makefile.in
+++ b/tests/Makefile.in
@@ -875,8 +875,6 @@ python9.test \
 python10.test \
 python11.test \
 python12.test \
-recurs.test \
-recurs2.test \
 remake.test \
 remake2.test \
 remake3.test \
@@ -1029,6 +1027,8 @@ vala4.test \
 vala5.test \
 vars.test \
 vars3.test \
+var-recurs.test \
+var-recurs2.test \
 vartar.test \
 version.test \
 version2.test \
diff --git a/tests/recurs.test b/tests/var-recurs.test
similarity index 100%
rename from tests/recurs.test
rename to tests/var-recurs.test
diff --git a/tests/recurs2.test b/tests/var-recurs2.test
similarity index 100%
rename from tests/recurs2.test
rename to tests/var-recurs2.test
-- 
1.7.1

From 16a1b300e37ecbbd1c6bebd05cc21a5582bbad4e Mon Sep 17 00:00:00 2001
From: Stefano Lattarini <address@hidden>
Date: Wed, 6 Oct 2010 02:37:30 +0200
Subject: [PATCH 3/3] Add support for user-defined recursive targets.

---
 ChangeLog                            |   51 +++++++++++++++
 Makefile.in                          |   28 +++++----
 automake.in                          |   42 +++++++++++++
 lib/Automake/Makefile.in             |   18 +++--
 lib/Makefile.in                      |   18 +++--
 lib/am/subdirs.am                    |   14 +++-
 m4/Makefile.am                       |    1 +
 m4/Makefile.in                       |    1 +
 m4/extra-recurs.m4                   |   20 ++++++
 tests/Makefile.am                    |   32 +++++++++-
 tests/Makefile.in                    |   32 +++++++++-
 tests/recurs-user-cond1.test         |   82 +++++++++++++++++++++++++
 tests/recurs-user-cond2.test         |   84 +++++++++++++++++++++++++
 tests/recurs-user-envclean.test      |   53 ++++++++++++++++
 tests/recurs-user-indir-acsubst.test |   67 ++++++++++++++++++++
 tests/recurs-user-indir-include.test |   74 ++++++++++++++++++++++
 tests/recurs-user-indir-local.test   |  112 ++++++++++++++++++++++++++++++++++
 tests/recurs-user-indir-makevar.test |   77 +++++++++++++++++++++++
 tests/recurs-user-k1.test            |   94 ++++++++++++++++++++++++++++
 tests/recurs-user-k2.test            |   96 +++++++++++++++++++++++++++++
 tests/recurs-user-leaf-nolocal.test  |   54 ++++++++++++++++
 tests/recurs-user-many-ac.test       |   64 +++++++++++++++++++
 tests/recurs-user-many-am.test       |   72 ++++++++++++++++++++++
 tests/recurs-user-nested-ac.test     |   87 ++++++++++++++++++++++++++
 tests/recurs-user-nested-am.test     |   91 +++++++++++++++++++++++++++
 tests/recurs-user-no-subdirs.test    |   60 ++++++++++++++++++
 tests/recurs-user-no-top-level.test  |   57 +++++++++++++++++
 tests/recurs-user-notnested-ac.test  |  108 ++++++++++++++++++++++++++++++++
 tests/recurs-user-notnested-am.test  |  108 ++++++++++++++++++++++++++++++++
 tests/recurs-user-only-dot.test      |   50 +++++++++++++++
 tests/recurs-user-order.test         |   66 ++++++++++++++++++++
 tests/recurs-user-override1.test     |   69 +++++++++++++++++++++
 tests/recurs-user-override2.test     |   89 +++++++++++++++++++++++++++
 tests/recurs-user-phony1.test        |   61 ++++++++++++++++++
 tests/recurs-user-phony2.test        |   57 +++++++++++++++++
 tests/recurs-user-wrap1.test         |   53 ++++++++++++++++
 tests/recurs-user-wrap2.test         |   49 +++++++++++++++
 tests/recurs-user-wrap3.test         |   54 ++++++++++++++++
 tests/recurs-user-wrap4.test         |   51 +++++++++++++++
 39 files changed, 2264 insertions(+), 32 deletions(-)
 create mode 100644 m4/extra-recurs.m4
 create mode 100755 tests/recurs-user-cond1.test
 create mode 100755 tests/recurs-user-cond2.test
 create mode 100755 tests/recurs-user-envclean.test
 create mode 100755 tests/recurs-user-indir-acsubst.test
 create mode 100755 tests/recurs-user-indir-include.test
 create mode 100755 tests/recurs-user-indir-local.test
 create mode 100755 tests/recurs-user-indir-makevar.test
 create mode 100755 tests/recurs-user-k1.test
 create mode 100755 tests/recurs-user-k2.test
 create mode 100755 tests/recurs-user-leaf-nolocal.test
 create mode 100755 tests/recurs-user-many-ac.test
 create mode 100755 tests/recurs-user-many-am.test
 create mode 100755 tests/recurs-user-nested-ac.test
 create mode 100755 tests/recurs-user-nested-am.test
 create mode 100755 tests/recurs-user-no-subdirs.test
 create mode 100755 tests/recurs-user-no-top-level.test
 create mode 100755 tests/recurs-user-notnested-ac.test
 create mode 100755 tests/recurs-user-notnested-am.test
 create mode 100755 tests/recurs-user-only-dot.test
 create mode 100755 tests/recurs-user-order.test
 create mode 100755 tests/recurs-user-override1.test
 create mode 100755 tests/recurs-user-override2.test
 create mode 100755 tests/recurs-user-phony1.test
 create mode 100755 tests/recurs-user-phony2.test
 create mode 100755 tests/recurs-user-wrap1.test
 create mode 100755 tests/recurs-user-wrap2.test
 create mode 100755 tests/recurs-user-wrap3.test
 create mode 100755 tests/recurs-user-wrap4.test

diff --git a/ChangeLog b/ChangeLog
index 7883d5e..64c2ab8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,56 @@
 2010-10-04  Stefano Lattarini  <address@hidden>
 
+       Add support for user-defined recursive targets.
+       * automake.in ($extra_recursive_targets): New global variable.
+       (scan_autoconf_traces): Trace macro `AM_EXTRA_RECURSIVE_TARGETS'.
+       (handle_user_recursion): New subroutine; among other things, define
+       the `EXTRA_RECURSIVE_TARGETS' make variable and associated `*-am',
+       `*-local' and `*-recursive' targets.
+       (do_check_merge_target): Call it.
+       * NEWS: TODO!
+       * doc/automake.texi: TODO!
+       * lib/am/subdirs.am (AM_RECURSIVE_TARGETS): Extend by adding
+       `$(EXTRA_RECURSIVE_TARGETS)'.
+       (am__EXTRA_RECURSIVE_TARGETS): New internal variable, computed
+       from `$(EXTRA_RECURSIVE_TARGETS)'.
+       (.PHONY, .MAKE): Updated.
+       ($(am__EXTRA_RECURSIVE_TARGETS)): New targets (sharing the rules
+       with `$(RECURSIVE_TARGETS)').
+       * m4/extra-recurs.m4: New file, contain definition of new macro
+       `AM_EXTRA_RECURSIVE_TARGETS' (just for tracing).
+       * m4/Makefile.am (dist_m4data_DATA): Updated.
+       * tests/recurs-user-cond1.test: New test.
+       * tests/recurs-user-envclean.test: Likewise.
+       * tests/recurs-user-indir-include.test: Likewise.
+       * tests/recurs-user-indir-local.test: Likewise.
+       * tests/recurs-user-indir-makevar.test: Likewise.
+       * tests/recurs-user-k1.test: Likewise.
+       * tests/recurs-user-k2.test: Likewise.
+       * tests/recurs-user-leaf-nolocal.test: Likewise.
+       * tests/recurs-user-many-ac.test: Likewise.
+       * tests/recurs-user-many-am.test: Likewise.
+       * tests/recurs-user-nested-ac.test: Likewise.
+       * tests/recurs-user-nested-am.test: Likewise.
+       * tests/recurs-user-no-subdirs.test: Likewise.
+       * tests/recurs-user-no-top-level.test: Likewise.
+       * tests/recurs-user-notnested-ac.test: Likewise.
+       * tests/recurs-user-notnested-am.test: Likewise.
+       * tests/recurs-user-only-dot.test: Likewise.
+       * tests/recurs-user-order.test: Likewise.
+       * tests/recurs-user-override1.test: Likewise.
+       * tests/recurs-user-override2.test: Likewise.
+       * tests/recurs-user-phony1.test: Likewise.
+       * tests/recurs-user-phony2.test: Likewise.
+       * tests/recurs-user-wrap1.test: Likewise.
+       * tests/recurs-user-wrap2.test: Likewise.
+       * tests/recurs-user-wrap3.test: Likewise.
+       * tests/recurs-user-wrap4.test: Likewise.
+       * tests/recurs-user-cond2.test: New test, xfailing.
+       * tests/recurs-user-indir-acsubst.test: Likewise.
+       * tests/Makefile.am (TESTS, XFAIL_TESTS): Updated.
+
+2010-10-04  Stefano Lattarini  <address@hidden>
+
        Add support for newer python versions.
        * m4/python.m4 (AM_PATH_PYTHON): Add python2.7 and python3.2 to
        _AM_PYTHON_INTERPRETER_LIST.  Since we are at it, break a long
diff --git a/Makefile.in b/Makefile.in
index 649565b..de5eff9 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -104,8 +104,11 @@ RECURSIVE_TARGETS = all-recursive check-recursive 
dvi-recursive \
 RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive        \
   distclean-recursive maintainer-clean-recursive
 AM_RECURSIVE_TARGETS = $(RECURSIVE_TARGETS:-recursive=) \
-       $(RECURSIVE_CLEAN_TARGETS:-recursive=) tags TAGS ctags CTAGS \
-       distdir dist dist-all distcheck
+       $(RECURSIVE_CLEAN_TARGETS:-recursive=) \
+       $(EXTRA_RECURSIVE_TARGETS) tags TAGS ctags CTAGS distdir dist \
+       dist-all distcheck
+am__EXTRA_RECURSIVE_TARGETS = $(EXTRA_RECURSIVE_TARGETS:=-recursive)
+EXTRA_RECURSIVE_TARGETS =
 ETAGS = etags
 CTAGS = ctags
 DIST_SUBDIRS = $(SUBDIRS)
@@ -397,7 +400,7 @@ uninstall-binSCRIPTS:
 # (1) if the variable is set in `config.status', edit `config.status'
 #     (which will cause the Makefiles to be regenerated when you run `make');
 # (2) otherwise, pass the desired values on the `make' command line.
-$(RECURSIVE_TARGETS):
+$(RECURSIVE_TARGETS) $(am__EXTRA_RECURSIVE_TARGETS):
        @fail= failcom='exit 1'; \
        for f in x $$MAKEFLAGS; do \
          case $$f in \
@@ -814,15 +817,16 @@ ps-am:
 uninstall-am: uninstall-binSCRIPTS
        @$(NORMAL_INSTALL)
        $(MAKE) $(AM_MAKEFLAGS) uninstall-hook
-.MAKE: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) ctags-recursive \
-       install-am install-exec-am install-strip tags-recursive \
-       uninstall-am
-
-.PHONY: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) CTAGS GTAGS \
-       all all-am am--refresh check check-am clean clean-generic \
-       ctags ctags-recursive dist dist-all dist-bzip2 dist-gzip \
-       dist-hook dist-lzma dist-shar dist-tarZ dist-xz dist-zip \
-       distcheck distclean distclean-generic distclean-tags \
+.MAKE: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) \
+       $(am__EXTRA_RECURSIVE_TARGETS) ctags-recursive install-am \
+       install-exec-am install-strip tags-recursive uninstall-am
+
+.PHONY: $(EXTRA_RECURSIVE_TARGETS) $(RECURSIVE_CLEAN_TARGETS) \
+       $(RECURSIVE_TARGETS) $(am__EXTRA_RECURSIVE_TARGETS) CTAGS \
+       GTAGS all all-am am--refresh check check-am clean \
+       clean-generic ctags ctags-recursive dist dist-all dist-bzip2 \
+       dist-gzip dist-hook dist-lzma dist-shar dist-tarZ dist-xz \
+       dist-zip distcheck distclean distclean-generic distclean-tags \
        distcleancheck distdir distuninstallcheck dvi dvi-am html \
        html-am info info-am install install-am install-binSCRIPTS \
        install-data install-data-am install-dvi install-dvi-am \
diff --git a/automake.in b/automake.in
index 6b36ae2..8cc0100 100755
--- a/automake.in
+++ b/automake.in
@@ -373,6 +373,9 @@ my $ac_gettext_location;
 # Whether AM_GNU_GETTEXT_INTL_SUBDIR has been seen.
 my $seen_gettext_intl = 0;
 
+# The arguments of the AM_EXTRA_RECURSIVE_TARGETS call (if any).
+my $extra_recursive_targets = '';
+
 # Lists of tags supported by Libtool.
 my %libtool_tags = ();
 # 1 if Libtool uses LT_SUPPORTED_TAG.  If it does, then it also
@@ -4691,6 +4694,39 @@ sub handle_all ($)
       }
 }
 
+# Generate helper targets for user recursion, where needed.
+sub handle_user_recursion ()
+{
+    # FIXME: there is a sane way to take into account the use of
+    # conditionals in the definition of `EXTRA_RECURSIVE_TARGETS'?
+    if (not var 'EXTRA_RECURSIVE_TARGETS')
+    {
+      define_pretty_variable ('EXTRA_RECURSIVE_TARGETS', TRUE, INTERNAL,
+                              $extra_recursive_targets);
+    }
+    my $var = var('EXTRA_RECURSIVE_TARGETS');
+    return
+      unless $var;
+    my @extra_recursive_targets = $var->value_as_list_recursive;
+    my $helper = var ('SUBDIRS') ? 'recursive' : 'local';
+    foreach my $target (@extra_recursive_targets)
+      {
+        # This allows the default target's rules to be overridden in
+        # Makefile.am.
+        user_phony_rule ($target);
+        depend ($target, "$target-$helper");
+        pretty_print_rule ("$target-am: $target-local");
+        # Every user-defined recursive target `foo' *must* have a valid
+        # associated `foo-local' rule; we define it as an empty rule by
+        # default, so that the user can transparently extend it in his
+        # own Makefile.am.
+        pretty_print_rule ("$target-local:");
+        # $target-recusrsive might as well be undefined, so do not add
+        # it here; it's taken care of in subdirs.am anyway.
+        depend (".PHONY", "$target-am", "$target-local");
+      }
+}
+
 
 # &do_check_merge_target ()
 # -------------------------
@@ -5238,6 +5274,7 @@ sub scan_autoconf_traces ($)
                AM_AUTOMAKE_VERSION => 1,
                AM_CONDITIONAL => 2,
                AM_ENABLE_MULTILIB => 0,
+               AM_EXTRA_RECURSIVE_TARGETS => 1,
                AM_GNU_GETTEXT => 0,
                AM_GNU_GETTEXT_INTL_SUBDIR => 0,
                AM_INIT_AUTOMAKE => 0,
@@ -5404,6 +5441,10 @@ sub scan_autoconf_traces ($)
        {
          $seen_multilib = $where;
        }
+      elsif ($macro eq 'AM_EXTRA_RECURSIVE_TARGETS')
+       {
+         $extra_recursive_targets = $args[1];
+       }
       elsif ($macro eq 'AM_GNU_GETTEXT')
        {
          $seen_gettext = $where;
@@ -8208,6 +8249,7 @@ sub generate_makefile ($$)
   handle_data;
   handle_headers;
   handle_subdirs;
+  handle_user_recursion;
   handle_tags;
   handle_minor_options;
   # Must come after handle_programs so that %known_programs is up-to-date.
diff --git a/lib/Automake/Makefile.in b/lib/Automake/Makefile.in
index e068ab8..a629b80 100644
--- a/lib/Automake/Makefile.in
+++ b/lib/Automake/Makefile.in
@@ -101,8 +101,10 @@ DATA = $(dist_perllib_DATA) $(nodist_perllib_DATA)
 RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive        \
   distclean-recursive maintainer-clean-recursive
 AM_RECURSIVE_TARGETS = $(RECURSIVE_TARGETS:-recursive=) \
-       $(RECURSIVE_CLEAN_TARGETS:-recursive=) tags TAGS ctags CTAGS \
-       distdir
+       $(RECURSIVE_CLEAN_TARGETS:-recursive=) \
+       $(EXTRA_RECURSIVE_TARGETS) tags TAGS ctags CTAGS distdir
+am__EXTRA_RECURSIVE_TARGETS = $(EXTRA_RECURSIVE_TARGETS:=-recursive)
+EXTRA_RECURSIVE_TARGETS =
 ETAGS = etags
 CTAGS = ctags
 DIST_SUBDIRS = $(SUBDIRS)
@@ -343,7 +345,7 @@ uninstall-nodist_perllibDATA:
 # (1) if the variable is set in `config.status', edit `config.status'
 #     (which will cause the Makefiles to be regenerated when you run `make');
 # (2) otherwise, pass the desired values on the `make' command line.
-$(RECURSIVE_TARGETS):
+$(RECURSIVE_TARGETS) $(am__EXTRA_RECURSIVE_TARGETS):
        @fail= failcom='exit 1'; \
        for f in x $$MAKEFLAGS; do \
          case $$f in \
@@ -630,11 +632,13 @@ ps-am:
 
 uninstall-am: uninstall-dist_perllibDATA uninstall-nodist_perllibDATA
 
-.MAKE: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) ctags-recursive \
-       install-am install-strip tags-recursive
+.MAKE: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) \
+       $(am__EXTRA_RECURSIVE_TARGETS) ctags-recursive install-am \
+       install-strip tags-recursive
 
-.PHONY: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) CTAGS GTAGS \
-       all all-am check check-am clean clean-generic ctags \
+.PHONY: $(EXTRA_RECURSIVE_TARGETS) $(RECURSIVE_CLEAN_TARGETS) \
+       $(RECURSIVE_TARGETS) $(am__EXTRA_RECURSIVE_TARGETS) CTAGS \
+       GTAGS all all-am check check-am clean clean-generic ctags \
        ctags-recursive distclean distclean-generic distclean-tags \
        distdir dvi dvi-am html html-am info info-am install \
        install-am install-data install-data-am \
diff --git a/lib/Makefile.in b/lib/Makefile.in
index f90b085..d0f415d 100644
--- a/lib/Makefile.in
+++ b/lib/Makefile.in
@@ -103,8 +103,10 @@ DATA = $(dist_pkgvdata_DATA) $(dist_script_DATA)
 RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive        \
   distclean-recursive maintainer-clean-recursive
 AM_RECURSIVE_TARGETS = $(RECURSIVE_TARGETS:-recursive=) \
-       $(RECURSIVE_CLEAN_TARGETS:-recursive=) tags TAGS ctags CTAGS \
-       distdir
+       $(RECURSIVE_CLEAN_TARGETS:-recursive=) \
+       $(EXTRA_RECURSIVE_TARGETS) tags TAGS ctags CTAGS distdir
+am__EXTRA_RECURSIVE_TARGETS = $(EXTRA_RECURSIVE_TARGETS:=-recursive)
+EXTRA_RECURSIVE_TARGETS =
 ETAGS = etags
 CTAGS = ctags
 DIST_SUBDIRS = $(SUBDIRS)
@@ -314,7 +316,7 @@ uninstall-dist_scriptDATA:
 # (1) if the variable is set in `config.status', edit `config.status'
 #     (which will cause the Makefiles to be regenerated when you run `make');
 # (2) otherwise, pass the desired values on the `make' command line.
-$(RECURSIVE_TARGETS):
+$(RECURSIVE_TARGETS) $(am__EXTRA_RECURSIVE_TARGETS):
        @fail= failcom='exit 1'; \
        for f in x $$MAKEFLAGS; do \
          case $$f in \
@@ -601,11 +603,13 @@ ps-am:
 
 uninstall-am: uninstall-dist_pkgvdataDATA uninstall-dist_scriptDATA
 
-.MAKE: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) ctags-recursive \
-       install-am install-data-am install-strip tags-recursive
+.MAKE: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) \
+       $(am__EXTRA_RECURSIVE_TARGETS) ctags-recursive install-am \
+       install-data-am install-strip tags-recursive
 
-.PHONY: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) CTAGS GTAGS \
-       all all-am check check-am clean clean-generic ctags \
+.PHONY: $(EXTRA_RECURSIVE_TARGETS) $(RECURSIVE_CLEAN_TARGETS) \
+       $(RECURSIVE_TARGETS) $(am__EXTRA_RECURSIVE_TARGETS) CTAGS \
+       GTAGS all all-am check check-am clean clean-generic ctags \
        ctags-recursive distclean distclean-generic distclean-tags \
        distdir dvi dvi-am html html-am info info-am install \
        install-am install-data install-data-am install-data-hook \
diff --git a/lib/am/subdirs.am b/lib/am/subdirs.am
index 9c01a8c..d656bbe 100644
--- a/lib/am/subdirs.am
+++ b/lib/am/subdirs.am
@@ -20,11 +20,18 @@ RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive 
clean-recursive     \
   distclean-recursive maintainer-clean-recursive
 ## All documented targets which invoke `make' recursively, or depend
 ## on targets that do so.
-AM_RECURSIVE_TARGETS += $(RECURSIVE_TARGETS:-recursive=) \
-  $(RECURSIVE_CLEAN_TARGETS:-recursive=)
+AM_RECURSIVE_TARGETS += \
+  $(RECURSIVE_TARGETS:-recursive=) \
+  $(RECURSIVE_CLEAN_TARGETS:-recursive=) \
+  $(EXTRA_RECURSIVE_TARGETS)
+
+am__EXTRA_RECURSIVE_TARGETS = $(EXTRA_RECURSIVE_TARGETS:=-recursive)
 
 .PHONY: $(RECURSIVE_TARGETS) $(RECURSIVE_CLEAN_TARGETS)
+.PHONY: $(EXTRA_RECURSIVE_TARGETS)
+.PHONY: $(am__EXTRA_RECURSIVE_TARGETS)
 .MAKE: $(RECURSIVE_TARGETS) $(RECURSIVE_CLEAN_TARGETS)
+.MAKE: $(am__EXTRA_RECURSIVE_TARGETS)
 
 # This directory's subdirectories are mostly independent; you can cd
 # into them and run `make' without going through this Makefile.
@@ -33,7 +40,7 @@ AM_RECURSIVE_TARGETS += $(RECURSIVE_TARGETS:-recursive=) \
 #     (which will cause the Makefiles to be regenerated when you run `make');
 # (2) otherwise, pass the desired values on the `make' command line.
 
-$(RECURSIVE_TARGETS):
+$(RECURSIVE_TARGETS) $(am__EXTRA_RECURSIVE_TARGETS):
 ## Using $failcom allows "-k" to keep its natural meaning when running a
 ## recursive rule.
        @fail= failcom='exit 1'; \
@@ -60,7 +67,6 @@ $(RECURSIVE_TARGETS):
          $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \
        fi; test -z "$$fail"
 
-
 mostlyclean: mostlyclean-recursive
 clean: clean-recursive
 distclean: distclean-recursive
diff --git a/m4/Makefile.am b/m4/Makefile.am
index 0cf074b..0709906 100644
--- a/m4/Makefile.am
+++ b/m4/Makefile.am
@@ -30,6 +30,7 @@ cond-if.m4 \
 depend.m4 \
 depout.m4 \
 dmalloc.m4 \
+extra-recurs.m4 \
 gcj.m4 \
 header.m4 \
 init.m4 \
diff --git a/m4/Makefile.in b/m4/Makefile.in
index 270ee91..18a57c7 100644
--- a/m4/Makefile.in
+++ b/m4/Makefile.in
@@ -193,6 +193,7 @@ cond-if.m4 \
 depend.m4 \
 depout.m4 \
 dmalloc.m4 \
+extra-recurs.m4 \
 gcj.m4 \
 header.m4 \
 init.m4 \
diff --git a/m4/extra-recurs.m4 b/m4/extra-recurs.m4
new file mode 100644
index 0000000..8f1cbe4
--- /dev/null
+++ b/m4/extra-recurs.m4
@@ -0,0 +1,20 @@
+# AM_EXTRA_RECURSIVE_TARGETS                                -*- 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_EXTRA_RECURSIVE_TARGETS
+# --------------------------
+# Define the list of user recursive targets.  This macro exists only to
+# be traced by Automake, which will ensure that a proper definition of
+# `EXTRA_RECURSIVE_TARGETS' (and associated rules) is propagated into all
+# the generated Makefile.in.  Individual Makefile.am should still be able
+# to override such definition of EXTRA_RECURSIVE_TARGETS, though.
+# TODO: We should rerally reject non-literal arguments here...
+AC_DEFUN([AM_EXTRA_RECURSIVE_TARGETS], [])
+
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 2755253..b3cfb04 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -21,7 +21,9 @@ all.test \
 auxdir2.test \
 cond17.test \
 gcj6.test \
-txinfo5.test
+txinfo5.test \
+recurs-user-cond2.test \
+recurs-user-indir-acsubst.test
 
 include $(srcdir)/parallel-tests.am
 
@@ -608,6 +610,34 @@ python9.test \
 python10.test \
 python11.test \
 python12.test \
+recurs-user-cond1.test \
+recurs-user-cond2.test \
+recurs-user-envclean.test \
+recurs-user-leaf-nolocal.test \
+recurs-user-indir-acsubst.test \
+recurs-user-indir-include.test \
+recurs-user-indir-local.test \
+recurs-user-indir-makevar.test \
+recurs-user-k1.test \
+recurs-user-k2.test \
+recurs-user-many-am.test \
+recurs-user-many-ac.test \
+recurs-user-nested-am.test \
+recurs-user-nested-ac.test \
+recurs-user-notnested-am.test \
+recurs-user-notnested-ac.test \
+recurs-user-no-subdirs.test \
+recurs-user-no-top-level.test \
+recurs-user-only-dot.test \
+recurs-user-order.test \
+recurs-user-override1.test \
+recurs-user-override2.test \
+recurs-user-phony1.test \
+recurs-user-phony2.test \
+recurs-user-wrap1.test \
+recurs-user-wrap2.test \
+recurs-user-wrap3.test \
+recurs-user-wrap4.test \
 remake.test \
 remake2.test \
 remake3.test \
diff --git a/tests/Makefile.in b/tests/Makefile.in
index 2699f0a..1fa95ec 100644
--- a/tests/Makefile.in
+++ b/tests/Makefile.in
@@ -277,7 +277,9 @@ all.test \
 auxdir2.test \
 cond17.test \
 gcj6.test \
-txinfo5.test
+txinfo5.test \
+recurs-user-cond2.test \
+recurs-user-indir-acsubst.test
 
 parallel_tests = \
 check-p.test \
@@ -875,6 +877,34 @@ python9.test \
 python10.test \
 python11.test \
 python12.test \
+recurs-user-cond1.test \
+recurs-user-cond2.test \
+recurs-user-envclean.test \
+recurs-user-leaf-nolocal.test \
+recurs-user-indir-acsubst.test \
+recurs-user-indir-include.test \
+recurs-user-indir-local.test \
+recurs-user-indir-makevar.test \
+recurs-user-k1.test \
+recurs-user-k2.test \
+recurs-user-many-am.test \
+recurs-user-many-ac.test \
+recurs-user-nested-am.test \
+recurs-user-nested-ac.test \
+recurs-user-notnested-am.test \
+recurs-user-notnested-ac.test \
+recurs-user-no-subdirs.test \
+recurs-user-no-top-level.test \
+recurs-user-only-dot.test \
+recurs-user-order.test \
+recurs-user-override1.test \
+recurs-user-override2.test \
+recurs-user-phony1.test \
+recurs-user-phony2.test \
+recurs-user-wrap1.test \
+recurs-user-wrap2.test \
+recurs-user-wrap3.test \
+recurs-user-wrap4.test \
 remake.test \
 remake2.test \
 remake3.test \
diff --git a/tests/recurs-user-cond1.test b/tests/recurs-user-cond1.test
new file mode 100755
index 0000000..33b1923
--- /dev/null
+++ b/tests/recurs-user-cond1.test
@@ -0,0 +1,82 @@
+#! /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 user-defined recursive targets works with
+# conditionally-defined $(SUBDIRS).
+
+. ./defs || Exit 1
+
+set -e
+
+cat >> configure.in <<'END'
+AC_CONFIG_FILES([sub1/Makefile sub2/Makefile])
+AM_CONDITIONAL([COND_GOOD], [:])
+AM_CONDITIONAL([COND_BAD], [false])
+AC_OUTPUT
+END
+
+mkdir sub1 sub2
+
+cat > Makefile.am <<'END'
+EXTRA_RECURSIVE_TARGETS = foo
+DIST_SUBDIRS = sub1 sub2
+
+SUBDIRS =
+if COND_GOOD
+  SUBDIRS += sub1
+else
+  SUBDIRS += sub3
+endif
+if COND_BAD
+  SUBDIRS += sub2
+else
+  foo-local:; : > foo
+  CLEANFILES = foo
+endif
+
+all-local: foo
+check-local:
+       test -f foo
+       test -f sub1/foo
+       test ! -r sub2/foo
+END
+
+cat > sub1/Makefile.am <<'END'
+foo:
+       : > $@
+CLEANFILES = foo
+END
+
+cat > sub2/Makefile.am <<'END'
+foo foo-local:
+       @echo 'ERROR: target "$@" in sub2/Makefile should not be run' >&2
+       @exit 1
+END
+
+$ACLOCAL
+$AUTOCONF
+# sub3 existence is required by automake
+mkdir sub3
+$AUTOMAKE
+# but shouldn't be required anymore thereafter
+rmdir sub3
+
+./configure
+
+$MAKE check
+$MAKE distcheck
+
+:
diff --git a/tests/recurs-user-cond2.test b/tests/recurs-user-cond2.test
new file mode 100755
index 0000000..152e782
--- /dev/null
+++ b/tests/recurs-user-cond2.test
@@ -0,0 +1,84 @@
+#! /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 user-defined recursive targets works with
+# conditionally-defined $(EXTRA_RECURSIVE_TARGETS).
+# Currently, this test fails due to limits in the implementation.
+# It's still unclear if such limits might be lifted in the future.
+
+. ./defs || Exit 1
+
+set -e
+
+cat >> configure.in <<'END'
+AC_CONFIG_FILES([sub/Makefile])
+AM_CONDITIONAL([COND_GOOD], [:])
+AM_CONDITIONAL([COND_BAD], [false])
+AC_OUTPUT
+END
+
+mkdir sub
+
+cat > Makefile.am <<'END'
+SUBDIRS = sub
+
+if COND_GOOD
+EXTRA_RECURSIVE_TARGETS = foo
+bar:
+else !COND_GOOD
+EXTRA_RECURSIVE_TARGETS = bar
+foo:
+endif !COND_GOOD
+
+if COND_BAD
+EXTRA_RECURSIVE_TARGETS += baz
+else !COND_BAD
+baz:
+endif !COND_BAD
+
+foo-local:; : > foo
+bar-local:; : > bar
+baz-local:; : > baz
+
+all-local: foo bar baz
+
+check-local:
+       test -f foo
+       test -f sub/foo
+       test ! -r bar
+       test ! -r sub/bar
+       test ! -r baz
+       test ! -r sub/baz
+
+CLEANFILES = foo
+END
+
+cat > sub/Makefile.am <<'END'
+foo bar baz:
+       touch $@
+CLEANFILES = foo
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+$MAKE check
+$MAKE distcheck
+
+:
diff --git a/tests/recurs-user-envclean.test b/tests/recurs-user-envclean.test
new file mode 100755
index 0000000..3c74d39
--- /dev/null
+++ b/tests/recurs-user-envclean.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 setting `EXTRA_RECURSIVE_TARGETS' from the environment do
+# not cause user recursion machinery to be activated.
+
+. ./defs || Exit 1
+
+set -e
+
+cat >> configure.in <<'END'
+AC_CONFIG_FILES([sub/Makefile])
+AC_OUTPUT
+END
+
+mkdir sub
+
+cat > Makefile.am <<'END'
+SUBDIRS = sub
+END
+
+cat > sub/Makefile.am <<'END'
+foo-local:
+       : > bar1
+foo:
+       : > bar2
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+EXTRA_RECURSIVE_TARGETS=foo $MAKE # sanity check
+EXTRA_RECURSIVE_TARGETS=foo $MAKE foo && Exit 1
+test ! -r sub/bar1
+test ! -r sub/bar2
+
+:
diff --git a/tests/recurs-user-indir-acsubst.test 
b/tests/recurs-user-indir-acsubst.test
new file mode 100755
index 0000000..2d35baa
--- /dev/null
+++ b/tests/recurs-user-indir-acsubst.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 user recursion works with when EXTRA_RECURSIVE_TARGETS
+# contains AC_SUBST'd *static* values.  Due to implementation reasons
+# (and probably also to design reasons), this currently doesn't work.
+
+. ./defs || Exit 1
+
+set -e
+
+cat >> configure.in <<'END'
+AC_CONFIG_FILES([sub/Makefile])
+dnl: Plase keep the leading and trailing whitespaces in @FOOBAR@
+dnl: definition; otherwise, in case of errors/bugs, we risk an
+dnl: infinite make recursion (with fork bomb!).  Yes, this has
+dnl: already happened in practice.
+AC_SUBST([FOOBAR], [' foo bar '])
+AC_OUTPUT
+END
+
+mkdir sub
+
+cat > Makefile.am <<'END'
+CLEANFILES = $(EXTRA_RECURSIVE_TARGETS)
+SUBDIRS = sub
+EXTRA_RECURSIVE_TARGETS = @FOOBAR@
+foo-local:
+       : > foo
+bar-local:
+       : > bar
+check-local: $(EXTRA_RECURSIVE_TARGETS)
+       test -f foo
+       test -f bar
+       test -f sub/foo
+       test -f sub/bar
+END
+
+cat > sub/Makefile.am <<'END'
+CLEANFILES = foo bar
+foo bar:
+       : > $@
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+$MAKE check
+$MAKE distcheck
+
+:
diff --git a/tests/recurs-user-indir-include.test 
b/tests/recurs-user-indir-include.test
new file mode 100755
index 0000000..a9fe235
--- /dev/null
+++ b/tests/recurs-user-indir-include.test
@@ -0,0 +1,74 @@
+#! /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 user recursion works with when EXTRA_RECURSIVE_TARGETS
+# is defined/extended by included files.
+
+. ./defs || Exit 1
+
+set -e
+
+cat >> configure.in <<'END'
+AC_CONFIG_FILES([sub/Makefile])
+AC_OUTPUT
+END
+
+mkdir sub
+
+cat > extra-define.am <<'END'
+EXTRA_RECURSIVE_TARGETS = foo
+END
+
+cat > extra-extend.am <<'END'
+EXTRA_RECURSIVE_TARGETS += bar
+END
+
+cat > Makefile.am <<'END'
+include extra-define.am
+include extra-extend.am
+
+SUBDIRS = sub
+
+foo-local:
+       : > foo
+bar-local:
+       : > bar
+
+CLEANFILES = $(EXTRA_RECURSIVE_TARGETS)
+
+check-local: foo bar
+       test -f foo
+       test -f bar
+       test -f sub/foo
+       test -f sub/bar
+END
+
+cat > sub/Makefile.am <<'END'
+CLEANFILES = foo bar
+$(CLEANFILES):
+       : > $@
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+$MAKE check
+$MAKE distcheck
+
+:
diff --git a/tests/recurs-user-indir-local.test 
b/tests/recurs-user-indir-local.test
new file mode 100755
index 0000000..2ab379d
--- /dev/null
+++ b/tests/recurs-user-indir-local.test
@@ -0,0 +1,112 @@
+#! /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 user recursion works with various types of indirections
+# *involved in the definition of the `*-local' targets*: make macros,
+# AC_SUBST'd strings, automake-time file inclusions, automake
+# conditionals...
+
+. ./defs || Exit 1
+
+set -e
+
+cat >> configure.in <<'END'
+AC_CONFIG_FILES([
+    sub1/Makefile
+    sub1/subsub/Makefile
+    sub2/Makefile
+    sub2/subsub/Makefile
+])
+AC_SUBST([ac__FOO_LOCAL], [foo-local])
+AM_CONDITIONAL([COND], [:])
+AC_OUTPUT
+END
+
+mkdir sub1 sub1/subsub sub2 sub2/subsub sub2/subsub/subsubsub
+
+cat > Makefile.am <<'END'
+EXTRA_RECURSIVE_TARGETS = foo
+SUBDIRS = sub1 sub2
+
+am__FOO_LOCAL = foo-local
+$(am__FOO_LOCAL):
+       pwd && : > foo
+CLEANFILES = foo
+
+all-local: foo
+check-local:
+       test -f foo
+       test -f sub1/foo
+       test -f sub1/subsub/foo
+       test -f sub2/foo
+       test -f sub2/subsub/foo
+       test ! -r sub2/subsub/bar
+END
+
+cat > sub1/Makefile.am <<'END'
+EXTRA_RECURSIVE_TARGETS = foo
+SUBDIRS = subsub
address@hidden@:
+       pwd && : > foo
+CLEANFILES = foo
+END
+
+cat > sub1/subsub/Makefile.am <<'END'
+EXTRA_RECURSIVE_TARGETS = foo
+e =
+f$(e)o$(e)o$(e)-$(e)l$(e)o$(e)c$(e)a$(e)l:
+       pwd && : > foo
+CLEANFILES = foo
+END
+
+cat > sub2/Makefile.am <<'END'
+EXTRA_RECURSIVE_TARGETS = foo
+include $(srcdir)/bar.am
+include $(srcdir)/baz.am
+CLEANFILES = foo
+END
+
+cat > sub2/bar.am <<'END'
+SUBDIRS = subsub
+END
+
+cat > sub2/baz.am <<'END'
+foo-local:
+       pwd && : > foo
+END
+
+cat > sub2/subsub/Makefile.am <<'END'
+EXTRA_RECURSIVE_TARGETS = foo
+if COND
+foo-local:
+       pwd && : > foo
+else !COND
+foo-local:
+       pwd && : > bar
+endif !COND
+CLEANFILES = foo
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+$MAKE check
+$MAKE distcheck
+
+:
diff --git a/tests/recurs-user-indir-makevar.test 
b/tests/recurs-user-indir-makevar.test
new file mode 100755
index 0000000..d7a0905
--- /dev/null
+++ b/tests/recurs-user-indir-makevar.test
@@ -0,0 +1,77 @@
+#! /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 user recursion works when the definition of the
+# EXTRA_RECURSIVE_TARGETS contains other make macros.
+
+. ./defs || Exit 1
+
+set -e
+
+cat >> configure.in <<'END'
+AC_CONFIG_FILES([sub/Makefile])
+AC_SUBST([CLEANFILES], ["foo bar1 bar2 baz1 baz2"])
+AC_OUTPUT
+END
+
+mkdir sub
+
+cat > Makefile.am <<'END'
+FOO = foo
+EXTRA_RECURSIVE_TARGETS = $(FOO) $(BAR)
+EXTRA_RECURSIVE_TARGETS += $(BAZ)
+BAZ = baz1 baz2
+BAR = ${BAR_0}
+BAR_0 = $(BAR_1)
+BAR_0 += ${BAR_p1}$(BAR_p2)
+BAR_1 = bar1
+BAR_p1 = ba
+BAR_p2 = r2
+
+SUBDIRS = sub
+
+foo-local bar1-local bar2-local baz1-local baz2-local:
+       touch `expr '$@' : '\(.*\)-local'`
+
+all-local: foo bar1 bar2 baz1 baz2
+check-local:
+       test -f foo
+       test -f bar1
+       test -f bar2
+       test -f baz1
+       test -f baz2
+       test -f sub/foo
+       test -f sub/bar1
+       test -f sub/bar2
+       test -f sub/baz1
+       test -f sub/baz2
+END
+
+cat > sub/Makefile.am <<'END'
+foo bar1 bar2 baz1 baz2:
+       : > $@
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+$MAKE check
+$MAKE distcheck
+
+:
diff --git a/tests/recurs-user-k1.test b/tests/recurs-user-k1.test
new file mode 100755
index 0000000..831c60a
--- /dev/null
+++ b/tests/recurs-user-k1.test
@@ -0,0 +1,94 @@
+#! /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 user recursion works with `make -k'.
+# Please keep this in sync with syster tests `user-recurs-k2.test'.
+
+. ./defs || Exit 1
+
+set -e
+
+cat >> configure.in <<'END'
+AC_CONFIG_FILES([
+    sub1/Makefile
+    sub1/subsub1/Makefile
+    sub2/Makefile
+    sub2/subsub2/Makefile
+    sub3/Makefile
+])
+FAIL='@echo "FAIL $@ in `pwd`"; exit 1'
+PASS='@echo "PASS $@ in `pwd`"; : > foo'
+AC_SUBST([FAIL])
+AC_SUBST([PASS])
+AC_OUTPUT
+END
+
+mkdir sub1 sub1/subsub1 sub2 sub2/subsub2 sub3
+
+cat > Makefile.am <<'END'
+EXTRA_RECURSIVE_TARGETS = foo
+SUBDIRS = sub1 . sub2 sub3
+foo-local:; @FAIL@
+END
+
+cat > sub1/Makefile.am <<'END'
+EXTRA_RECURSIVE_TARGETS = foo
+SUBDIRS = subsub1
+foo-local:; @PASS@
+END
+
+cat > sub1/subsub1/Makefile.am <<'END'
+EXTRA_RECURSIVE_TARGETS = foo
+foo-local:; @FAIL@
+END
+
+cat > sub2/Makefile.am <<'END'
+EXTRA_RECURSIVE_TARGETS = foo
+SUBDIRS = subsub2
+foo-local:; @FAIL@
+END
+
+cat > sub2/subsub2/Makefile.am <<'END'
+EXTRA_RECURSIVE_TARGETS = foo
+foo-local:; @PASS@
+END
+
+cat > sub3/Makefile.am <<'END'
+EXTRA_RECURSIVE_TARGETS = foo
+foo-local:; @PASS@
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+cat > exp <<END
+./sub1/foo
+./sub2/subsub2/foo
+./sub3/foo
+END
+
+$MAKE -k foo || : # don't trust the exit status of `make -k'
+
+find . -name foo > t || { cat t; Exit 1; }
+LC_ALL=C sort t > got
+cat exp
+cat got
+diff exp got
+
+:
diff --git a/tests/recurs-user-k2.test b/tests/recurs-user-k2.test
new file mode 100755
index 0000000..3705276
--- /dev/null
+++ b/tests/recurs-user-k2.test
@@ -0,0 +1,96 @@
+#! /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 user recursion works with `make --keep-going'.
+# Please keep this in sync with syster test `user-recurs-k1.test'.
+
+required=GNUmake
+. ./defs || Exit 1
+
+set -e
+
+cat >> configure.in <<'END'
+AC_CONFIG_FILES([
+    sub1/Makefile
+    sub1/subsub1/Makefile
+    sub2/Makefile
+    sub2/subsub2/Makefile
+    sub3/Makefile
+])
+FAIL='@echo "FAIL $@ in `pwd`"; exit 1'
+PASS='@echo "PASS $@ in `pwd`"; : > foo'
+AC_SUBST([FAIL])
+AC_SUBST([PASS])
+AC_OUTPUT
+END
+
+mkdir sub1 sub1/subsub1 sub2 sub2/subsub2 sub3
+
+cat > Makefile.am <<'END'
+EXTRA_RECURSIVE_TARGETS = foo
+SUBDIRS = sub1 . sub2 sub3
+foo-local:; @FAIL@
+END
+
+cat > sub1/Makefile.am <<'END'
+EXTRA_RECURSIVE_TARGETS = foo
+SUBDIRS = subsub1
+foo-local:; @PASS@
+END
+
+cat > sub1/subsub1/Makefile.am <<'END'
+EXTRA_RECURSIVE_TARGETS = foo
+foo-local:; @FAIL@
+END
+
+cat > sub2/Makefile.am <<'END'
+EXTRA_RECURSIVE_TARGETS = foo
+SUBDIRS = subsub2
+foo-local:; @FAIL@
+END
+
+cat > sub2/subsub2/Makefile.am <<'END'
+EXTRA_RECURSIVE_TARGETS = foo
+foo-local:; @PASS@
+END
+
+cat > sub3/Makefile.am <<'END'
+EXTRA_RECURSIVE_TARGETS = foo
+foo-local:; @PASS@
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+cat > exp <<END
+./sub1/foo
+./sub2/subsub2/foo
+./sub3/foo
+END
+
+# Trust the exit status of `make --keep-going' for GNU make.
+$MAKE --keep-going foo && Exit 1
+
+find . -name foo > t || { cat t; Exit 1; }
+LC_ALL=C sort t > got
+cat exp
+cat got
+diff exp got
+
+:
diff --git a/tests/recurs-user-leaf-nolocal.test 
b/tests/recurs-user-leaf-nolocal.test
new file mode 100755
index 0000000..b69717f
--- /dev/null
+++ b/tests/recurs-user-leaf-nolocal.test
@@ -0,0 +1,54 @@
+#! /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 "leaf" Makefiles do not get an autogenerated `foo-local'
+# target associated to a user-defined recursive target `local'.
+
+. ./defs || Exit 1
+
+set -e
+
+cat >> configure.in <<'END'
+AC_CONFIG_FILES([sub/Makefile])
+AC_OUTPUT
+END
+
+mkdir sub
+
+cat > Makefile.am <<'END'
+SUBDIRS = sub
+EXTRA_RECURSIVE_TARGETS = foo
+check-local:
+       cd ./sub || exit 1; \
+        $(MAKE) $(AM_MAKEFLAGS) foo-local && exit 1; \
+        exit 0;
+END
+
+: > sub/Makefile.am
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+$MAKE
+cd sub
+$MAKE foo-local && Exit 1
+cd ..
+$MAKE distcheck
+
+:
diff --git a/tests/recurs-user-many-ac.test b/tests/recurs-user-many-ac.test
new file mode 100755
index 0000000..f7cc72c
--- /dev/null
+++ b/tests/recurs-user-many-ac.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 many user-defined recursive targets can be supported
+# at once, and their list defined through AM_EXTRA_RECURSIVE_TARGETS.
+# Please keep this in sync with sister test `user-recurs-many-am.test'.
+
+. ./defs || Exit 1
+
+set -e
+
+cat >> configure.in <<'END'
+AC_CONFIG_FILES([sub/Makefile])
+## NOTE: extra white spaces, tabs, newlines and backslashes in the
+## lines below: on purpose.
+AM_EXTRA_RECURSIVE_TARGETS([ foo  \
+       bar  ])
+AC_OUTPUT
+END
+
+mkdir sub
+
+cat > Makefile.am <<'END'
+SUBDIRS = sub
+CLEANFILES = $(EXTRA_RECURSIVE_TARGETS)
+foo-local bar-local:
+       touch `echo $@ | sed 's/-local$$//'`
+check-local: $(EXTRA_RECURSIVE_TARGETS)
+       ls -l . sub # for debugging
+       test -f foo
+       test -f bar
+       test -f sub/bar
+       test -f sub/foo
+END
+
+cat > sub/Makefile.am <<'END'
+foo-local bar-local:
+       touch `echo $@ | sed 's/-local$$//'`
+CLEANFILES = $(EXTRA_RECURSIVE_TARGETS)
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+$MAKE check
+$MAKE distcheck
+
+:
diff --git a/tests/recurs-user-many-am.test b/tests/recurs-user-many-am.test
new file mode 100755
index 0000000..ab90c7b
--- /dev/null
+++ b/tests/recurs-user-many-am.test
@@ -0,0 +1,72 @@
+#! /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 many user-defined recursive targets can be supported
+# at once, and their list properly extended.
+# Please keep this in sync with sister test `user-recurs-many-ac.test'.
+
+. ./defs || Exit 1
+
+set -e
+
+cat >> configure.in <<'END'
+AC_CONFIG_FILES([sub/Makefile])
+AC_OUTPUT
+END
+
+mkdir sub
+
+sed 's/EOL$//' > Makefile.am <<'END'
+## NOTE: extra white spaces, tabs, newlines and backslashes in the
+## line below: on purpose.
+EXTRA_RECURSIVE_TARGETS =   foo  \
+       bar
+## NOTE: extra *trailing* white spaces in the line below: on purpose.
+EXTRA_RECURSIVE_TARGETS += quux  EOL
+SUBDIRS = sub
+
+quux-local bar-local:
+       touch `echo $@ | sed 's/-local$$//'`
+CLEANFILES = quux bar
+
+all-local: $(EXTRA_RECURSIVE_TARGETS)
+check-local:
+       ls -l . sub # for debugging
+       test -f bar
+       test -f quux
+       test ! -r foo
+       test -f sub/foo
+       test -f sub/bar
+       test ! -r sub/quux
+END
+
+cat > sub/Makefile.am <<'END'
+foo bar:
+       : > $@
+quux:
+CLEANFILES = foo bar
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+$MAKE check
+$MAKE distcheck
+
+:
diff --git a/tests/recurs-user-nested-ac.test b/tests/recurs-user-nested-ac.test
new file mode 100755
index 0000000..401422a
--- /dev/null
+++ b/tests/recurs-user-nested-ac.test
@@ -0,0 +1,87 @@
+#! /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 user recursion can be made to work with nested uses
+# of $(SUBDIRS) and `EXTRA_RECURSIVE_TARGETS' defined in configure.in
+# through macro `AM_EXTRA_RECURSIVE_TARGETS'.
+# Keep this in sync with syster test `user-recurs-nested-ac.test'.
+
+. ./defs || Exit 1
+
+set -e
+
+cat >> configure.in <<'END'
+AC_CONFIG_FILES([
+    sub1/Makefile
+    sub1/sub2/Makefile
+    sub1/sub2/sub3/Makefile
+])
+AM_EXTRA_RECURSIVE_TARGETS([foo])
+AC_OUTPUT
+END
+
+mkdir sub1 sub1/sub2 sub1/sub2/sub3
+
+cat > Makefile.am <<'END'
+SUBDIRS = sub1
+
+foo-local:
+       cp sub1/foo foo
+MOSTLYCLEANFILES = foo
+
+.PHONY: test
+test:
+       echo 'It works!' > exp
+       diff exp foo
+       diff exp sub1/foo
+       diff exp sub1/sub2/sub3/foo
+       rm -f exp
+
+all-local: $(EXTRA_RECURSIVE_TARGETS)
+check-local: test
+END
+
+cat > sub1/Makefile.am <<'END'
+SUBDIRS = sub2
+foo-local:
+       cp sub2/sub3/foo foo
+MOSTLYCLEANFILES = foo
+END
+
+# Here we lack an explicit definiton the "foo-local" target, but this
+# shouldn't stop "foo" recursion into subdirectory `sub3'.
+cat > sub1/sub2/Makefile.am <<'END'
+SUBDIRS = sub3
+END
+
+cat > sub1/sub2/sub3/Makefile.am <<'END'
+foo-local:
+       echo 'It works!' > foo
+MOSTLYCLEANFILES = foo
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+$MAKE foo
+$MAKE test
+
+$MAKE distcheck
+
+:
diff --git a/tests/recurs-user-nested-am.test b/tests/recurs-user-nested-am.test
new file mode 100755
index 0000000..eec7776
--- /dev/null
+++ b/tests/recurs-user-nested-am.test
@@ -0,0 +1,91 @@
+#! /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 user recursion can be made to work with nested uses
+# of $(SUBDIRS) and `EXTRA_RECURSIVE_TARGETS' defined by hand in
+# all the required Makefile.am's.
+
+# Keep this in sync with syster test `user-recurs-nested-ac.test'.
+
+. ./defs || Exit 1
+
+set -e
+
+cat >> configure.in <<'END'
+AC_CONFIG_FILES([
+    sub1/Makefile
+    sub1/sub2/Makefile
+    sub1/sub2/sub3/Makefile
+])
+AC_OUTPUT
+END
+
+mkdir sub1 sub1/sub2 sub1/sub2/sub3
+
+cat > Makefile.am <<'END'
+EXTRA_RECURSIVE_TARGETS = foo
+SUBDIRS = sub1
+
+foo-local:
+       cp sub1/foo foo
+MOSTLYCLEANFILES = foo
+
+.PHONY: test
+test:
+       echo 'It works!' > exp
+       diff exp foo
+       diff exp sub1/foo
+       diff exp sub1/sub2/sub3/foo
+       rm -f exp
+
+all-local: $(EXTRA_RECURSIVE_TARGETS)
+check-local: test
+END
+
+cat > sub1/Makefile.am <<'END'
+EXTRA_RECURSIVE_TARGETS = foo
+SUBDIRS = sub2
+foo-local:
+       cp sub2/sub3/foo foo
+MOSTLYCLEANFILES = foo
+END
+
+# Here we lack an explicit definiton the "foo-local" target, but this
+# shouldn't stop "foo" recursion into subdirectory `sub3'.
+cat > sub1/sub2/Makefile.am <<'END'
+EXTRA_RECURSIVE_TARGETS = foo
+SUBDIRS = sub3
+END
+
+cat > sub1/sub2/sub3/Makefile.am <<'END'
+EXTRA_RECURSIVE_TARGETS = foo
+foo-local:
+       echo 'It works!' > foo
+MOSTLYCLEANFILES = foo
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+$MAKE foo
+$MAKE test
+
+$MAKE distcheck
+
+:
diff --git a/tests/recurs-user-no-subdirs.test 
b/tests/recurs-user-no-subdirs.test
new file mode 100755
index 0000000..d68f527
--- /dev/null
+++ b/tests/recurs-user-no-subdirs.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 that user recursion can be made to work even when $(SUBDIRS)
+# is empty or undefined.
+
+. ./defs || Exit 1
+
+set -e
+
+cat >> configure.in <<'END'
+AC_OUTPUT
+END
+
+$ACLOCAL
+$AUTOCONF
+
+# First try with undefined $(SUBDIRS).
+cat > Makefile.am <<'END'
+all-local: foo
+foo-local:
+       : > bar
+MOSTLYCLEANFILES = bar
+check-local: test
+.PHONY: test
+test:
+       test -f bar
+EXTRA_RECURSIVE_TARGETS = foo
+END
+$AUTOMAKE
+./configure
+$MAKE foo
+$MAKE test
+$MAKE distcheck
+
+$MAKE distclean
+test ! -r bar # sanity check
+
+# Now try with empty but defined $(SUBDIRS).
+echo SUBDIRS = >> Makefile.am
+$AUTOMAKE
+./configure
+$MAKE foo
+$MAKE test
+$MAKE distcheck
+
+:
diff --git a/tests/recurs-user-no-top-level.test 
b/tests/recurs-user-no-top-level.test
new file mode 100755
index 0000000..1af99af
--- /dev/null
+++ b/tests/recurs-user-no-top-level.test
@@ -0,0 +1,57 @@
+#! /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 user recursion works even for targets that don't exist
+# in the top-level Makefile.
+
+. ./defs || Exit 1
+
+set -e
+
+cat >> configure.in <<'END'
+AC_CONFIG_FILES([sub/Makefile])
+AC_OUTPUT
+END
+
+mkdir sub
+
+cat > Makefile.am <<'END'
+SUBDIRS = sub
+EXTRA_RECURSIVE_TARGETS = foo-bar
+all-local: foo-bar
+check-local:
+       test -f sub/foo-bar
+END
+
+cat > sub/Makefile.am <<'END'
+EXTRA_RECURSIVE_TARGETS = foo-bar
+foo-bar-local:
+       : > foo-bar
+MOSTLYCLEANFILES = foo-bar
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+$MAKE foo-bar
+test -f sub/foo-bar
+
+$MAKE distcheck
+
+:
diff --git a/tests/recurs-user-notnested-ac.test 
b/tests/recurs-user-notnested-ac.test
new file mode 100755
index 0000000..f4c9707
--- /dev/null
+++ b/tests/recurs-user-notnested-ac.test
@@ -0,0 +1,108 @@
+#! /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 user recursion can be made to work when $(SUBDIRS) useges
+# are not nested, and `EXTRA_RECURSIVE_TARGETS' is defined in configure.in
+# through macro `AM_EXTRA_RECURSIVE_TARGETS'.
+# Keep this in sync with syster test `user-recurs-notnested-am.test'.
+
+. ./defs || Exit 1
+
+set -e
+
+cat >> configure.in <<'END'
+AC_CONFIG_FILES(
+    sub1/Makefile
+    sub2/Makefile
+dnl ## There's deliberately no `sub3/Makefile'.
+    sub3/subsub/Makefile
+    sub4/Makefile
+    sub4/subsub/Makefile
+)
+AM_EXTRA_RECURSIVE_TARGETS([foo])
+AC_OUTPUT
+END
+
+mkdir sub1 sub2 sub3 sub4 sub3/subsub sub4/subsub
+
+cat > Makefile.am <<'END'
+SUBDIRS = sub1 sub2 sub3/subsub sub4 sub4/subsub
+
+foo-local:
+       echo _rootdir_ >foo
+MOSTLYCLEANFILES = foo
+
+.PHONY: test
+test: foo
+       grep _rootdir_ foo
+       grep :sub1: sub1/foo
+       grep ,sub1, sub1/bar
+       test ! -r sub2/foo
+       test ! -r sub3/foo
+       grep %sub3/subsub% sub3/subsub/quux
+       test ! -r sub3/subsub/foo
+       test ! -r sub4/foo
+       grep =sub4/subsub= sub4/subsub/foo
+
+check-local: test
+END
+
+# A "foo-local" target with dependencies shouldn't cause problems.
+cat > sub1/Makefile.am <<'END'
+EXTRA_RECURSIVE_TARGETS = foo
+foo-local: bar
+       sed 's/,/:/g' bar >foo
+bar:
+       echo ,sub1, >bar
+MOSTLYCLEANFILES = foo bar
+END
+
+# The lack of a "foo" target here shouldn't cause any error in
+# automake nor in make.
+echo 'EXTRA_RECURSIVE_TARGETS = foo' > sub2/Makefile.am
+
+# The lack of file "sub3/Makefile.am" shouldn't cause any problem either.
+: # just don't create it
+
+# A "foo-local" creating a file != "foo" shouldn't cause any problem.
+cat > sub3/subsub/Makefile.am <<'END'
+EXTRA_RECURSIVE_TARGETS = foo
+foo-local:
+       echo %sub3/subsub% >quux
+MOSTLYCLEANFILES = quux
+END
+
+# No "foo-local" nor "foo" target here ...
+echo 'EXTRA_RECURSIVE_TARGETS = foo' > sub4/Makefile.am
+# ... should not cause errors, nor cause the "foo-local" target here
+# not to be executed.
+cat > sub4/subsub/Makefile.am <<'END'
+EXTRA_RECURSIVE_TARGETS = foo
+foo-local:
+       echo =sub4/subsub= >foo
+MOSTLYCLEANFILES = foo
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+$MAKE test
+$MAKE distcheck
+
+:
diff --git a/tests/recurs-user-notnested-am.test 
b/tests/recurs-user-notnested-am.test
new file mode 100755
index 0000000..9a063ec
--- /dev/null
+++ b/tests/recurs-user-notnested-am.test
@@ -0,0 +1,108 @@
+#! /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 user recursion can be made to work when $(SUBDIRS) useges
+# are not nested, and `EXTRA_RECURSIVE_TARGETS' is defined by hand in
+# all the required Makefile.am's.
+# Keep this in sync with syster test `user-recurs-notnested-ac.test'.
+
+. ./defs || Exit 1
+
+set -e
+
+cat >> configure.in <<'END'
+AC_CONFIG_FILES(
+    sub1/Makefile
+    sub2/Makefile
+dnl ## There's deliberately no `sub3/Makefile'.
+    sub3/subsub/Makefile
+    sub4/Makefile
+    sub4/subsub/Makefile
+)
+AC_OUTPUT
+END
+
+mkdir sub1 sub2 sub3 sub4 sub3/subsub sub4/subsub
+
+cat > Makefile.am <<'END'
+SUBDIRS = sub1 sub2 sub3/subsub sub4 sub4/subsub
+EXTRA_RECURSIVE_TARGETS = foo
+
+foo-local:
+       echo _rootdir_ >foo
+MOSTLYCLEANFILES = foo
+
+.PHONY: test
+test: foo
+       grep _rootdir_ foo
+       grep :sub1: sub1/foo
+       grep ,sub1, sub1/bar
+       test ! -r sub2/foo
+       test ! -r sub3/foo
+       grep %sub3/subsub% sub3/subsub/quux
+       test ! -r sub3/subsub/foo
+       test ! -r sub4/foo
+       grep =sub4/subsub= sub4/subsub/foo
+
+check-local: test
+END
+
+# A "foo-local" target with dependencies shouldn't cause problems.
+cat > sub1/Makefile.am <<'END'
+EXTRA_RECURSIVE_TARGETS = foo
+foo-local: bar
+       sed 's/,/:/g' bar >foo
+bar:
+       echo ,sub1, >bar
+MOSTLYCLEANFILES = foo bar
+END
+
+# The lack of a "foo" target here shouldn't cause any error in
+# automake nor in make.
+echo 'EXTRA_RECURSIVE_TARGETS = foo' > sub2/Makefile.am
+
+# The lack of file "sub3/Makefile.am" shouldn't cause any problem either.
+: # just don't create it
+
+# A "foo-local" creating a file != "foo" shouldn't cause any problem.
+cat > sub3/subsub/Makefile.am <<'END'
+EXTRA_RECURSIVE_TARGETS = foo
+foo-local:
+       echo %sub3/subsub% >quux
+MOSTLYCLEANFILES = quux
+END
+
+# No "foo-local" nor "foo" target here ...
+echo 'EXTRA_RECURSIVE_TARGETS = foo' > sub4/Makefile.am
+# ... should not cause errors, nor cause the "foo-local" target here
+# not to be executed.
+cat > sub4/subsub/Makefile.am <<'END'
+EXTRA_RECURSIVE_TARGETS = foo
+foo-local:
+       echo =sub4/subsub= >foo
+MOSTLYCLEANFILES = foo
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+$MAKE test
+$MAKE distcheck
+
+:
diff --git a/tests/recurs-user-only-dot.test b/tests/recurs-user-only-dot.test
new file mode 100755
index 0000000..09637ce
--- /dev/null
+++ b/tests/recurs-user-only-dot.test
@@ -0,0 +1,50 @@
+#! /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 user-defined recursive rules works when $(SUBDIRS) contains
+# only an current directory `.'.
+
+. ./defs || Exit 1
+
+set -e
+
+cat >> configure.in <<'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+SUBDIRS = .
+EXTRA_RECURSIVE_TARGETS = foo
+foo-local:
+       : > foo
+MOSTLYCLEANFILES = foo
+all-local: foo
+check-local:
+       test -f foo
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+$MAKE foo
+test -f foo
+
+$MAKE distcheck
+
+:
diff --git a/tests/recurs-user-order.test b/tests/recurs-user-order.test
new file mode 100755
index 0000000..dc67356
--- /dev/null
+++ b/tests/recurs-user-order.test
@@ -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/>.
+
+# Check that user recursion respect $(SUBDIRS) order.
+
+. ./defs || Exit 1
+
+set -e
+
+cat >> configure.in <<'END'
+AC_CONFIG_FILES([
+    sub1/Makefile
+    sub2/Makefile
+    sub3/Makefile
+])
+AC_OUTPUT
+END
+
+mkdir sub1 sub2 sub3
+
+cat > Makefile.am <<'END'
+SUBDIRS = sub1 . sub3 sub2
+EXTRA_RECURSIVE_TARGETS = foo
+foo-local:
+       echo '.' >> $(top_builddir)/got
+.PHONY: test
+test: foo
+       @(echo sub1 && echo . && echo sub3 && echo sub2) > exp
+       cat exp
+       cat got
+       diff exp got
+check-local: test
+MOSTLYCLEANFILES = got exp
+END
+
+for i in 1 2 3; do
+  cat > sub$i/Makefile.am <<END
+EXTRA_RECURSIVE_TARGETS = foo
+foo-local:
+       echo sub$i >> \$(top_builddir)/got
+END
+done
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+$MAKE test
+$MAKE distcheck
+
+:
diff --git a/tests/recurs-user-override1.test b/tests/recurs-user-override1.test
new file mode 100755
index 0000000..9a54d6c
--- /dev/null
+++ b/tests/recurs-user-override1.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 override of user-defined recursive targets work as
+# expected.
+
+. ./defs || Exit 1
+
+set -e
+
+cat >> configure.in <<'END'
+AC_CONFIG_FILES([sub/Makefile])
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+SUBDIRS = sub
+EXTRA_RECURSIVE_TARGETS = foobar zardoz
+all-local: foobar zardoz
+foobar:
+       : > foobar.out
+MOSTLYCLEANFILES = foobar.out
+check-local:
+       test -f foobar.out
+       test ! -r sub/foobar.out
+       test -f sub/zardoz.out
+       test ! -r sub/baz.out
+END
+
+mkdir sub
+cat > sub/Makefile.am <<'END'
+EXTRA_RECURSIVE_TARGETS = foobar zardoz
+foobar foobar-local:
+       : > foobar.out
+zardoz-local:
+       : > baz.out
+zardoz:
+       : > zardoz.out
+MOSTLYCLEANFILES = zardoz.out
+END
+
+$ACLOCAL
+$AUTOCONF
+
+AUTOMAKE_fails
+grep '^Makefile\.am:4:.*user target.*foobar' stderr
+grep '^sub/Makefile\.am:6:.*user target.*zardoz' stderr
+
+$AUTOMAKE -Wno-override
+
+./configure
+
+$MAKE check
+$MAKE distcheck
+
+:
diff --git a/tests/recurs-user-override2.test b/tests/recurs-user-override2.test
new file mode 100755
index 0000000..fcd9070
--- /dev/null
+++ b/tests/recurs-user-override2.test
@@ -0,0 +1,89 @@
+#! /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 Makefiles can override the value of `EXTRA_RECURSIVE_TARGETS'
+# set by `AM_EXTRA_RECURSIVE_TARGETS'.
+
+. ./defs || Exit 1
+
+set -e
+
+cat >> configure.in <<'END'
+AC_CONFIG_FILES([sub/Makefile sub/sub2/Makefile])
+AM_EXTRA_RECURSIVE_TARGETS([foo bar baz])
+AC_OUTPUT
+END
+
+mkdir sub sub/sub2
+
+cat > Makefile.am <<'END'
+SUBDIRS = sub
+foo-local bar-local baz-local:
+       touch `expr '$@' : '\(.*\)-local'`
+MOSTLYCLEANFILES = $(EXTRA_RECURSIVE_TARGETS)
+.PHONY: quux
+quux:
+check-local: $(EXTRA_RECURSIVE_TARGETS)
+       ls -l . sub sub/sub2 # for debugging
+       test -f foo
+       test -f bar
+       test -f baz
+       test ! -r sub/foo
+       test -f sub/bar
+       test -f sub/baz2
+       test ! -r sub/baz
+       test -f sub/sub2/foo
+       test ! -r sub/sub2/bar
+       test ! -r sub/sub2/baz
+END
+
+cat > sub/Makefile.am <<'END'
+SUBDIRS = sub2
+EXTRA_RECURSIVE_TARGETS = foo bar
+MOSTLYCLEANFILES = baz2 bar
+baz: baz2
+baz2:
+       : > $@
+baz-local:
+       @echo 'ERROR: target "$@" in sub/Makefile should not run' >&2
+       @exit 1
+bar-local:
+       : > bar
+END
+
+cat > sub/sub2/Makefile.am <<'END'
+baz baz-local: bad
+bad:
+       @echo 'ERROR: target "$@" in sub/sub2/Makefile should not run' >&2
+       @exit 1
+foo-local:
+       : > foo
+MOSTLYCLEANFILES = foo
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+$MAKE check
+cd sub/sub2
+$MAKE bar bar-local
+cd ../..
+$MAKE distcheck
+
+:
diff --git a/tests/recurs-user-phony1.test b/tests/recurs-user-phony1.test
new file mode 100755
index 0000000..5422a0c
--- /dev/null
+++ b/tests/recurs-user-phony1.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 user-defined recursive targets and their associate
+# local targets are declared as phony.
+
+. ./defs || Exit 1
+
+set -e
+
+cat >> configure.in <<'END'
+AC_CONFIG_FILES([sub/Makefile])
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+EXTRA_RECURSIVE_TARGETS = foo
+SUBDIRS = sub
+foo-local:
+       echo 'GOOD!' > foo
+       echo 'GOOD!' > foo-local
+END
+
+mkdir sub
+cat > sub/Makefile.am <<'END'
+EXTRA_RECURSIVE_TARGETS = foo
+foo-local:
+       echo 'GOOD!' > foo
+       echo 'GOOD!' > foo-local
+END
+
+files='foo foo-local sub/foo sub/foo-local'
+
+for f in $files; do echo 'bad :-(' > $f; done
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure
+
+$MAKE foo
+
+for f in $files; do
+  cat $f # for debugging
+  grep 'GOOD!' $f
+done
+
+:
diff --git a/tests/recurs-user-phony2.test b/tests/recurs-user-phony2.test
new file mode 100755
index 0000000..bfd4009
--- /dev/null
+++ b/tests/recurs-user-phony2.test
@@ -0,0 +1,57 @@
+#! /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 internal `*-recursive' and `*-am' targets defined for
+# user recursive targets are declared as phony.
+
+. ./defs || Exit 1
+
+set -e
+
+cat >> configure.in <<'END'
+AC_CONFIG_FILES([sub/Makefile])
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+EXTRA_RECURSIVE_TARGETS = foo
+SUBDIRS = sub
+## This shouldn't be run if foo-am is not called.
+foo-local:
+       : > bar
+END
+
+mkdir sub
+cat > sub/Makefile.am <<'END'
+## This shouldn't be run if foo-recursive is not called.
+foo:
+       : > baz
+END
+
+: > foo-recursive
+: > foo-am
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+$MAKE foo
+test -f bar
+test -f sub/baz
+
+:
diff --git a/tests/recurs-user-wrap1.test b/tests/recurs-user-wrap1.test
new file mode 100755
index 0000000..f9ded1d
--- /dev/null
+++ b/tests/recurs-user-wrap1.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 rules generated by user recursion are apt to be wrapped
+# by other makefiles.
+
+. ./defs || Exit 1
+
+set -e
+
+cat >> configure.in <<'END'
+AC_OUTPUT
+END
+
+cat > exp <<END
+bar
+foo-local
+END
+
+cat > Makefile.am <<'END'
+EXTRA_RECURSIVE_TARGETS = foo
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+cat - Makefile.in > t <<'END'
+bar foo-local:
+       echo $@ >> got
+foo: bar
+END
+mv -f t Makefile.in
+
+./configure
+
+$MAKE foo
+diff exp got
+
+:
diff --git a/tests/recurs-user-wrap2.test b/tests/recurs-user-wrap2.test
new file mode 100755
index 0000000..8334007
--- /dev/null
+++ b/tests/recurs-user-wrap2.test
@@ -0,0 +1,49 @@
+#! /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 rules generated by user recursion are apt to be wrapped
+# by other makefiles.
+
+. ./defs || Exit 1
+
+set -e
+
+cat >> configure.in <<'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+SUBDIRS = .
+EXTRA_RECURSIVE_TARGETS = foo
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+cat >> Makefile <<'END'
+bar foo-local:
+       : > $@
+foo: bar
+END
+
+$MAKE foo
+test -f bar
+test -f foo-local
+
+:
diff --git a/tests/recurs-user-wrap3.test b/tests/recurs-user-wrap3.test
new file mode 100755
index 0000000..e502295
--- /dev/null
+++ b/tests/recurs-user-wrap3.test
@@ -0,0 +1,54 @@
+#! /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 rules generated by user recursion are apt to be wrapped
+# by other makefiles.
+
+required=GNUmake
+. ./defs || Exit 1
+
+set -e
+
+cat >> configure.in <<'END'
+AC_OUTPUT
+END
+
+cat > exp <<END
+bar
+foo-local
+END
+
+cat > Makefile.am <<'END'
+EXTRA_RECURSIVE_TARGETS = foo
+END
+
+cat > wrap.mk <<'END'
+bar foo-local:
+       echo $@ >> got
+foo: bar
+include Makefile
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+$MAKE -f wrap.mk foo
+diff exp got
+
+:
diff --git a/tests/recurs-user-wrap4.test b/tests/recurs-user-wrap4.test
new file mode 100755
index 0000000..437f590
--- /dev/null
+++ b/tests/recurs-user-wrap4.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 that rules generated by user recursion are apt to be wrapped
+# by other makefiles.
+
+required=GNUmake
+. ./defs || Exit 1
+
+set -e
+
+cat >> configure.in <<'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+SUBDIRS = .
+EXTRA_RECURSIVE_TARGETS = foo
+END
+
+cat > GNUmakefile <<'END'
+include Makefile
+bar foo-local:
+       : > $@
+foo: bar
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+
+$MAKE foo
+test -f bar
+test -f foo-local
+
+:
-- 
1.7.1


reply via email to

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