1 # $Id: varmisc.mk,v 1.11 2020/07/02 15:43:43 sjg Exp $
3 # Miscellaneous variable tests.
5 all: unmatched_var_paren D_true U_true D_false U_false Q_lhs Q_rhs NQ_none \
9 @echo ${foo::=foo-text}
11 True = ${echo true >&2:L:sh}TRUE
12 False= ${echo false >&2:L:sh}FALSE
18 @echo :U skipped when var set
19 @echo ${VSET:U${False}}
22 @echo :D skipped if var undef
23 @echo ${UNDEF:D${False}}
26 @echo :U expanded when var undef
27 @echo ${UNDEF:U${True}}
30 @echo :D expanded when var set
31 @echo ${VSET:D${True}}
34 @echo :? only lhs when value true
35 @echo ${1:L:?${True}:${False}}
38 @echo :? only rhs when value false
39 @echo ${0:L:?${True}:${False}}
42 @echo do not evaluate or expand :? if discarding
43 @echo ${VSET:U${1:L:?${True}:${False}}}
47 # slightly contorted syntax to use utc via variable
49 @echo ${year=%Y month=%m day=%d:L:gmtime=1459494000}
50 @echo date=${%Y%m%d:L:${gmtime=${April1}:L}}
52 # big jumps to handle 3 digits per step
53 M_cmpv.units = 1 1000 1000000
54 M_cmpv = S,., ,g:_:range:@i@+ $${_:[-$$i]} \* $${M_cmpv.units:[$$i]}@:S,^,expr 0 ,1:sh
57 cmpv.only = target specific vars
60 @echo Version=${Version} == ${Version:${M_cmpv}}
61 @echo Literal=3.4.5 == ${3.4.5:L:${M_cmpv}}
62 @echo We have ${${.TARGET:T}.only}
64 # catch misshandling of nested vars in .for loop
68 .if defined(MAN$s) && !empty(MAN$s)
76 # This is an expanded variant of the above .for loop.
77 # Between 2020-08-28 and 2020-07-02 this paragraph generated a wrong
78 # error message "Variable VARNAME is recursive".
79 # When evaluating the !empty expression, the ${:U1} was not expanded and
80 # thus resulted in the seeming definition VARNAME=${VARNAME}, which is
81 # obviously recursive.
82 VARNAME= ${VARNAME${:U1}}
83 .if defined(VARNAME${:U2}) && !empty(VARNAME${:U2})