1# $Id: varmisc.mk,v 1.9 2017/02/01 18:44:54 sjg Exp $
2#
3# Miscellaneous variable tests.
4
5all: unmatched_var_paren D_true U_true D_false U_false Q_lhs Q_rhs NQ_none \
6	strftime cmpv
7
8unmatched_var_paren:
9	@echo ${foo::=foo-text}
10
11True = ${echo true >&2:L:sh}TRUE
12False= ${echo false >&2:L:sh}FALSE
13
14VSET= is set
15.undef UNDEF
16
17U_false:
18	@echo :U skipped when var set
19	@echo ${VSET:U${False}}
20
21D_false:
22	@echo :D skipped if var undef
23	@echo ${UNDEF:D${False}}
24
25U_true:
26	@echo :U expanded when var undef
27	@echo ${UNDEF:U${True}}
28
29D_true:
30	@echo :D expanded when var set
31	@echo ${VSET:D${True}}
32
33Q_lhs:
34	@echo :? only lhs when value true
35	@echo ${1:L:?${True}:${False}}
36
37Q_rhs:
38	@echo :? only rhs when value false
39	@echo ${0:L:?${True}:${False}}
40
41NQ_none:
42	@echo do not evaluate or expand :? if discarding
43	@echo ${VSET:U${1:L:?${True}:${False}}}
44
45April1= 1459494000
46
47# slightly contorted syntax to use utc via variable
48strftime:
49	@echo ${year=%Y month=%m day=%d:L:gmtime=1459494000}
50	@echo date=${%Y%m%d:L:${gmtime=${April1}:L}}
51
52# big jumps to handle 3 digits per step
53M_cmpv.units = 1 1000 1000000
54M_cmpv = S,., ,g:_:range:@i@+ $${_:[-$$i]} \* $${M_cmpv.units:[$$i]}@:S,^,expr 0 ,1:sh
55
56Version = 123.456.789
57cmpv.only = target specific vars
58
59cmpv:
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}
63