1 1.6 rillig # $NetBSD: cond-cmp-string.mk,v 1.6 2020/10/24 08:46:08 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.6 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.6 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.6 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.6 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.6 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.6 rillig . error 39 1.3 rillig .endif 40 1.4 rillig 41 1.5 rillig # There is no = operator for strings. 42 1.4 rillig .if !("value" = "value") 43 1.4 rillig . error 44 1.4 rillig .else 45 1.4 rillig . error 46 1.4 rillig .endif 47 1.4 rillig 48 1.4 rillig # There is no === operator for strings either. 49 1.4 rillig .if !("value" === "value") 50 1.4 rillig . error 51 1.4 rillig .else 52 1.4 rillig . error 53 1.4 rillig .endif 54 1.4 rillig 55