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