Subject: Re: bug#27781: LIBOBJS should depend on LIBOBJDIR

From: Mathieu Lirzin <[email-masked]>
Date: Fri, 15 Sep 2017 11:00:28 +0200

Michael Haubenwallner <[email-masked]> writes:

> On 08/27/2017 05:23 PM, Mathieu Lirzin wrote:
>
>>> From: Michael Haubenwallner <[email-masked]>
>>> Date: Wed, 16 Aug 2017 18:16:12 +0200
>>> Subject: [PATCH] automake: Depend on LIBOBJDIR for LIBOBJS.
>>>
>>> This change fixes automake bug#27781.
>>>
>>> * bin/automake.in: Add Makefile dependency on LIBOBJDIR/dirstamp for
>>> each LIBOBJS/ALLOCA source file found.
>>> ---
>> 
>> This patch can't be applied on the 'minor' branch, which corresponds to
>> the branch of the next release (I know this is confusing [1]).  Could
>> resend it after rebasing onto the 'minor' branch?
>> 
>
> Here we go, also removing t/libobj-no-dependency-tracking.sh from XFAIL_TESTS.

I would like to apply this slightly modified patch which adds a NEWS entry,
and adapt to the revert of commit 5521219348c55af354878583b99c5f9d66d6d38a

>From 333b98f2d108111e9a99e7ede17de7f0a1adba03 Mon Sep 17 00:00:00 2001
From: Michael Haubenwallner <[email-masked]>
Date: Wed, 16 Aug 2017 18:16:12 +0200
Subject: [PATCH] automake: Depend on LIBOBJDIR for LIBOBJS and ALLOCA

This change fixes automake bug#27781.

* bin/automake.in: Add Makefile dependency on LIBOBJDIR/dirstamp for
each LIBOBJS/ALLOCA source file found.
* t/list-of-tests.mk (XFAIL_TESTS): Drop
t/libobj-no-dependency-tracking.sh.
* NEWS: Announce bug fix.
---
 NEWS               |  5 +++++
 bin/automake.in    | 31 ++++++++++++++++++++-----------
 t/list-of-tests.mk |  1 -
 3 files changed, 25 insertions(+), 12 deletions(-)

diff --git a/NEWS b/NEWS
index eb0a415..e50a955 100644
--- a/NEWS
+++ b/NEWS
@@ -113,6 +113,11 @@ New in ?.?.?:
   - Installed 'aclocal' m4 macros can now accept installation directories
     containing '@' characters (automake bug#20903)
 
+  - When combining AC_LIBOBJ or AC_FUNC_ALLOCA with the
+    "--disable-dependency-tracking" configure option in an out of source
+    build, the build sub-directory defined by AC_CONFIG_LIBOBJ_DIR is now
+    properly created.  (automake bug#27781)
+
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 New in 1.15.1:
diff --git a/bin/automake.in b/bin/automake.in
index 4294736..9709f06 100644
--- a/bin/automake.in
+++ b/bin/automake.in
@@ -2329,13 +2329,14 @@ sub handle_lib_objects
   return $seen_libobjs;
 }
 
-# handle_LIBOBJS_or_ALLOCA ($VAR)
-# -------------------------------
+# handle_LIBOBJS_or_ALLOCA ($VAR, $BASE)
+# --------------------------------------
 # Definitions common to LIBOBJS and ALLOCA.
 # VAR should be one of LIBOBJS, LTLIBOBJS, ALLOCA, or LTALLOCA.
+# BASE should be one base file name from AC_LIBSOURCE, or alloca.
 sub handle_LIBOBJS_or_ALLOCA
 {
-  my ($var) = @_;
+  my ($var, $base) = @_;
 
   my $dir = '';
 
@@ -2357,10 +2358,18 @@ sub handle_LIBOBJS_or_ALLOCA
 	  $dir = backname ($relative_dir) . "/$dir"
 	    if $relative_dir ne '.';
 	  define_variable ('LIBOBJDIR', "$dir", INTERNAL);
-	  $clean_files{"\$($var)"} = MOSTLY_CLEAN;
-	  # libtool might create LIBOBJS or ALLOCA as a side-effect of using
+	  if ($dir && !defined $clean_files{"$dir$base.\$(OBJEXT)"})
+	    {
+	      my $dirstamp = require_build_directory ($dir);
+	      $output_rules .= "$dir$base.\$(OBJEXT): $dirstamp\n";
+	      $output_rules .= "$dir$base.lo: $dirstamp\n"
+		if ($var =~ /^LT/);
+	    }
+	  # libtool might create .$(OBJEXT) as a side-effect of using
 	  # LTLIBOBJS or LTALLOCA.
-	  $clean_files{"\$($var)"} = MOSTLY_CLEAN if $var =~ s/^LT//;
+	  $clean_files{"$dir$base.\$(OBJEXT)"} = MOSTLY_CLEAN;
+	  $clean_files{"$dir$base.lo"} = MOSTLY_CLEAN
+	    if ($var =~ /^LT/);
 	}
       else
 	{
@@ -2381,14 +2390,14 @@ sub handle_LIBOBJS
   $var->requires_variables ("\@${lt}LIBOBJS\@ used", $lt . 'LIBOBJS')
     if ! keys %libsources;
 
-  my $dir = handle_LIBOBJS_or_ALLOCA "${lt}LIBOBJS";
-
   foreach my $iter (keys %libsources)
     {
-      if ($iter =~ /\.[cly]$/)
+      my $dir = '';
+      if ($iter =~ /^(.*)(\.[cly])$/)
 	{
-	  saw_extension ($&);
+	  saw_extension ($2);
 	  saw_extension ('.c');
+	  $dir = handle_LIBOBJS_or_ALLOCA ("${lt}LIBOBJS", $1);
 	}
 
       if ($iter =~ /\.h$/)
@@ -2416,7 +2425,7 @@ sub handle_ALLOCA
   my ($var, $cond, $lt) = @_;
   my $myobjext = $lt ? 'lo' : 'o';
   $lt ||= '';
-  my $dir = handle_LIBOBJS_or_ALLOCA "${lt}ALLOCA";
+  my $dir = handle_LIBOBJS_or_ALLOCA ("${lt}ALLOCA", "alloca");
 
   $dir eq '' and $dir = './';
   $var->requires_variables ("\@${lt}ALLOCA\@ used", $lt . 'ALLOCA');
diff --git a/t/list-of-tests.mk b/t/list-of-tests.mk
index dab4a7c..ebf9651 100644
--- a/t/list-of-tests.mk
+++ b/t/list-of-tests.mk
@@ -38,7 +38,6 @@ t/override-conditional-pr13940.sh \
 t/dist-pr109765.sh \
 t/instdir-cond2.sh \
 t/java-nobase.sh \
-t/libobj-no-dependency-tracking.sh \
 t/objext-pr10128.sh \
 t/remake-timing-bug-pr8365.sh \
 t/lex-subobj-nodep.sh \
-- 
2.9.5

Tell me if that's OK with you.

Sorry for the delay.

-- 
Mathieu Lirzin
GPG: F2A3 8D7E EB2B 6640 5761  070D 0ADE E100 9460 4D37