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