modmisc.mk revision 1.53 1 1.53 rillig # $NetBSD: modmisc.mk,v 1.53 2023/06/16 07:20:45 rillig Exp $
2 1.1 apb #
3 1.1 apb # miscellaneous modifier tests
4 1.1 apb
5 1.1 apb # do not put any dirs in this list which exist on some
6 1.1 apb # but not all target systems - an exists() check is below.
7 1.49 rillig path= :/bin:/tmp::/:.:/no/such/dir:.
8 1.1 apb # strip cwd from path.
9 1.49 rillig MOD_NODOT= S/:/ /g:N.:ts:
10 1.49 rillig # and decorate, note that $'s need to be doubled. Also note that
11 1.1 apb # the modifier_variable can be used with other modifiers.
12 1.49 rillig MOD_NODOTX= S/:/ /g:N.:@d@'$$d'@
13 1.1 apb # another mod - pretend it is more interesting
14 1.49 rillig MOD_HOMES= S,/home/,/homes/,
15 1.49 rillig MOD_OPT= @d@$${exists($$d):?$$d:$${d:S,/usr,/opt,}}@
16 1.49 rillig MOD_SEP= S,:, ,g
17 1.1 apb
18 1.53 rillig all: modvar modvarloop emptyvar undefvar
19 1.23 rillig all: mod-quote
20 1.22 rillig all: mod-break-many-words
21 1.1 apb
22 1.23 rillig # Demonstrates modifiers that are given indirectly from a variable.
23 1.1 apb modvar:
24 1.1 apb @echo "path='${path}'"
25 1.1 apb @echo "path='${path:${MOD_NODOT}}'"
26 1.1 apb @echo "path='${path:S,home,homes,:${MOD_NODOT}}'"
27 1.1 apb @echo "path=${path:${MOD_NODOTX}:ts:}"
28 1.1 apb @echo "path=${path:${MOD_HOMES}:${MOD_NODOTX}:ts:}"
29 1.1 apb
30 1.1 apb .for d in ${path:${MOD_SEP}:N.} /usr/xbin
31 1.49 rillig path_$d?= ${d:${MOD_OPT}:${MOD_HOMES}}/
32 1.49 rillig paths+= ${d:${MOD_OPT}:${MOD_HOMES}}
33 1.1 apb .endfor
34 1.1 apb
35 1.1 apb modvarloop:
36 1.1 apb @echo "path_/usr/xbin=${path_/usr/xbin}"
37 1.1 apb @echo "paths=${paths}"
38 1.1 apb @echo "PATHS=${paths:tu}"
39 1.2 rillig
40 1.7 rillig # When a modifier is applied to the "" variable, the result is discarded.
41 1.7 rillig emptyvar:
42 1.7 rillig @echo S:${:S,^$,empty,}
43 1.7 rillig @echo C:${:C,^$,empty,}
44 1.7 rillig @echo @:${:@var@${var}@}
45 1.7 rillig
46 1.7 rillig # The :U modifier turns even the "" variable into something that has a value.
47 1.50 rillig # The value of the resulting expression is empty, but is still considered to
48 1.50 rillig # contain a single empty word. This word can be accessed by the :S and :C
49 1.50 rillig # modifiers, but not by the :@ modifier since it explicitly skips empty words.
50 1.7 rillig undefvar:
51 1.7 rillig @echo S:${:U:S,^$,empty,}
52 1.7 rillig @echo C:${:U:C,^$,empty,}
53 1.7 rillig @echo @:${:U:@var@empty@}
54 1.8 rillig
55 1.19 rillig
56 1.23 rillig mod-quote:
57 1.19 rillig @echo $@: new${.newline:Q}${.newline:Q}line
58 1.22 rillig
59 1.53 rillig # Cover the bmake_realloc in Substring_Words.
60 1.22 rillig mod-break-many-words:
61 1.22 rillig @echo $@: ${UNDEF:U:range=500:[#]}
62