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