cond-late.mk revision 1.7
11.7Srillig# $NetBSD: cond-late.mk,v 1.7 2024/06/30 13:01:01 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.3Srillig# If the order of evaluation were to change to first parse the condition
271.3Srillig# and then expand the variables, the output would change from the
281.3Srillig# current "yes no" to "yes yes", since both variables are non-empty.
291.4Srillig# expect: yes
301.4Srillig# expect: no
311.2Srilligcond-literal:
321.1Srillig	@echo ${ ${COND.true} :?yes:no}
331.1Srillig	@echo ${ ${COND.false} :?yes:no}
341.2Srillig
351.7Srillig.if make(do-parse-time)
361.4SrilligVAR=	${${UNDEF} != "no":?:}
371.7Srillig# expect+1: while evaluating variable "VAR": while evaluating condition " != "no"": Bad condition
381.7Srillig.  if empty(VAR:Mpattern)
391.7Srillig.  endif
401.2Srillig.endif
41