make(1) is broken?
John Baldwin
jhb at freebsd.org
Thu Aug 10 14:34:40 UTC 2006
On Thursday 10 August 2006 06:08, Stanislav Sedov wrote:
> Hi!
>
> I have a strange problem linked with make(1)
>
> Consider the following Makefile:
> ---------------------------------------------------------------
> COMPS=aa ab ac
> AA=aa
>
> VAR1=${COMPS:Maa}
> VAR2=${COMPS:M${AA}}
>
> .for COMP in ${AA}
> VAR3=${COMPS:M${COMP}}
> .endfor
> ---------------------------------------------------------------
>
> Now, running make(1) gives:
> % make -V VAR1
> aa
> % make -V VAR2
> }
> % make -V VAR3
> aa
>
> Results for VAR2 seems quite strange for me. It looks like
> ${COMP}!=${AA}
>
> So, the question: is make(1) broken, or it's my misunderstanding?
>
> Any help greatly appreciated. Thanks!
I think it's your misunderstanding, when you do .for, make expands
$COMP to generate more lines that it then later evaluates, so with the
.for expanded you get:
COMPS=
AA=
VAR1=${COMPS:Maa}
VAR2=${COMPS:M${AA}}
VAR3=${COMPS:Maa}
Then when make evaluates VAR2, it doesn't expand ${AA} but tries to
match that substring ('${AA}') in COMPS. Actually, though, it's less
obvious than that, as since it isn't looking to do variable expansion
in an M modifier, it ends the $COMPS expansion when it sees the first },
so what you end up with is this:
VAR2='${COMPS:M${AA}'}
That is, it tries to match the substring '${AA' in ${COMPS} and then
appends a '}' character to that, which gives the '}' result you saw.
--
John Baldwin
More information about the freebsd-hackers
mailing list