1# $NetBSD: cond-token-var.mk,v 1.7 2023/06/01 20:56:35 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# expect+1: ok 21. info ok 22.else 23. error 24.endif 25 26# A variable that appears on the left-hand side must be defined. 27# expect+1: Malformed conditional (${UNDEF} == ${DEF}) 28.if ${UNDEF} == ${DEF} 29. error 30.endif 31 32# A variable that appears on the right-hand side must be defined. 33# expect+1: Malformed conditional (${DEF} == ${UNDEF}) 34.if ${DEF} == ${UNDEF} 35. error 36.endif 37 38# A defined variable may appear as an expression of its own. 39.if ${DEF} 40.endif 41 42# An undefined variable on its own generates a parse error. 43# expect+1: Malformed conditional (${UNDEF}) 44.if ${UNDEF} 45.endif 46 47# The :U modifier turns an undefined expression into a defined expression. 48# Since the expression is defined now, it doesn't generate any parse error. 49.if ${UNDEF:U} 50.endif 51 52# If the value of the variable expression is a number, it is compared against 53# zero. 54.if ${:U0} 55. error 56.endif 57.if !${:U1} 58. error 59.endif 60 61# If the value of the variable expression is not a number, any non-empty 62# value evaluates to true, even if there is only whitespace. 63.if ${:U} 64. error 65.endif 66.if !${:U } 67. error 68.endif 69.if !${:Uanything} 70. error 71.endif 72