1 # $NetBSD: modmisc.mk,v 1.51 2020/11/15 20:20:58 rillig Exp $
3 # miscellaneous modifier tests
5 # do not put any dirs in this list which exist on some
6 # but not all target systems - an exists() check is below.
7 path= :/bin:/tmp::/:.:/no/such/dir:.
9 MOD_NODOT= S/:/ /g:N.:ts:
10 # and decorate, note that $'s need to be doubled. Also note that
11 # the modifier_variable can be used with other modifiers.
12 MOD_NODOTX= S/:/ /g:N.:@d@'$$d'@
13 # another mod - pretend it is more interesting
14 MOD_HOMES= S,/home/,/homes/,
15 MOD_OPT= @d@$${exists($$d):?$$d:$${d:S,/usr,/opt,}}@
18 all: modvar modvarloop modsysv emptyvar undefvar
20 all: mod-break-many-words
24 @echo "The answer is ${libfoo.a:L:libfoo.a=42}"
26 # Demonstrates modifiers that are given indirectly from a variable.
28 @echo "path='${path}'"
29 @echo "path='${path:${MOD_NODOT}}'"
30 @echo "path='${path:S,home,homes,:${MOD_NODOT}}'"
31 @echo "path=${path:${MOD_NODOTX}:ts:}"
32 @echo "path=${path:${MOD_HOMES}:${MOD_NODOTX}:ts:}"
34 .for d in ${path:${MOD_SEP}:N.} /usr/xbin
35 path_$d?= ${d:${MOD_OPT}:${MOD_HOMES}}/
36 paths+= ${d:${MOD_OPT}:${MOD_HOMES}}
40 @echo "path_/usr/xbin=${path_/usr/xbin}"
41 @echo "paths=${paths}"
42 @echo "PATHS=${paths:tu}"
44 # When a modifier is applied to the "" variable, the result is discarded.
46 @echo S:${:S,^$,empty,}
47 @echo C:${:C,^$,empty,}
48 @echo @:${:@var@${var}@}
50 # The :U modifier turns even the "" variable into something that has a value.
51 # The value of the resulting expression is empty, but is still considered to
52 # contain a single empty word. This word can be accessed by the :S and :C
53 # modifiers, but not by the :@ modifier since it explicitly skips empty words.
55 @echo S:${:U:S,^$,empty,}
56 @echo C:${:U:C,^$,empty,}
57 @echo @:${:U:@var@empty@}
61 @echo $@: new${.newline:Q}${.newline:Q}line
63 # Cover the bmake_realloc in Str_Words.
65 @echo $@: ${UNDEF:U:range=500:[#]}
67 # To apply a modifier indirectly via another variable, the whole
68 # modifier must be put into a single variable expression.
69 .if ${value:L:${:US}${:U,value,replacement,}} != "S,value,replacement,}"
73 # Adding another level of indirection (the 2 nested :U expressions) helps.
74 .if ${value:L:${:U${:US}${:U,value,replacement,}}} != "replacement"
78 # Multiple indirect modifiers can be applied one after another as long as
79 # they are separated with colons.
80 .if ${value:L:${:US,a,A,}:${:US,e,E,}} != "vAluE"
84 # An indirect variable that evaluates to the empty string is allowed though.
85 # This makes it possible to define conditional modifiers, like this:
87 # M.little-endian= S,1234,4321,
88 # M.big-endian= # none
89 .if ${value:L:${:Dempty}S,a,A,} != "vAlue"