1 # $NetBSD: varmod-undefined.mk,v 1.7 2020/11/15 20:20:58 rillig Exp $
3 # Tests for the :U variable modifier, which returns the given string
4 # if the variable is undefined.
10 # The pattern ${:Uword} is heavily used when expanding .for loops.
12 # This is how an expanded .for loop looks like.
22 # The variable expressions in the text of the :U modifier may be arbitrarily
25 .if ${:U${:Unested}${${${:Udeeply}}}} != nested
29 # The nested variable expressions may contain braces, and these braces don't
30 # need to match pairwise. In the following example, the :S modifier uses '{'
31 # as delimiter, which confuses both editors and humans because the opening
32 # and # closing braces don't match anymore. It's syntactically valid though.
33 # For more similar examples, see varmod-subst.mk, mod-subst-delimiter.
35 .if ${:U${:Uvalue:S{a{X{}} != vXlue
39 # The escaping rules for the :U modifier (left-hand side) and condition
40 # string literals (right-hand side) are completely different.
42 # In the :U modifier, the backslash only escapes very few characters, all
43 # other backslashes are retained.
45 # In condition string literals, the backslash always escapes the following
46 # character, no matter whether it would be necessary or not.
48 # In both contexts, \n is an escaped letter n, not a newline; that's what
49 # the .newline variable is for.
51 # Whitespace at the edges is preserved, on both sides of the comparison.
53 .if ${:U \: \} \$ \\ \a \b \n } != " : } \$ \\ \\a \\b \\n "
57 # Even after the :U modifier has been applied, the expression still remembers
58 # that it originated from an undefined variable, and the :U modifier can
59 # be used to overwrite the value of the expression.
61 .if ${UNDEF:Uvalue:S,a,X,} != "vXlue"
63 .elif ${UNDEF:Uvalue:S,a,X,:Uwas undefined} != "was undefined"