]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/bmake/unit-tests/cond-late.mk
Merge bmake-20201117
[FreeBSD/FreeBSD.git] / contrib / bmake / unit-tests / cond-late.mk
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
17 all: cond-literal
18
19 COND.true=      "yes" == "yes"
20 COND.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.
25 cond-literal:
26         @echo ${ ${COND.true} :?yes:no}
27         @echo ${ ${COND.false} :?yes:no}
28
29 VAR+=   ${${UNDEF} != "no":?:}
30 .if empty(VAR:Mpattern)
31 .endif