2020-11-20 03:54:37 +00:00
|
|
|
# $NetBSD: cond-late.mk,v 1.3 2020/11/15 14:07:53 rillig Exp $
|
2020-05-20 19:34:48 +00:00
|
|
|
#
|
|
|
|
# Using the :? modifier, variable expressions can contain conditional
|
2020-11-20 03:54:37 +00:00
|
|
|
# expressions that are evaluated late, at expansion time.
|
|
|
|
#
|
|
|
|
# Any variables appearing in these
|
2020-05-20 19:34:48 +00:00
|
|
|
# conditions are expanded before parsing the condition. This is
|
|
|
|
# different from many other places.
|
|
|
|
#
|
|
|
|
# Because of this, variables that are used in these lazy conditions
|
|
|
|
# should not contain double-quotes, or the parser will probably fail.
|
|
|
|
#
|
|
|
|
# They should also not contain operators like == or <, since these are
|
|
|
|
# actually interpreted as these operators. This is demonstrated below.
|
|
|
|
#
|
|
|
|
|
2020-09-05 16:11:04 +00:00
|
|
|
all: cond-literal
|
|
|
|
|
2020-05-20 19:34:48 +00:00
|
|
|
COND.true= "yes" == "yes"
|
|
|
|
COND.false= "yes" != "yes"
|
|
|
|
|
2020-11-20 03:54:37 +00:00
|
|
|
# If the order of evaluation were to change to first parse the condition
|
|
|
|
# and then expand the variables, the output would change from the
|
|
|
|
# current "yes no" to "yes yes", since both variables are non-empty.
|
2020-09-05 16:11:04 +00:00
|
|
|
cond-literal:
|
2020-05-20 19:34:48 +00:00
|
|
|
@echo ${ ${COND.true} :?yes:no}
|
|
|
|
@echo ${ ${COND.false} :?yes:no}
|
2020-09-05 16:11:04 +00:00
|
|
|
|
|
|
|
VAR+= ${${UNDEF} != "no":?:}
|
|
|
|
.if empty(VAR:Mpattern)
|
|
|
|
.endif
|