Subject: bug#27781: LIBOBJS should depend on LIBOBJDIR

From: Mathieu Lirzin <[email-masked]>
Date: Sun, 27 Aug 2017 16:07:58 +0200

Michael Haubenwallner <[email-masked]> writes:

> On 08/23/2017 11:24 PM, Mathieu Lirzin wrote:
>> Michael Haubenwallner <[email-masked]> writes:
>>> On 08/22/2017 12:40 AM, Mathieu Lirzin wrote:
>>>> Michael Haubenwallner <[email-masked]> writes:
>>>>
>>>>>        # If LTLIBOBJS is used, we must also clear LIBOBJS (which might
>>>>>        # be created by libtool as a side-effect of creating LTLIBOBJS).
>>>>> -      $clean_files{"\$($var)"} = MOSTLY_CLEAN if $var =~ s/^LT//;
>>>>> +      if ($var =~ s/^LT//) {
>>>>> +	$clean_files{"\$($var)"} = MOSTLY_CLEAN;
>>>>> +	$output_rules .= "\$($var): $dirstamp\n" if ($dirstamp);
>>>>> +      }
>>>>>      }
>>>>>  
>>>>>    return $dir;
>>>
>> 
>> Regarding that part of the code even before you made it seems to me that
>> the conditional second '$clean_files{"\$($var)"} = MOSTLY_CLEAN'
>> statement is useless. Am I overlooking something?
> It took a while for me too to understand what's going on here:
>
> Consider $var = 'LTLIBOBJS';
>
>> Here is the snippet of the code before your changed.
>> 
>> --8<---------------cut here---------------start------------->8---
>> 	  define_variable ('LIBOBJDIR', "$dir", INTERNAL);
>> 	  $clean_files{"\$($var)"} = MOSTLY_CLEAN;
>
> here, unconditionally: $clean_files{'$(LTLIBOBJS)'} = MOSTLY_CLEAN;
>
>> 	  # If LTLIBOBJS is used, we must also clear LIBOBJS (which might
>> 	  # be created by libtool as a side-effect of creating LTLIBOBJS).
>> 	  $clean_files{"\$($var)"} = MOSTLY_CLEAN if $var =~ s/^LT//;
>
> Crucial here is that trailing { if $var =~ s/^LT// }:
> First, leading 'LT' eventually is dropped: $var = 'LIBOBJS';
> If the leading 'LT' was actually found: $clean_files{'LIBOBJS'} = MOSTLY_CLEAN;

I overlooked the regexp substitution.  This code is too complex for what it
achieves.  I have pushed the following patch in commit
5521219348c55af354878583b99c5f9d66d6d38a

>From 5521219348c55af354878583b99c5f9d66d6d38a Mon Sep 17 00:00:00 2001
From: Mathieu Lirzin <[email-masked]>
Date: Sun, 27 Aug 2017 15:27:00 +0200
Subject: [PATCH] automake: Handle LTLIBOBJS more specifically

* bin/automake.in (handle_LIBOBJS_or_ALLOCA): Remove complex regexp
substitution when handling LTLIBOBJS.
---
 bin/automake.in | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/bin/automake.in b/bin/automake.in
index d126836..cdea388 100644
--- a/bin/automake.in
+++ b/bin/automake.in
@@ -2306,9 +2306,8 @@ sub handle_LIBOBJS_or_ALLOCA
 	    if $relative_dir ne '.';
 	  define_variable ('LIBOBJDIR', "$dir", INTERNAL);
 	  $clean_files{"\$($var)"} = MOSTLY_CLEAN;
-	  # If LTLIBOBJS is used, we must also clear LIBOBJS (which might
-	  # be created by libtool as a side-effect of creating LTLIBOBJS).
-	  $clean_files{"\$($var)"} = MOSTLY_CLEAN if $var =~ s/^LT//;
+	  # libtool might create LIBOBJS as a side-effect of using LTLIBOBJS.
+	  $clean_files{"\$(LIBOBJS)"} = MOSTLY_CLEAN if $var eq "LTLIBOBJS";
 	}
       else
 	{
-- 
2.9.5

Thanks for the explanation.

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