11.10Srillig# $NetBSD: cond-late.mk,v 1.10 2025/06/30 21:44:39 rillig Exp $
21.1Srillig#
31.5Srillig# Using the :? modifier, 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.7Srilligall: parse-time cond-literal
191.7Srillig
201.7Srilligparse-time: .PHONY
211.7Srillig	@${MAKE} -f ${MAKEFILE} do-parse-time || true
221.2Srillig
231.1SrilligCOND.true=	"yes" == "yes"
241.1SrilligCOND.false=	"yes" != "yes"
251.1Srillig
261.10Srillig.if make(do-parse-time)
271.10SrilligVAR=	${${UNDEF} != "no":?:}
281.10Srillig# expect+1: Bad condition
291.10Srillig.  if empty(VAR:Mpattern)
301.10Srillig.  endif
311.10Srillig.endif
321.10Srillig
331.3Srillig# If the order of evaluation were to change to first parse the condition
341.3Srillig# and then expand the variables, the output would change from the
351.3Srillig# current "yes no" to "yes yes", since both variables are non-empty.
361.4Srillig# expect: yes
371.4Srillig# expect: no
381.2Srilligcond-literal:
391.1Srillig	@echo ${ ${COND.true} :?yes:no}
401.1Srillig	@echo ${ ${COND.false} :?yes:no}
41