1 # $Id: modmisc.mk,v 1.1.1.2 2020/07/04 17:52:46 sjg 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 mod-HTE emptyvar undefvar
19 all: mod-S mod-C mod-at-varname mod-at-resolve
22 @echo "The answer is ${libfoo.a:L:libfoo.a=42}"
25 @echo "path='${path}'"
26 @echo "path='${path:${MOD_NODOT}}'"
27 @echo "path='${path:S,home,homes,:${MOD_NODOT}}'"
28 @echo "path=${path:${MOD_NODOTX}:ts:}"
29 @echo "path=${path:${MOD_HOMES}:${MOD_NODOTX}:ts:}"
31 .for d in ${path:${MOD_SEP}:N.} /usr/xbin
32 path_$d?= ${d:${MOD_OPT}:${MOD_HOMES}}/
33 paths+= ${d:${MOD_OPT}:${MOD_HOMES}}
37 @echo "path_/usr/xbin=${path_/usr/xbin}"
38 @echo "paths=${paths}"
39 @echo "PATHS=${paths:tu}"
41 PATHNAMES= a/b/c def a.b.c a.b/c a a.a .gitignore a a.a
43 @echo "dirname of '"${PATHNAMES:Q}"' is '"${PATHNAMES:H:Q}"'"
44 @echo "basename of '"${PATHNAMES:Q}"' is '"${PATHNAMES:T:Q}"'"
45 @echo "suffix of '"${PATHNAMES:Q}"' is '"${PATHNAMES:E:Q}"'"
46 @echo "root of '"${PATHNAMES:Q}"' is '"${PATHNAMES:R:Q}"'"
48 # When a modifier is applied to the "" variable, the result is discarded.
50 @echo S:${:S,^$,empty,}
51 @echo C:${:C,^$,empty,}
52 @echo @:${:@var@${var}@}
54 # The :U modifier turns even the "" variable into something that has a value.
55 # The resulting variable is empty, but is still considered to contain a
56 # single empty word. This word can be accessed by the :S and :C modifiers,
57 # but not by the :@ modifier since it explicitly skips empty words.
59 @echo S:${:U:S,^$,empty,}
60 @echo C:${:U:C,^$,empty,}
61 @echo @:${:U:@var@empty@}
64 @echo :${:Ua b b c:S,a b,,:Q}:
65 @echo :${:Ua b b c:S,a b,,1:Q}:
66 @echo :${:Ua b b c:S,a b,,W:Q}:
67 @echo :${:Ua b b c:S,b,,g:Q}:
68 @echo :${:U1 2 3 1 2 3:S,1 2,___,Wg:S,_,x,:Q}:
71 @echo :${:Ua b b c:C,a b,,:Q}:
72 @echo :${:Ua b b c:C,a b,,1:Q}:
73 @echo :${:Ua b b c:C,a b,,W:Q}:
74 @echo :${:Uword1 word2:C,****,____,g:C,word,____,:Q}:
75 @echo :${:Ua b b c:C,b,,g:Q}:
76 @echo :${:U1 2 3 1 2 3:C,1 2,___,Wg:C,_,x,:Q}:
78 # In the :@ modifier, the name of the loop variable can even be generated
79 # dynamically. There's no practical use-case for this, and hopefully nobody
80 # will ever depend on this, but technically it's possible.
82 @echo :${:Uone two three:@${:Ubar:S,b,v,}@+${var}+@:Q}:
84 # The :@ modifier resolves the variables a little more often than expected.
85 # In particular, it resolves _all_ variables from the context, and not only
86 # the loop variable (in this case v).
88 # The d means direct reference, the i means indirect reference.
89 RESOLVE= ${RES1} $${RES1}
90 RES1= 1d${RES2} 1i$${RES2}
91 RES2= 2d${RES3} 2i$${RES3}
95 @echo $@:${RESOLVE:@v@w${v}w@:Q}: