tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Make's empty(), defined() and .ifdef don't catch outer .for iterators



Am 08.07.2026 03:22:35 schrieb Kogule Ryo :

> Hi forks,
>
> Make's empty() does not catch outer .for iterators.
>
>> .for i in yes no
>> .  if !empty(i:M[Yy][Ee][Ss])
>> output+=    yes
>> .  endif
>> .endfor
>
> defined() and .ifdef do the same.  Is this behavior intentional?

Is rather say accepted than intended. It is a consequence of how the .for loops are implemented. When evaluating a .for loop, text that looks like an expression of the form ${i:…} is expanded textually before processing the lines of the body of the .for loop.

This limitation is not documented in the manual page, though. It would even be possible to fix it by creating temporary variables during iteration. Up to now, the pressure to do this was not high enough to get this edge case fixed.

The usual workaround is to write this instead:

.if ${i:M[Yy][Ee][Ss]}

Or, even shorter:

.if ${i:tl} == "yes"

See usr.bin/make/unit-tests/directive-for-empty.mk for a more detailed explanation.

Roland


Home | Main Index | Thread Index | Old Index