2023-12-17 12:44:00 +03:00
|
|
|
# $NetBSD: cond-op-and.mk,v 1.9 2023/12/17 09:44:00 rillig Exp $
|
2020-08-16 15:07:50 +03:00
|
|
|
#
|
2020-08-16 17:25:16 +03:00
|
|
|
# Tests for the && operator in .if conditions.
|
2020-08-16 15:07:50 +03:00
|
|
|
|
2020-08-28 17:48:37 +03:00
|
|
|
.if 0 && 0
|
2020-10-24 11:46:08 +03:00
|
|
|
. error
|
2020-08-28 17:48:37 +03:00
|
|
|
.endif
|
|
|
|
|
|
|
|
.if 1 && 0
|
2020-10-24 11:46:08 +03:00
|
|
|
. error
|
2020-08-28 17:48:37 +03:00
|
|
|
.endif
|
|
|
|
|
|
|
|
.if 0 && 1
|
2020-10-24 11:46:08 +03:00
|
|
|
. error
|
2020-08-28 17:48:37 +03:00
|
|
|
.endif
|
|
|
|
|
|
|
|
.if !(1 && 1)
|
2020-10-24 11:46:08 +03:00
|
|
|
. error
|
2020-08-28 17:48:37 +03:00
|
|
|
.endif
|
|
|
|
|
2021-12-10 22:14:35 +03:00
|
|
|
|
2020-08-28 17:48:37 +03:00
|
|
|
# The right-hand side is not evaluated since the left-hand side is already
|
|
|
|
# false.
|
|
|
|
.if 0 && ${UNDEF}
|
|
|
|
.endif
|
2020-08-16 15:07:50 +03:00
|
|
|
|
2021-12-10 22:14:35 +03:00
|
|
|
# When an outer condition makes the inner '&&' condition irrelevant, neither
|
|
|
|
# of its operands must be evaluated.
|
|
|
|
#
|
|
|
|
.if 1 || (${UNDEF} && ${UNDEF})
|
|
|
|
.endif
|
|
|
|
|
|
|
|
# Test combinations of outer '||' with inner '&&', to ensure that the operands
|
|
|
|
# of the inner '&&' are only evaluated if necessary.
|
|
|
|
DEF= defined
|
2023-12-17 12:44:00 +03:00
|
|
|
# expect+1: Malformed conditional (0 || (${DEF} && ${UNDEF}))
|
2021-12-10 22:14:35 +03:00
|
|
|
.if 0 || (${DEF} && ${UNDEF})
|
|
|
|
.endif
|
|
|
|
.if 0 || (!${DEF} && ${UNDEF})
|
|
|
|
.endif
|
2023-12-17 12:44:00 +03:00
|
|
|
# expect+1: Malformed conditional (0 || (${UNDEF} && ${UNDEF}))
|
2021-12-10 22:14:35 +03:00
|
|
|
.if 0 || (${UNDEF} && ${UNDEF})
|
|
|
|
.endif
|
2023-12-17 12:44:00 +03:00
|
|
|
# expect+1: Malformed conditional (0 || (!${UNDEF} && ${UNDEF}))
|
2021-12-10 22:14:35 +03:00
|
|
|
.if 0 || (!${UNDEF} && ${UNDEF})
|
|
|
|
.endif
|
|
|
|
.if 1 || (${DEF} && ${UNDEF})
|
|
|
|
.endif
|
|
|
|
.if 1 || (!${DEF} && ${UNDEF})
|
|
|
|
.endif
|
|
|
|
.if 1 || (${UNDEF} && ${UNDEF})
|
|
|
|
.endif
|
|
|
|
.if 1 || (!${UNDEF} && ${UNDEF})
|
|
|
|
.endif
|
|
|
|
|
|
|
|
|
2020-09-11 01:38:57 +03:00
|
|
|
# The && operator may be abbreviated as &. This is not widely known though
|
|
|
|
# and is also not documented in the manual page.
|
|
|
|
|
|
|
|
.if 0 & 0
|
|
|
|
. error
|
|
|
|
.endif
|
|
|
|
.if 1 & 0
|
|
|
|
. error
|
|
|
|
.endif
|
|
|
|
.if 0 & 1
|
|
|
|
. error
|
|
|
|
.endif
|
|
|
|
.if !(1 & 1)
|
|
|
|
. error
|
|
|
|
.endif
|
|
|
|
|
|
|
|
# There is no operator &&&.
|
2023-06-01 23:56:35 +03:00
|
|
|
# expect+1: Malformed conditional (0 &&& 0)
|
2020-09-11 01:38:57 +03:00
|
|
|
.if 0 &&& 0
|
|
|
|
. error
|
|
|
|
.endif
|
|
|
|
|
2023-08-16 00:27:09 +03:00
|
|
|
# The '&&' operator must be preceded by whitespace, otherwise it becomes part
|
|
|
|
# of the preceding bare word. The condition is parsed as '"1&&" != "" && 1'.
|
|
|
|
.if 1&& && 1
|
|
|
|
.else
|
|
|
|
. error
|
|
|
|
.endif
|