On Thu, May 20, 2010 at 2:58 AM, Joachim Schipper
<[email protected]> wrote:
> On Thu, May 20, 2010 at 11:11:51AM +0200, Joachim Schipper wrote:
>> Makefile:
>>
>> A=This is the variable A
>> FOO=$$A
>> BAR:=$$A
>>
>> test:
>>       echo '${FOO}'
>>       echo '${BAR}'
>>
>> I expected, and GNU make gives,
>>
>> echo '$A'
>> $A
>> echo '$A'
>> $A
>>
>> However, our make gives
>>
>> echo '$A'
>> $A
>> echo 'This is the variable A'
>> This is the variable A
>>
>> Is this sensible, a historical accident that should be preserved, or a
>> bug? I, at least, was rather surprised...
>
> An addendum to the above: := really does expand exactly twice (and not
> "until done"), although this is not obvious from the above.

Yuck.  So they're really two different definitions for ":=", where BSD
make defines it as "expand the value once immediately, then continue
as with '='" contrasted with GNU make's definition of "expand the
value immediately and then suppress further expansion".

Furthermore, GNU make marks the variable as needing immediate
expansion if used with '+=', where BSD make instead has the
(undocumented!) ':+=' and '+:=' operators.  Consider:

-----
A=$$B
B=b
FOO1=$$A $A
FOO2=
FOO2+=$$A $A
BAR1:=$$A $A
BAR2:=
BAR2+=$$A $A

A=after

test:
        @echo '${FOO1}'
        @echo '${FOO2}'
        @echo '${BAR1}'
        @echo '${BAR2}'
----

prompt$ make
$A after
 $A after
after b
 $A after
prompt$ gmake
$A after
 $A after
$A $B
 $A $B

 <ponder>

As clean as the BSD model is, I cannot recall ever needing multiple
rounds of expansion like this and suspect the double expansion to be
unwise and unsafe in general.  Does anyone actually have a use case
for this or can it be considered a bug and fixed?  (I wonder if the
ports makefiles depend on this...)


Philip Guenther

Reply via email to