1# $NetBSD: cond-token-var.mk,v 1.6 2021/04/25 21:05:38 rillig Exp $ 2# 3# Tests for variable expressions in .if conditions. 4# 5# Note the fine distinction between a variable and a variable expression. 6# A variable has a name and a value. To access the value, one writes a 7# variable expression of the form ${VAR}. This is a simple variable 8# expression. Variable expressions can get more complicated by adding 9# variable modifiers such as in ${VAR:Mpattern}. 10# 11# XXX: Strictly speaking, variable modifiers should be called expression 12# modifiers instead since they only modify the expression, not the variable. 13# Well, except for the assignment modifiers, these do indeed change the value 14# of the variable. 15 16DEF= defined 17 18# A defined variable may appear on either side of the comparison. 19.if ${DEF} == ${DEF} 20. info ok 21.else 22. error 23.endif 24 25# A variable that appears on the left-hand side must be defined. 26# The following line thus generates a parse error. 27.if ${UNDEF} == ${DEF} 28. error 29.endif 30 31# A variable that appears on the right-hand side must be defined. 32# The following line thus generates a parse error. 33.if ${DEF} == ${UNDEF} 34. error 35.endif 36 37# A defined variable may appear as an expression of its own. 38.if ${DEF} 39.endif 40 41# An undefined variable on its own generates a parse error. 42.if ${UNDEF} 43.endif 44 45# The :U modifier turns an undefined expression into a defined expression. 46# Since the expression is defined now, it doesn't generate any parse error. 47.if ${UNDEF:U} 48.endif 49 50# If the value of the variable expression is a number, it is compared against 51# zero. 52.if ${:U0} 53. error 54.endif 55.if !${:U1} 56. error 57.endif 58 59# If the value of the variable expression is not a number, any non-empty 60# value evaluates to true, even if there is only whitespace. 61.if ${:U} 62. error 63.endif 64.if !${:U } 65. error 66.endif 67.if !${:Uanything} 68. error 69.endif 70