Simon J. Gerraty 2c3632d14f Update to bmake-20200902
Lots of code refactoring, simplification and cleanup.
Lots of new unit-tests providing much higher code coverage.
All courtesy of rillig at netbsd.

Other significant changes:

o new read-only variable .SHELL which provides the path of the shell
  used to run scripts (as defined by  the .SHELL target).

o variable parsing detects more errors.

o new debug option -dl: LINT mode, does the equivalent of := for all
  variable assignments so that file and line number are reported for
  variable parse errors.
2020-09-05 19:29:42 +00:00

61 lines
1.6 KiB
Makefile

# $NetBSD: cond-op.mk,v 1.4 2020/08/28 14:07:51 rillig Exp $
#
# Tests for operators like &&, ||, ! in .if conditions.
#
# See also:
# cond-op-and.mk
# cond-op-not.mk
# cond-op-or.mk
# cond-op-parentheses.mk
# In make, && binds more tightly than ||, like in C.
# If make had the same precedence for both && and ||, the result would be
# different.
# If || were to bind more tightly than &&, the result would be different
# as well.
.if !(1 || 1 && 0)
.error
.endif
# If make were to interpret the && and || operators like the shell, the
# implicit binding would be this:
.if (1 || 1) && 0
.error
.endif
# The precedence of the ! operator is different from C though. It has a
# lower precedence than the comparison operators.
.if !"word" == "word"
.error
.endif
# This is how the above condition is actually interpreted.
.if !("word" == "word")
.error
.endif
# TODO: Demonstrate that the precedence of the ! and == operators actually
# makes a difference. There is a simple example for sure, I just cannot
# wrap my head around it.
# This condition is malformed because the '!' on the right-hand side must not
# appear unquoted. If any, it must be enclosed in quotes.
# In any case, it is not interpreted as a negation of an unquoted string.
# See CondGetString.
.if "!word" == !word
.error
.endif
# Surprisingly, the ampersand and pipe are allowed in bare strings.
# That's another opportunity for writing confusing code.
# See CondGetString, which only has '!' in the list of stop characters.
.if "a&&b||c" != a&&b||c
.error
.endif
# Just in case that parsing should ever stop on the first error.
.info Parsing continues until here.
all:
@:;