xref: /freebsd/contrib/bmake/unit-tests/cond-late.mk (revision dd41de95a84d979615a2ef11df6850622bf6184e)
1# $NetBSD: cond-late.mk,v 1.3 2020/11/15 14:07:53 rillig Exp $
2#
3# Using the :? modifier, variable expressions can contain conditional
4# expressions that are evaluated late, at expansion time.
5#
6# Any variables appearing in these
7# conditions are expanded before parsing the condition.  This is
8# different from many other places.
9#
10# Because of this, variables that are used in these lazy conditions
11# should not contain double-quotes, or the parser will probably fail.
12#
13# They should also not contain operators like == or <, since these are
14# actually interpreted as these operators. This is demonstrated below.
15#
16
17all: cond-literal
18
19COND.true=	"yes" == "yes"
20COND.false=	"yes" != "yes"
21
22# If the order of evaluation were to change to first parse the condition
23# and then expand the variables, the output would change from the
24# current "yes no" to "yes yes", since both variables are non-empty.
25cond-literal:
26	@echo ${ ${COND.true} :?yes:no}
27	@echo ${ ${COND.false} :?yes:no}
28
29VAR+=	${${UNDEF} != "no":?:}
30.if empty(VAR:Mpattern)
31.endif
32