xref: /freebsd/contrib/bmake/unit-tests/cond-late.mk (revision a8c56be47166295d37600ff81fc1857db87b3a9b)
1# $NetBSD: cond-late.mk,v 1.10 2025/06/30 21:44:39 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 make(do-parse-time)
27VAR=	${${UNDEF} != "no":?:}
28# expect+1: Bad condition
29.  if empty(VAR:Mpattern)
30.  endif
31.endif
32
33# If the order of evaluation were to change to first parse the condition
34# and then expand the variables, the output would change from the
35# current "yes no" to "yes yes", since both variables are non-empty.
36# expect: yes
37# expect: no
38cond-literal:
39	@echo ${ ${COND.true} :?yes:no}
40	@echo ${ ${COND.false} :?yes:no}
41