xref: /freebsd/contrib/bmake/unit-tests/modmisc.mk (revision 95eb4b873b6a8b527c5bd78d7191975dfca38998)
1# $NetBSD: modmisc.mk,v 1.53 2023/06/16 07:20:45 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 emptyvar undefvar
19all:	mod-quote
20all:	mod-break-many-words
21
22# Demonstrates modifiers that are given indirectly from a variable.
23modvar:
24	@echo "path='${path}'"
25	@echo "path='${path:${MOD_NODOT}}'"
26	@echo "path='${path:S,home,homes,:${MOD_NODOT}}'"
27	@echo "path=${path:${MOD_NODOTX}:ts:}"
28	@echo "path=${path:${MOD_HOMES}:${MOD_NODOTX}:ts:}"
29
30.for d in ${path:${MOD_SEP}:N.} /usr/xbin
31path_$d?=	${d:${MOD_OPT}:${MOD_HOMES}}/
32paths+=		${d:${MOD_OPT}:${MOD_HOMES}}
33.endfor
34
35modvarloop:
36	@echo "path_/usr/xbin=${path_/usr/xbin}"
37	@echo "paths=${paths}"
38	@echo "PATHS=${paths:tu}"
39
40# When a modifier is applied to the "" variable, the result is discarded.
41emptyvar:
42	@echo S:${:S,^$,empty,}
43	@echo C:${:C,^$,empty,}
44	@echo @:${:@var@${var}@}
45
46# The :U modifier turns even the "" variable into something that has a value.
47# The value of the resulting expression is empty, but is still considered to
48# contain a single empty word. This word can be accessed by the :S and :C
49# modifiers, but not by the :@ modifier since it explicitly skips empty words.
50undefvar:
51	@echo S:${:U:S,^$,empty,}
52	@echo C:${:U:C,^$,empty,}
53	@echo @:${:U:@var@empty@}
54
55
56mod-quote:
57	@echo $@: new${.newline:Q}${.newline:Q}line
58
59# Cover the bmake_realloc in Substring_Words.
60mod-break-many-words:
61	@echo $@: ${UNDEF:U:range=500:[#]}
62