On Wed, May 26, 2010 at 09:15:32PM -0700, Philip Guenther wrote:
> 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...)
This behaviour annoyed me when I wanted to do something like
PKG_PATH:=`echo '${PKG_PATH}' | sed -re 's/:?$$/:foo/'`
This works fine with GNU make, but BSD make requires
PKG_PATH:=`echo '${PKG_PATH}' | sed -re 's/:?$$$$/:foo/'`
but also accepts $$$.
Would a patch for this be desirable? I have very limited hacking time,
but I could try to come up with something over the weekend/next week. It
should, of course, be extensively tested before applying.
(OTOH, the current behaviour is sufficiently surprising that I'd expect
any Makefiles not explicitly written for BSD make to assume the GNU
behaviour.)
Joachim