1 1.6 rillig # $NetBSD: cond-cmp-unary.mk,v 1.6 2023/11/19 21:47:52 rillig Exp $ 2 1.1 rillig # 3 1.1 rillig # Tests for unary comparisons in .if conditions, that is, comparisons with 4 1.1 rillig # a single operand. If the operand is a number, it is compared to zero, 5 1.1 rillig # if it is a string, it is tested for emptiness. 6 1.1 rillig 7 1.3 rillig # The number 0 in all its various representations evaluates to false. 8 1.3 rillig .if 0 || 0.0 || 0e0 || 0.0e0 || 0.0e10 9 1.1 rillig . error 10 1.1 rillig .endif 11 1.1 rillig 12 1.1 rillig # Any other number evaluates to true. 13 1.1 rillig .if !12345 14 1.1 rillig . error 15 1.1 rillig .endif 16 1.1 rillig 17 1.1 rillig # The empty string evaluates to false. 18 1.1 rillig .if "" 19 1.1 rillig . error 20 1.1 rillig .endif 21 1.1 rillig 22 1.1 rillig # Any other string evaluates to true. 23 1.1 rillig .if !"0" 24 1.1 rillig . error 25 1.1 rillig .endif 26 1.1 rillig 27 1.6 rillig # The empty string may come from an expression. 28 1.2 rillig # 29 1.4 rillig # XXX: As of 2023-06-01, this empty string is interpreted "as a number" in 30 1.4 rillig # EvalTruthy, which is plain wrong. The bug is in TryParseNumber. 31 1.1 rillig .if ${:U} 32 1.1 rillig . error 33 1.1 rillig .endif 34 1.1 rillig 35 1.6 rillig # An expression that is not surrounded by quotes is interpreted 36 1.1 rillig # as a number if possible, otherwise as a string. 37 1.1 rillig .if ${:U0} 38 1.1 rillig . error 39 1.1 rillig .endif 40 1.1 rillig 41 1.6 rillig # A non-zero number from an expression evaluates to true. 42 1.1 rillig .if !${:U12345} 43 1.1 rillig . error 44 1.1 rillig .endif 45 1.1 rillig 46 1.2 rillig # A string of whitespace should evaluate to false. 47 1.2 rillig # 48 1.4 rillig # XXX: As of 2023-06-01, the implementation in EvalTruthy does not skip 49 1.2 rillig # whitespace before testing for the end. This was probably an oversight in 50 1.2 rillig # a commit from 1992-04-15 saying "A variable is empty when it just contains 51 1.2 rillig # spaces". 52 1.2 rillig .if ${:U } 53 1.5 rillig # expect+1: This is only reached because of a bug in EvalTruthy. 54 1.4 rillig . info This is only reached because of a bug in EvalTruthy. 55 1.2 rillig .else 56 1.2 rillig . error 57 1.2 rillig .endif 58 1.2 rillig 59 1.3 rillig # The condition '${VAR:M*}' is almost equivalent to '${VAR:M*} != ""'. The 60 1.3 rillig # only case where they differ is for a single word whose numeric value is zero. 61 1.3 rillig .if ${:U0:M*} 62 1.3 rillig . error 63 1.3 rillig .endif 64 1.3 rillig .if ${:U0:M*} == "" 65 1.3 rillig . error 66 1.3 rillig .endif 67 1.3 rillig # Multiple words cannot be parsed as a single number, thus evaluating to true. 68 1.3 rillig .if !${:U0 0:M*} 69 1.3 rillig . error 70 1.3 rillig .endif 71 1.3 rillig .if ${:U0 0:M*} == "" 72 1.3 rillig . error 73 1.3 rillig .endif 74 1.3 rillig 75 1.1 rillig all: # nothing 76