1 1.3 rillig # $NetBSD: cond-cmp-string.mk,v 1.3 2020/08/20 18:43:19 rillig Exp $ 2 1.1 rillig # 3 1.2 rillig # Tests for string comparisons in .if conditions. 4 1.1 rillig 5 1.3 rillig # This is a simple comparison of string literals. 6 1.3 rillig # Nothing surprising here. 7 1.3 rillig .if "str" != "str" 8 1.3 rillig .error 9 1.3 rillig .endif 10 1.1 rillig 11 1.3 rillig # The right-hand side of the comparison may be written without quotes. 12 1.3 rillig .if "str" != str 13 1.3 rillig .error 14 1.3 rillig .endif 15 1.3 rillig 16 1.3 rillig # The left-hand side of the comparison must be enclosed in quotes. 17 1.3 rillig # This one is not enclosed in quotes and thus generates an error message. 18 1.3 rillig .if str != str 19 1.3 rillig .error 20 1.3 rillig .endif 21 1.3 rillig 22 1.3 rillig # The left-hand side of the comparison requires a defined variable. 23 1.3 rillig # The variable named "" is not defined, but applying the :U modifier to it 24 1.3 rillig # makes it "kind of defined" (see VAR_KEEP). Therefore it is ok here. 25 1.3 rillig .if ${:Ustr} != "str" 26 1.3 rillig .error 27 1.3 rillig .endif 28 1.3 rillig 29 1.3 rillig # Any character in a string literal may be escaped using a backslash. 30 1.3 rillig # This means that "\n" does not mean a newline but a simple "n". 31 1.3 rillig .if "string" != "\s\t\r\i\n\g" 32 1.3 rillig .error 33 1.3 rillig .endif 34 1.3 rillig 35 1.3 rillig # It is not possible to concatenate two string literals to form a single 36 1.3 rillig # string. 37 1.3 rillig .if "string" != "str""ing" 38 1.3 rillig .error 39 1.3 rillig .endif 40