1 # $NetBSD: varmod-ifelse.mk,v 1.5 2020/10/23 14:24:51 rillig Exp $
3 # Tests for the ${cond:?then:else} variable modifier, which evaluates either
4 # the then-expression or the else-expression, depending on the condition.
6 # The modifier was added on 1998-04-01.
8 # Until 2015-10-11, the modifier always evaluated both the "then" and the
11 # TODO: Implementation
13 # The variable name of the expression is expanded and then taken as the
14 # condition. In this case it becomes:
16 # variable expression == "variable expression"
18 # This confuses the parser, which expects an operator instead of the bare
19 # word "expression". If the name were expanded lazily, everything would be
20 # fine since the condition would be:
22 # ${:Uvariable expression} == "literal"
24 # Evaluating the variable name lazily would require additional code in
25 # Var_Parse and ParseVarname, it would be more useful and predictable
27 .if ${${:Uvariable expression} == "literal":?bad:bad}
33 # In a variable assignment, undefined variables are not an error.
34 # Because of the early expansion, the whole condition evaluates to
35 # ' == ""' though, which cannot be parsed because the left-hand side looks
37 COND:= ${${UNDEF} == "":?bad-assign:bad-assign}
39 # In a condition, undefined variables generate a "Malformed conditional"
40 # error. That error message is wrong though. In lint mode, the correct
41 # "Undefined variable" error message is generated.
42 # The difference to the ':=' variable assignment is the additional
43 # "Malformed conditional" error message.
44 .if ${${UNDEF} == "":?bad-cond:bad-cond}
50 # When the :? is parsed, it is greedy. The else branch spans all the
51 # text, up until the closing character '}', even if the text looks like
53 .if ${1:?then:else:Q} != "then"
56 .if ${0:?then:else:Q} != "else:Q"