cond-late.mk revision 1.4
11.4Srillig# $NetBSD: cond-late.mk,v 1.4 2023/05/10 15:53:32 rillig Exp $
21.1Srillig#
31.1Srillig# Using the :? modifier, variable expressions can contain conditional
41.3Srillig# expressions that are evaluated late, at expansion time.
51.3Srillig#
61.4Srillig# Any expressions appearing in these conditions are expanded before parsing
71.4Srillig# the condition.  This is different from conditions in .if directives, where
81.4Srillig# expressions are evaluated individually and only as far as necessary, see
91.4Srillig# cond-short.mk.
101.1Srillig#
111.1Srillig# Because of this, variables that are used in these lazy conditions
121.1Srillig# should not contain double-quotes, or the parser will probably fail.
131.1Srillig#
141.1Srillig# They should also not contain operators like == or <, since these are
151.1Srillig# actually interpreted as these operators. This is demonstrated below.
161.1Srillig#
171.1Srillig
181.2Srilligall: cond-literal
191.2Srillig
201.1SrilligCOND.true=	"yes" == "yes"
211.1SrilligCOND.false=	"yes" != "yes"
221.1Srillig
231.3Srillig# If the order of evaluation were to change to first parse the condition
241.3Srillig# and then expand the variables, the output would change from the
251.3Srillig# current "yes no" to "yes yes", since both variables are non-empty.
261.4Srillig# expect: yes
271.4Srillig# expect: no
281.2Srilligcond-literal:
291.1Srillig	@echo ${ ${COND.true} :?yes:no}
301.1Srillig	@echo ${ ${COND.false} :?yes:no}
311.2Srillig
321.4SrilligVAR=	${${UNDEF} != "no":?:}
331.4Srillig# expect-reset
341.4Srillig# expect: make: Bad conditional expression ' != "no"' in ' != "no"?:'
351.2Srillig.if empty(VAR:Mpattern)
361.2Srillig.endif
37