1*e2eeea75SSimon J. Gerraty# $NetBSD: modmisc.mk,v 1.51 2020/11/15 20:20:58 rillig Exp $ 2db29cad8SSimon J. Gerraty# 3db29cad8SSimon J. Gerraty# miscellaneous modifier tests 4db29cad8SSimon J. Gerraty 5db29cad8SSimon J. Gerraty# do not put any dirs in this list which exist on some 6db29cad8SSimon J. Gerraty# but not all target systems - an exists() check is below. 7db29cad8SSimon J. Gerratypath= :/bin:/tmp::/:.:/no/such/dir:. 8db29cad8SSimon J. Gerraty# strip cwd from path. 9db29cad8SSimon J. GerratyMOD_NODOT= S/:/ /g:N.:ts: 10db29cad8SSimon J. Gerraty# and decorate, note that $'s need to be doubled. Also note that 11db29cad8SSimon J. Gerraty# the modifier_variable can be used with other modifiers. 12db29cad8SSimon J. GerratyMOD_NODOTX= S/:/ /g:N.:@d@'$$d'@ 13db29cad8SSimon J. Gerraty# another mod - pretend it is more interesting 14db29cad8SSimon J. GerratyMOD_HOMES= S,/home/,/homes/, 15db29cad8SSimon J. GerratyMOD_OPT= @d@$${exists($$d):?$$d:$${d:S,/usr,/opt,}}@ 16db29cad8SSimon J. GerratyMOD_SEP= S,:, ,g 17db29cad8SSimon J. Gerraty 182c3632d1SSimon J. Gerratyall: modvar modvarloop modsysv emptyvar undefvar 192c3632d1SSimon J. Gerratyall: mod-quote 202c3632d1SSimon J. Gerratyall: mod-break-many-words 21db29cad8SSimon J. Gerraty 222c3632d1SSimon J. Gerraty# See also sysv.mk. 23db29cad8SSimon J. Gerratymodsysv: 24db29cad8SSimon J. Gerraty @echo "The answer is ${libfoo.a:L:libfoo.a=42}" 25db29cad8SSimon J. Gerraty 262c3632d1SSimon J. Gerraty# Demonstrates modifiers that are given indirectly from a variable. 27db29cad8SSimon J. Gerratymodvar: 28db29cad8SSimon J. Gerraty @echo "path='${path}'" 29db29cad8SSimon J. Gerraty @echo "path='${path:${MOD_NODOT}}'" 30db29cad8SSimon J. Gerraty @echo "path='${path:S,home,homes,:${MOD_NODOT}}'" 31db29cad8SSimon J. Gerraty @echo "path=${path:${MOD_NODOTX}:ts:}" 32db29cad8SSimon J. Gerraty @echo "path=${path:${MOD_HOMES}:${MOD_NODOTX}:ts:}" 33db29cad8SSimon J. Gerraty 34db29cad8SSimon J. Gerraty.for d in ${path:${MOD_SEP}:N.} /usr/xbin 35db29cad8SSimon J. Gerratypath_$d?= ${d:${MOD_OPT}:${MOD_HOMES}}/ 36db29cad8SSimon J. Gerratypaths+= ${d:${MOD_OPT}:${MOD_HOMES}} 37db29cad8SSimon J. Gerraty.endfor 38db29cad8SSimon J. Gerraty 39db29cad8SSimon J. Gerratymodvarloop: 40db29cad8SSimon J. Gerraty @echo "path_/usr/xbin=${path_/usr/xbin}" 41db29cad8SSimon J. Gerraty @echo "paths=${paths}" 42db29cad8SSimon J. Gerraty @echo "PATHS=${paths:tu}" 433841c287SSimon J. Gerraty 443841c287SSimon J. Gerraty# When a modifier is applied to the "" variable, the result is discarded. 453841c287SSimon J. Gerratyemptyvar: 463841c287SSimon J. Gerraty @echo S:${:S,^$,empty,} 473841c287SSimon J. Gerraty @echo C:${:C,^$,empty,} 483841c287SSimon J. Gerraty @echo @:${:@var@${var}@} 493841c287SSimon J. Gerraty 503841c287SSimon J. Gerraty# The :U modifier turns even the "" variable into something that has a value. 51*e2eeea75SSimon J. Gerraty# The value of the resulting expression is empty, but is still considered to 52*e2eeea75SSimon J. Gerraty# contain a single empty word. This word can be accessed by the :S and :C 53*e2eeea75SSimon J. Gerraty# modifiers, but not by the :@ modifier since it explicitly skips empty words. 543841c287SSimon J. Gerratyundefvar: 553841c287SSimon J. Gerraty @echo S:${:U:S,^$,empty,} 563841c287SSimon J. Gerraty @echo C:${:U:C,^$,empty,} 573841c287SSimon J. Gerraty @echo @:${:U:@var@empty@} 583841c287SSimon J. Gerraty 593841c287SSimon J. Gerraty 602c3632d1SSimon J. Gerratymod-quote: 612c3632d1SSimon J. Gerraty @echo $@: new${.newline:Q}${.newline:Q}line 623841c287SSimon J. Gerraty 63*e2eeea75SSimon J. Gerraty# Cover the bmake_realloc in Str_Words. 642c3632d1SSimon J. Gerratymod-break-many-words: 652c3632d1SSimon J. Gerraty @echo $@: ${UNDEF:U:range=500:[#]} 663841c287SSimon J. Gerraty 672c3632d1SSimon J. Gerraty# To apply a modifier indirectly via another variable, the whole 68*e2eeea75SSimon J. Gerraty# modifier must be put into a single variable expression. 692c3632d1SSimon J. Gerraty.if ${value:L:${:US}${:U,value,replacement,}} != "S,value,replacement,}" 702c3632d1SSimon J. Gerraty. warning unexpected 712c3632d1SSimon J. Gerraty.endif 722c3632d1SSimon J. Gerraty 732c3632d1SSimon J. Gerraty# Adding another level of indirection (the 2 nested :U expressions) helps. 742c3632d1SSimon J. Gerraty.if ${value:L:${:U${:US}${:U,value,replacement,}}} != "replacement" 752c3632d1SSimon J. Gerraty. warning unexpected 762c3632d1SSimon J. Gerraty.endif 772c3632d1SSimon J. Gerraty 782c3632d1SSimon J. Gerraty# Multiple indirect modifiers can be applied one after another as long as 792c3632d1SSimon J. Gerraty# they are separated with colons. 802c3632d1SSimon J. Gerraty.if ${value:L:${:US,a,A,}:${:US,e,E,}} != "vAluE" 812c3632d1SSimon J. Gerraty. warning unexpected 822c3632d1SSimon J. Gerraty.endif 832c3632d1SSimon J. Gerraty 842c3632d1SSimon J. Gerraty# An indirect variable that evaluates to the empty string is allowed though. 852c3632d1SSimon J. Gerraty# This makes it possible to define conditional modifiers, like this: 863841c287SSimon J. Gerraty# 872c3632d1SSimon J. Gerraty# M.little-endian= S,1234,4321, 882c3632d1SSimon J. Gerraty# M.big-endian= # none 892c3632d1SSimon J. Gerraty.if ${value:L:${:Dempty}S,a,A,} != "vAlue" 902c3632d1SSimon J. Gerraty. warning unexpected 912c3632d1SSimon J. Gerraty.endif 923841c287SSimon J. Gerraty 93