freebsd-src/unit-tests/cond-late.mk
Simon J. Gerraty 945078deae Import bmake-20230510
Relevant/interesting changes:

	o parse.c: don't print null filename in stack traces
	o for.c: skip syntactically wrong .for loops
	o var.c: allow for :gmtime=${mtime}
	add :mtime[=timestamp] where timestamp is used if stat(2)
	fails, if :mtime=error stat(2) failure causes error.
	o make.1: fix documentation of .PREFIX to match reality and POSIX
	o unit-tests: improved var-scope-local
2023-05-13 10:03:50 -07:00

37 lines
1.2 KiB
Makefile

# $NetBSD: cond-late.mk,v 1.4 2023/05/10 15:53:32 rillig Exp $
#
# Using the :? modifier, variable expressions can contain conditional
# expressions that are evaluated late, at expansion time.
#
# Any expressions appearing in these conditions are expanded before parsing
# the condition. This is different from conditions in .if directives, where
# expressions are evaluated individually and only as far as necessary, see
# cond-short.mk.
#
# Because of this, variables that are used in these lazy conditions
# should not contain double-quotes, or the parser will probably fail.
#
# They should also not contain operators like == or <, since these are
# actually interpreted as these operators. This is demonstrated below.
#
all: cond-literal
COND.true= "yes" == "yes"
COND.false= "yes" != "yes"
# If the order of evaluation were to change to first parse the condition
# and then expand the variables, the output would change from the
# current "yes no" to "yes yes", since both variables are non-empty.
# expect: yes
# expect: no
cond-literal:
@echo ${ ${COND.true} :?yes:no}
@echo ${ ${COND.false} :?yes:no}
VAR= ${${UNDEF} != "no":?:}
# expect-reset
# expect: make: Bad conditional expression ' != "no"' in ' != "no"?:'
.if empty(VAR:Mpattern)
.endif