2021-01-14 01:24:34 +00:00
|
|
|
# $NetBSD: modmisc.mk,v 1.52 2020/12/20 19:29:06 rillig Exp $
|
2012-06-08 21:57:36 +00:00
|
|
|
#
|
|
|
|
# miscellaneous modifier tests
|
|
|
|
|
|
|
|
# do not put any dirs in this list which exist on some
|
|
|
|
# but not all target systems - an exists() check is below.
|
2020-11-07 19:39:21 +00:00
|
|
|
path= :/bin:/tmp::/:.:/no/such/dir:.
|
2012-06-08 21:57:36 +00:00
|
|
|
# strip cwd from path.
|
2020-11-07 19:39:21 +00:00
|
|
|
MOD_NODOT= S/:/ /g:N.:ts:
|
|
|
|
# and decorate, note that $'s need to be doubled. Also note that
|
2012-06-08 21:57:36 +00:00
|
|
|
# the modifier_variable can be used with other modifiers.
|
2020-11-07 19:39:21 +00:00
|
|
|
MOD_NODOTX= S/:/ /g:N.:@d@'$$d'@
|
2012-06-08 21:57:36 +00:00
|
|
|
# another mod - pretend it is more interesting
|
2020-11-07 19:39:21 +00:00
|
|
|
MOD_HOMES= S,/home/,/homes/,
|
|
|
|
MOD_OPT= @d@$${exists($$d):?$$d:$${d:S,/usr,/opt,}}@
|
|
|
|
MOD_SEP= S,:, ,g
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2020-09-05 16:11:04 +00:00
|
|
|
all: modvar modvarloop modsysv emptyvar undefvar
|
|
|
|
all: mod-quote
|
|
|
|
all: mod-break-many-words
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2020-09-05 16:11:04 +00:00
|
|
|
# See also sysv.mk.
|
2012-06-08 21:57:36 +00:00
|
|
|
modsysv:
|
|
|
|
@echo "The answer is ${libfoo.a:L:libfoo.a=42}"
|
|
|
|
|
2020-09-05 16:11:04 +00:00
|
|
|
# Demonstrates modifiers that are given indirectly from a variable.
|
2012-06-08 21:57:36 +00:00
|
|
|
modvar:
|
|
|
|
@echo "path='${path}'"
|
|
|
|
@echo "path='${path:${MOD_NODOT}}'"
|
|
|
|
@echo "path='${path:S,home,homes,:${MOD_NODOT}}'"
|
|
|
|
@echo "path=${path:${MOD_NODOTX}:ts:}"
|
|
|
|
@echo "path=${path:${MOD_HOMES}:${MOD_NODOTX}:ts:}"
|
|
|
|
|
|
|
|
.for d in ${path:${MOD_SEP}:N.} /usr/xbin
|
2020-11-07 19:39:21 +00:00
|
|
|
path_$d?= ${d:${MOD_OPT}:${MOD_HOMES}}/
|
|
|
|
paths+= ${d:${MOD_OPT}:${MOD_HOMES}}
|
2012-06-08 21:57:36 +00:00
|
|
|
.endfor
|
|
|
|
|
|
|
|
modvarloop:
|
|
|
|
@echo "path_/usr/xbin=${path_/usr/xbin}"
|
|
|
|
@echo "paths=${paths}"
|
|
|
|
@echo "PATHS=${paths:tu}"
|
2020-07-08 18:32:15 +00:00
|
|
|
|
|
|
|
# When a modifier is applied to the "" variable, the result is discarded.
|
|
|
|
emptyvar:
|
|
|
|
@echo S:${:S,^$,empty,}
|
|
|
|
@echo C:${:C,^$,empty,}
|
|
|
|
@echo @:${:@var@${var}@}
|
|
|
|
|
|
|
|
# The :U modifier turns even the "" variable into something that has a value.
|
2020-11-20 03:54:37 +00:00
|
|
|
# The value of the resulting expression is empty, but is still considered to
|
|
|
|
# contain a single empty word. This word can be accessed by the :S and :C
|
|
|
|
# modifiers, but not by the :@ modifier since it explicitly skips empty words.
|
2020-07-08 18:32:15 +00:00
|
|
|
undefvar:
|
|
|
|
@echo S:${:U:S,^$,empty,}
|
|
|
|
@echo C:${:U:C,^$,empty,}
|
|
|
|
@echo @:${:U:@var@empty@}
|
|
|
|
|
2020-09-05 16:11:04 +00:00
|
|
|
|
|
|
|
mod-quote:
|
|
|
|
@echo $@: new${.newline:Q}${.newline:Q}line
|
|
|
|
|
2020-11-20 03:54:37 +00:00
|
|
|
# Cover the bmake_realloc in Str_Words.
|
2020-09-05 16:11:04 +00:00
|
|
|
mod-break-many-words:
|
|
|
|
@echo $@: ${UNDEF:U:range=500:[#]}
|