2023-01-28 00:23:54 +00:00
|
|
|
# $NetBSD: varmod-undefined.mk,v 1.8 2022/08/06 21:26:05 rillig Exp $
|
2020-09-05 16:11:04 +00:00
|
|
|
#
|
|
|
|
# Tests for the :U variable modifier, which returns the given string
|
|
|
|
# if the variable is undefined.
|
|
|
|
#
|
2020-11-07 19:39:21 +00:00
|
|
|
# See also:
|
2020-11-20 03:54:37 +00:00
|
|
|
# directive-for.mk
|
2020-11-07 19:39:21 +00:00
|
|
|
# varmod-defined.mk
|
2020-09-05 16:11:04 +00:00
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
# The pattern ${:Uword} is heavily used when expanding .for loops.
|
|
|
|
#
|
2020-09-05 16:11:04 +00:00
|
|
|
# This is how an expanded .for loop looks like.
|
|
|
|
# .for word in one
|
|
|
|
# . if ${word} != one
|
|
|
|
.if ${:Uone} != one
|
2020-11-07 19:39:21 +00:00
|
|
|
# . error ${word}
|
2020-09-05 16:11:04 +00:00
|
|
|
. error ${:Uone}
|
2020-11-07 19:39:21 +00:00
|
|
|
# . endif
|
2020-09-05 16:11:04 +00:00
|
|
|
.endif
|
2020-11-07 19:39:21 +00:00
|
|
|
# .endfor
|
2020-09-05 16:11:04 +00:00
|
|
|
|
|
|
|
# The variable expressions in the text of the :U modifier may be arbitrarily
|
|
|
|
# nested.
|
|
|
|
|
|
|
|
.if ${:U${:Unested}${${${:Udeeply}}}} != nested
|
2020-11-07 19:39:21 +00:00
|
|
|
. error
|
2020-09-05 16:11:04 +00:00
|
|
|
.endif
|
|
|
|
|
|
|
|
# The nested variable expressions may contain braces, and these braces don't
|
|
|
|
# need to match pairwise. In the following example, the :S modifier uses '{'
|
|
|
|
# as delimiter, which confuses both editors and humans because the opening
|
2023-01-28 00:23:54 +00:00
|
|
|
# and closing braces don't match anymore. It's syntactically valid though.
|
2020-09-05 16:11:04 +00:00
|
|
|
# For more similar examples, see varmod-subst.mk, mod-subst-delimiter.
|
|
|
|
|
|
|
|
.if ${:U${:Uvalue:S{a{X{}} != vXlue
|
2020-11-07 19:39:21 +00:00
|
|
|
. error
|
2020-09-05 16:11:04 +00:00
|
|
|
.endif
|
|
|
|
|
|
|
|
# The escaping rules for the :U modifier (left-hand side) and condition
|
|
|
|
# string literals (right-hand side) are completely different.
|
|
|
|
#
|
|
|
|
# In the :U modifier, the backslash only escapes very few characters, all
|
|
|
|
# other backslashes are retained.
|
|
|
|
#
|
|
|
|
# In condition string literals, the backslash always escapes the following
|
|
|
|
# character, no matter whether it would be necessary or not.
|
|
|
|
#
|
|
|
|
# In both contexts, \n is an escaped letter n, not a newline; that's what
|
|
|
|
# the .newline variable is for.
|
|
|
|
#
|
|
|
|
# Whitespace at the edges is preserved, on both sides of the comparison.
|
2020-11-07 19:39:21 +00:00
|
|
|
#
|
2020-09-05 16:11:04 +00:00
|
|
|
.if ${:U \: \} \$ \\ \a \b \n } != " : } \$ \\ \\a \\b \\n "
|
2020-11-07 19:39:21 +00:00
|
|
|
. error
|
|
|
|
.endif
|
|
|
|
|
|
|
|
# Even after the :U modifier has been applied, the expression still remembers
|
|
|
|
# that it originated from an undefined variable, and the :U modifier can
|
|
|
|
# be used to overwrite the value of the expression.
|
|
|
|
#
|
|
|
|
.if ${UNDEF:Uvalue:S,a,X,} != "vXlue"
|
|
|
|
. error
|
|
|
|
.elif ${UNDEF:Uvalue:S,a,X,:Uwas undefined} != "was undefined"
|
|
|
|
. error
|
2020-09-05 16:11:04 +00:00
|
|
|
.endif
|
|
|
|
|
|
|
|
all:
|
|
|
|
@:;
|