1# $NetBSD: modmisc.mk,v 1.52 2020/12/20 19:29:06 rillig Exp $ 2# 3# miscellaneous modifier tests 4 5# do not put any dirs in this list which exist on some 6# but not all target systems - an exists() check is below. 7path= :/bin:/tmp::/:.:/no/such/dir:. 8# strip cwd from path. 9MOD_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. 12MOD_NODOTX= S/:/ /g:N.:@d@'$$d'@ 13# another mod - pretend it is more interesting 14MOD_HOMES= S,/home/,/homes/, 15MOD_OPT= @d@$${exists($$d):?$$d:$${d:S,/usr,/opt,}}@ 16MOD_SEP= S,:, ,g 17 18all: modvar modvarloop modsysv emptyvar undefvar 19all: mod-quote 20all: mod-break-many-words 21 22# See also sysv.mk. 23modsysv: 24 @echo "The answer is ${libfoo.a:L:libfoo.a=42}" 25 26# Demonstrates modifiers that are given indirectly from a variable. 27modvar: 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:}" 33 34.for d in ${path:${MOD_SEP}:N.} /usr/xbin 35path_$d?= ${d:${MOD_OPT}:${MOD_HOMES}}/ 36paths+= ${d:${MOD_OPT}:${MOD_HOMES}} 37.endfor 38 39modvarloop: 40 @echo "path_/usr/xbin=${path_/usr/xbin}" 41 @echo "paths=${paths}" 42 @echo "PATHS=${paths:tu}" 43 44# When a modifier is applied to the "" variable, the result is discarded. 45emptyvar: 46 @echo S:${:S,^$,empty,} 47 @echo C:${:C,^$,empty,} 48 @echo @:${:@var@${var}@} 49 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. 54undefvar: 55 @echo S:${:U:S,^$,empty,} 56 @echo C:${:U:C,^$,empty,} 57 @echo @:${:U:@var@empty@} 58 59 60mod-quote: 61 @echo $@: new${.newline:Q}${.newline:Q}line 62 63# Cover the bmake_realloc in Str_Words. 64mod-break-many-words: 65 @echo $@: ${UNDEF:U:range=500:[#]} 66