Makefile .for and .if expansion

Kris Kennaway kris at obsecurity.org
Sat Feb 12 18:45:26 PST 2005


On Sat, Feb 12, 2005 at 06:32:01PM -0800, Kris Kennaway wrote:
> The following small makefile doesn't behave as one would naively
> expect:
> 
> MANLANG?=foo ""
> all:
> .for i in ${MANLANG}
> .if empty(${i})
>         @echo foo ${i}
> .endif
> .endfor
> 
> ports-i386%make
> foo foo
> foo
> 
> I think this is because the .if evaluation is happening too early, and
> it's not being done after the .for loop is expanded and the i variable
> is set.

Actually it looks like it's happening too late:

For: Iterator i List foo ""
For: end for 1
Global:i = ""
--- i = ""
.if empty(i)
        @echo foo ""
.endif

---- at line 3
Global:delete i
Global:i = foo
--- i = foo
.if empty(i)
        @echo foo foo
.endif

---- at line 3
Global:delete i

i.e. the series of .if statements are expanded out by .for and then
the variable i is deleted, so by the time the .if is evaluated the
unset variable evaluates to empty.

Kris
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20050212/a31eb591/attachment.bin


More information about the freebsd-hackers mailing list