2022-02-05 20:03:50 +00:00
|
|
|
# $NetBSD: cond-func.mk,v 1.11 2022/01/07 19:30:17 rillig Exp $
|
2020-09-05 16:11:04 +00:00
|
|
|
#
|
|
|
|
# Tests for those parts of the functions in .if conditions that are common
|
|
|
|
# among several functions.
|
|
|
|
#
|
|
|
|
# The below test uses the function defined(...) since it has no side-effects,
|
2020-11-20 03:54:37 +00:00
|
|
|
# the other functions (except empty(...)) would work equally well. The
|
|
|
|
# function empty is special because it uses a different parsing algorithm for
|
|
|
|
# its argument.
|
2020-09-05 16:11:04 +00:00
|
|
|
|
|
|
|
DEF= defined
|
|
|
|
${:UA B}= variable name with spaces
|
|
|
|
${:UVAR(value)}= variable name with parentheses
|
2020-11-20 03:54:37 +00:00
|
|
|
${:UVAR{value}}= variable name with balanced braces
|
|
|
|
|
|
|
|
# Really strange variable names must be given indirectly via another variable,
|
|
|
|
# so that no unbalanced braces appear in the top-level expression.
|
|
|
|
VARNAME_UNBALANCED_BRACES= VAR{{{value
|
|
|
|
${VARNAME_UNBALANCED_BRACES}= variable name with unbalanced braces
|
2020-09-05 16:11:04 +00:00
|
|
|
|
|
|
|
.if !defined(DEF)
|
2020-11-07 19:39:21 +00:00
|
|
|
. error
|
2020-09-05 16:11:04 +00:00
|
|
|
.endif
|
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
# Horizontal whitespace (space tab) after the opening parenthesis is ignored.
|
2020-09-05 16:11:04 +00:00
|
|
|
.if !defined( DEF)
|
2020-11-07 19:39:21 +00:00
|
|
|
. error
|
2020-09-05 16:11:04 +00:00
|
|
|
.endif
|
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
# Horizontal whitespace (space tab) before the closing parenthesis is ignored.
|
2020-09-05 16:11:04 +00:00
|
|
|
.if !defined(DEF )
|
2020-11-07 19:39:21 +00:00
|
|
|
. error
|
2020-09-05 16:11:04 +00:00
|
|
|
.endif
|
|
|
|
|
|
|
|
# The argument of a function must not directly contain whitespace.
|
|
|
|
.if !defined(A B)
|
2020-11-07 19:39:21 +00:00
|
|
|
. error
|
2020-09-05 16:11:04 +00:00
|
|
|
.endif
|
|
|
|
|
|
|
|
# If necessary, the whitespace can be generated by a variable expression.
|
|
|
|
.if !defined(${:UA B})
|
2020-11-07 19:39:21 +00:00
|
|
|
. error
|
2020-09-05 16:11:04 +00:00
|
|
|
.endif
|
|
|
|
|
|
|
|
# Characters that could be mistaken for operators must not appear directly
|
|
|
|
# in a function argument. As with whitespace, these can be generated
|
|
|
|
# indirectly.
|
|
|
|
#
|
|
|
|
# It's not entirely clear why these characters are forbidden.
|
|
|
|
# The most plausible reason seems to be typo detection.
|
|
|
|
.if !defined(A&B)
|
2020-11-07 19:39:21 +00:00
|
|
|
. error
|
2020-09-05 16:11:04 +00:00
|
|
|
.endif
|
|
|
|
.if !defined(A|B)
|
2020-11-07 19:39:21 +00:00
|
|
|
. error
|
2020-09-05 16:11:04 +00:00
|
|
|
.endif
|
|
|
|
|
|
|
|
# Even parentheses may appear in variable names.
|
|
|
|
# They must be balanced though.
|
|
|
|
.if !defined(VAR(value))
|
2020-11-07 19:39:21 +00:00
|
|
|
. error
|
2020-09-05 16:11:04 +00:00
|
|
|
.endif
|
|
|
|
|
|
|
|
# Braces do not have any special meaning when parsing arguments.
|
|
|
|
.if !defined(VAR{value})
|
2020-11-07 19:39:21 +00:00
|
|
|
. error
|
|
|
|
.endif
|
|
|
|
|
2020-11-20 03:54:37 +00:00
|
|
|
# Braces do not have any special meaning when parsing arguments.
|
|
|
|
# They don't need to be balanced.
|
|
|
|
.if !defined(VAR{{{value)
|
|
|
|
. error
|
|
|
|
.endif
|
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
# There may be spaces around the operators and parentheses, and even
|
|
|
|
# inside the parentheses. The spaces inside the parentheses are not
|
|
|
|
# allowed for the empty() function (see cond-func-empty.mk), therefore
|
|
|
|
# they are typically omitted for the other functions as well.
|
|
|
|
.if ! defined ( DEF )
|
|
|
|
. error
|
2020-09-05 16:11:04 +00:00
|
|
|
.endif
|
|
|
|
|
2020-11-20 03:54:37 +00:00
|
|
|
# The following condition is interpreted as defined(A) && defined(B).
|
|
|
|
# In lack of a function call expression, each kind of .if directive has a
|
|
|
|
# default function that is called when a bare word is parsed. For the plain
|
|
|
|
# .if directive, this function is defined(); see "struct If ifs" in cond.c.
|
|
|
|
.if A&B
|
|
|
|
. error
|
|
|
|
.endif
|
|
|
|
|
|
|
|
.if defined()
|
|
|
|
. error
|
|
|
|
.else
|
|
|
|
. info The empty variable is never defined.
|
|
|
|
.endif
|
|
|
|
|
2022-02-05 20:03:50 +00:00
|
|
|
# The plain word 'defined' is interpreted as 'defined(defined)', see
|
|
|
|
# CondParser_ComparisonOrLeaf.
|
2020-11-20 03:54:37 +00:00
|
|
|
# That variable is not defined (yet).
|
|
|
|
.if defined
|
|
|
|
. error
|
|
|
|
.else
|
2022-02-05 20:03:50 +00:00
|
|
|
. info A plain function name is parsed as defined(...).
|
2020-11-20 03:54:37 +00:00
|
|
|
.endif
|
|
|
|
|
2022-02-05 20:03:50 +00:00
|
|
|
# If a variable named 'defined' is actually defined, the bare word 'defined'
|
|
|
|
# is interpreted as 'defined(defined)', and the condition evaluates to true.
|
|
|
|
defined= # defined but empty
|
2020-11-20 03:54:37 +00:00
|
|
|
.if defined
|
2022-02-05 20:03:50 +00:00
|
|
|
. info A plain function name is parsed as defined(...).
|
2020-11-20 03:54:37 +00:00
|
|
|
.else
|
|
|
|
. error
|
|
|
|
.endif
|
|
|
|
|
|
|
|
# A plain symbol name may start with one of the function names, in this case
|
|
|
|
# 'defined'.
|
|
|
|
.if defined-var
|
|
|
|
. error
|
|
|
|
.else
|
|
|
|
. info Symbols may start with a function name.
|
|
|
|
.endif
|
|
|
|
|
2022-02-05 20:03:50 +00:00
|
|
|
defined-var= # defined but empty
|
2020-11-20 03:54:37 +00:00
|
|
|
.if defined-var
|
|
|
|
. info Symbols may start with a function name.
|
|
|
|
.else
|
|
|
|
. error
|
|
|
|
.endif
|
|
|
|
|
|
|
|
# Missing closing parenthesis when parsing the function argument.
|
|
|
|
.if defined(
|
|
|
|
. error
|
|
|
|
.else
|
|
|
|
. error
|
|
|
|
.endif
|