Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 10 Aug 2006 10:34:24 -0400
From:      John Baldwin <jhb@freebsd.org>
To:        freebsd-hackers@freebsd.org
Cc:        ports@freebsd.org, Stanislav Sedov <ssedov@mbsd.msk.ru>
Subject:   Re: make(1) is broken?
Message-ID:  <200608101034.24589.jhb@freebsd.org>
In-Reply-To: <20060810160836.40eb4128@localhost>
References:  <20060810160836.40eb4128@localhost>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200608101034.24589.jhb>