xref: /freebsd/contrib/bmake/unit-tests/cond-late.mk (revision fd0e6af5e49c3db034f1c45ff3f053f282e758c3)
1# $NetBSD: cond-late.mk,v 1.8 2024/07/04 17:47:54 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: parse-time cond-literal
19
20parse-time: .PHONY
21	@${MAKE} -f ${MAKEFILE} do-parse-time || true
22
23COND.true=	"yes" == "yes"
24COND.false=	"yes" != "yes"
25
26# If the order of evaluation were to change to first parse the condition
27# and then expand the variables, the output would change from the
28# current "yes no" to "yes yes", since both variables are non-empty.
29# expect: yes
30# expect: no
31cond-literal:
32	@echo ${ ${COND.true} :?yes:no}
33	@echo ${ ${COND.false} :?yes:no}
34
35.if make(do-parse-time)
36VAR=	${${UNDEF} != "no":?:}
37# expect+1: while evaluating variable "VAR" with value "${${UNDEF} != "no":?:}": while evaluating condition " != "no"": Bad condition
38.  if empty(VAR:Mpattern)
39.  endif
40.endif
41