2023-01-28 00:23:54 +00:00
|
|
|
# $NetBSD: cond-cmp-unary.mk,v 1.3 2022/09/08 05:43:20 rillig Exp $
|
2020-11-07 19:39:21 +00:00
|
|
|
#
|
|
|
|
# Tests for unary comparisons in .if conditions, that is, comparisons with
|
|
|
|
# a single operand. If the operand is a number, it is compared to zero,
|
|
|
|
# if it is a string, it is tested for emptiness.
|
|
|
|
|
2023-01-28 00:23:54 +00:00
|
|
|
# The number 0 in all its various representations evaluates to false.
|
|
|
|
.if 0 || 0.0 || 0e0 || 0.0e0 || 0.0e10
|
2020-11-07 19:39:21 +00:00
|
|
|
. error
|
|
|
|
.endif
|
|
|
|
|
|
|
|
# Any other number evaluates to true.
|
|
|
|
.if !12345
|
|
|
|
. error
|
|
|
|
.endif
|
|
|
|
|
|
|
|
# The empty string evaluates to false.
|
|
|
|
.if ""
|
|
|
|
. error
|
|
|
|
.endif
|
|
|
|
|
|
|
|
# Any other string evaluates to true.
|
|
|
|
.if !"0"
|
|
|
|
. error
|
|
|
|
.endif
|
|
|
|
|
|
|
|
# The empty string may come from a variable expression.
|
2020-11-20 03:54:37 +00:00
|
|
|
#
|
|
|
|
# XXX: As of 2020-11-11, this empty string is interpreted "as a number" in
|
|
|
|
# EvalNotEmpty, which is plain wrong. The bug is in TryParseNumber.
|
2020-11-07 19:39:21 +00:00
|
|
|
.if ${:U}
|
|
|
|
. error
|
|
|
|
.endif
|
|
|
|
|
|
|
|
# A variable expression that is not surrounded by quotes is interpreted
|
|
|
|
# as a number if possible, otherwise as a string.
|
|
|
|
.if ${:U0}
|
|
|
|
. error
|
|
|
|
.endif
|
|
|
|
|
|
|
|
# A non-zero number from a variable expression evaluates to true.
|
|
|
|
.if !${:U12345}
|
|
|
|
. error
|
|
|
|
.endif
|
|
|
|
|
2020-11-20 03:54:37 +00:00
|
|
|
# A string of whitespace should evaluate to false.
|
|
|
|
#
|
|
|
|
# XXX: As of 2020-11-11, the implementation in EvalNotEmpty does not skip
|
|
|
|
# whitespace before testing for the end. This was probably an oversight in
|
|
|
|
# a commit from 1992-04-15 saying "A variable is empty when it just contains
|
|
|
|
# spaces".
|
|
|
|
.if ${:U }
|
|
|
|
. info This is only reached because of a bug in EvalNotEmpty.
|
|
|
|
.else
|
|
|
|
. error
|
|
|
|
.endif
|
|
|
|
|
2023-01-28 00:23:54 +00:00
|
|
|
# The condition '${VAR:M*}' is almost equivalent to '${VAR:M*} != ""'. The
|
|
|
|
# only case where they differ is for a single word whose numeric value is zero.
|
|
|
|
.if ${:U0:M*}
|
|
|
|
. error
|
|
|
|
.endif
|
|
|
|
.if ${:U0:M*} == ""
|
|
|
|
. error
|
|
|
|
.endif
|
|
|
|
# Multiple words cannot be parsed as a single number, thus evaluating to true.
|
|
|
|
.if !${:U0 0:M*}
|
|
|
|
. error
|
|
|
|
.endif
|
|
|
|
.if ${:U0 0:M*} == ""
|
|
|
|
. error
|
|
|
|
.endif
|
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
all: # nothing
|