xref: /freebsd/contrib/bmake/unit-tests/modmisc.mk (revision 148ee84570001f46b7b667c86573d378101c3801)
1*148ee845SSimon J. Gerraty# $NetBSD: modmisc.mk,v 1.53 2023/06/16 07:20:45 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
18*148ee845SSimon J. Gerratyall:	modvar modvarloop emptyvar undefvar
192c3632d1SSimon J. Gerratyall:	mod-quote
202c3632d1SSimon J. Gerratyall:	mod-break-many-words
21db29cad8SSimon J. Gerraty
222c3632d1SSimon J. Gerraty# Demonstrates modifiers that are given indirectly from a variable.
23db29cad8SSimon J. Gerratymodvar:
24db29cad8SSimon J. Gerraty	@echo "path='${path}'"
25db29cad8SSimon J. Gerraty	@echo "path='${path:${MOD_NODOT}}'"
26db29cad8SSimon J. Gerraty	@echo "path='${path:S,home,homes,:${MOD_NODOT}}'"
27db29cad8SSimon J. Gerraty	@echo "path=${path:${MOD_NODOTX}:ts:}"
28db29cad8SSimon J. Gerraty	@echo "path=${path:${MOD_HOMES}:${MOD_NODOTX}:ts:}"
29db29cad8SSimon J. Gerraty
30db29cad8SSimon J. Gerraty.for d in ${path:${MOD_SEP}:N.} /usr/xbin
31db29cad8SSimon J. Gerratypath_$d?=	${d:${MOD_OPT}:${MOD_HOMES}}/
32db29cad8SSimon J. Gerratypaths+=		${d:${MOD_OPT}:${MOD_HOMES}}
33db29cad8SSimon J. Gerraty.endfor
34db29cad8SSimon J. Gerraty
35db29cad8SSimon J. Gerratymodvarloop:
36db29cad8SSimon J. Gerraty	@echo "path_/usr/xbin=${path_/usr/xbin}"
37db29cad8SSimon J. Gerraty	@echo "paths=${paths}"
38db29cad8SSimon J. Gerraty	@echo "PATHS=${paths:tu}"
393841c287SSimon J. Gerraty
403841c287SSimon J. Gerraty# When a modifier is applied to the "" variable, the result is discarded.
413841c287SSimon J. Gerratyemptyvar:
423841c287SSimon J. Gerraty	@echo S:${:S,^$,empty,}
433841c287SSimon J. Gerraty	@echo C:${:C,^$,empty,}
443841c287SSimon J. Gerraty	@echo @:${:@var@${var}@}
453841c287SSimon J. Gerraty
463841c287SSimon J. Gerraty# The :U modifier turns even the "" variable into something that has a value.
47e2eeea75SSimon J. Gerraty# The value of the resulting expression is empty, but is still considered to
48e2eeea75SSimon J. Gerraty# contain a single empty word. This word can be accessed by the :S and :C
49e2eeea75SSimon J. Gerraty# modifiers, but not by the :@ modifier since it explicitly skips empty words.
503841c287SSimon J. Gerratyundefvar:
513841c287SSimon J. Gerraty	@echo S:${:U:S,^$,empty,}
523841c287SSimon J. Gerraty	@echo C:${:U:C,^$,empty,}
533841c287SSimon J. Gerraty	@echo @:${:U:@var@empty@}
543841c287SSimon J. Gerraty
553841c287SSimon J. Gerraty
562c3632d1SSimon J. Gerratymod-quote:
572c3632d1SSimon J. Gerraty	@echo $@: new${.newline:Q}${.newline:Q}line
583841c287SSimon J. Gerraty
59*148ee845SSimon J. Gerraty# Cover the bmake_realloc in Substring_Words.
602c3632d1SSimon J. Gerratymod-break-many-words:
612c3632d1SSimon J. Gerraty	@echo $@: ${UNDEF:U:range=500:[#]}
62