1 # $NetBSD: cond-cmp-string.mk,v 1.11 2020/10/30 14:53:31 rillig Exp $
3 # Tests for string comparisons in .if conditions.
5 # This is a simple comparison of string literals.
6 # Nothing surprising here.
11 # The right-hand side of the comparison may be written without quotes.
16 # The left-hand side of the comparison must be enclosed in quotes.
17 # This one is not enclosed in quotes and thus generates an error message.
22 # The left-hand side of the comparison requires a defined variable.
23 # The variable named "" is not defined, but applying the :U modifier to it
24 # makes it "kind of defined" (see VAR_KEEP). Therefore it is ok here.
29 # Any character in a string literal may be escaped using a backslash.
30 # This means that "\n" does not mean a newline but a simple "n".
31 .if "string" != "\s\t\r\i\n\g"
35 # It is not possible to concatenate two string literals to form a single
37 .if "string" != "str""ing"
41 # There is no = operator for strings.
42 .if !("value" = "value")
48 # There is no === operator for strings either.
49 .if !("value" === "value")
55 # A variable expression can be enclosed in double quotes.
56 .if ${:Uword} != "${:Uword}"
60 # Between 2003-01-01 (maybe even earlier) and 2020-10-30, adding one of the
61 # characters " \t!=><" directly after a variable expression resulted in a
62 # "Malformed conditional", even though the string was well-formed.
63 .if ${:Uword } != "${:Uword} "
66 # Some other characters worked though, and some didn't.
67 # Those that are mentioned in is_separator didn't work.
68 .if ${:Uword0} != "${:Uword}0"
71 .if ${:Uword&} != "${:Uword}&"
74 .if ${:Uword!} != "${:Uword}!"
77 .if ${:Uword<} != "${:Uword}<"
81 # Adding another variable expression to the string literal works though.
82 .if ${:Uword} != "${:Uwo}${:Urd}"
86 # Adding a space at the beginning of the quoted variable expression works
88 .if ${:U word } != " ${:Uword} "