1*22619282SSimon J. Gerraty# $NetBSD: cond-func.mk,v 1.15 2024/07/06 21:21:10 rillig Exp $ 22c3632d1SSimon J. Gerraty# 32c3632d1SSimon J. Gerraty# Tests for those parts of the functions in .if conditions that are common 42c3632d1SSimon J. Gerraty# among several functions. 52c3632d1SSimon J. Gerraty# 6c1d01b5fSSimon J. Gerraty# The below test uses the 'defined' function since it has no side-effects. 7c1d01b5fSSimon J. Gerraty# The other functions would work equally well, except for 'empty', which 8c1d01b5fSSimon J. Gerraty# parses its argument differently from the other functions. 9c1d01b5fSSimon J. Gerraty# 102c3632d1SSimon J. Gerraty 112c3632d1SSimon J. GerratyDEF= defined 122c3632d1SSimon J. Gerraty${:UA B}= variable name with spaces 132c3632d1SSimon J. Gerraty${:UVAR(value)}= variable name with parentheses 14e2eeea75SSimon J. Gerraty${:UVAR{value}}= variable name with balanced braces 15e2eeea75SSimon J. Gerraty 16e2eeea75SSimon J. Gerraty# Really strange variable names must be given indirectly via another variable, 17e2eeea75SSimon J. Gerraty# so that no unbalanced braces appear in the top-level expression. 18e2eeea75SSimon J. GerratyVARNAME_UNBALANCED_BRACES= VAR{{{value 19e2eeea75SSimon J. Gerraty${VARNAME_UNBALANCED_BRACES}= variable name with unbalanced braces 202c3632d1SSimon J. Gerraty 212c3632d1SSimon J. Gerraty.if !defined(DEF) 222c3632d1SSimon J. Gerraty. error 232c3632d1SSimon J. Gerraty.endif 242c3632d1SSimon J. Gerraty 25956e45f6SSimon J. Gerraty# Horizontal whitespace (space tab) after the opening parenthesis is ignored. 262c3632d1SSimon J. Gerraty.if !defined( DEF) 272c3632d1SSimon J. Gerraty. error 282c3632d1SSimon J. Gerraty.endif 292c3632d1SSimon J. Gerraty 30956e45f6SSimon J. Gerraty# Horizontal whitespace (space tab) before the closing parenthesis is ignored. 312c3632d1SSimon J. Gerraty.if !defined(DEF ) 322c3632d1SSimon J. Gerraty. error 332c3632d1SSimon J. Gerraty.endif 342c3632d1SSimon J. Gerraty 352c3632d1SSimon J. Gerraty# The argument of a function must not directly contain whitespace. 36148ee845SSimon J. Gerraty# expect+1: Missing closing parenthesis for defined() 372c3632d1SSimon J. Gerraty.if !defined(A B) 382c3632d1SSimon J. Gerraty. error 392c3632d1SSimon J. Gerraty.endif 402c3632d1SSimon J. Gerraty 41d5e0a182SSimon J. Gerraty# If necessary, the whitespace can be generated by an expression. 422c3632d1SSimon J. Gerraty.if !defined(${:UA B}) 432c3632d1SSimon J. Gerraty. error 442c3632d1SSimon J. Gerraty.endif 452c3632d1SSimon J. Gerraty 462c3632d1SSimon J. Gerraty# Characters that could be mistaken for operators must not appear directly 472c3632d1SSimon J. Gerraty# in a function argument. As with whitespace, these can be generated 482c3632d1SSimon J. Gerraty# indirectly. 492c3632d1SSimon J. Gerraty# 502c3632d1SSimon J. Gerraty# It's not entirely clear why these characters are forbidden. 512c3632d1SSimon J. Gerraty# The most plausible reason seems to be typo detection. 52148ee845SSimon J. Gerraty# expect+1: Missing closing parenthesis for defined() 532c3632d1SSimon J. Gerraty.if !defined(A&B) 542c3632d1SSimon J. Gerraty. error 552c3632d1SSimon J. Gerraty.endif 56148ee845SSimon J. Gerraty# expect+1: Missing closing parenthesis for defined() 572c3632d1SSimon J. Gerraty.if !defined(A|B) 582c3632d1SSimon J. Gerraty. error 592c3632d1SSimon J. Gerraty.endif 602c3632d1SSimon J. Gerraty 612c3632d1SSimon J. Gerraty# Even parentheses may appear in variable names. 622c3632d1SSimon J. Gerraty# They must be balanced though. 632c3632d1SSimon J. Gerraty.if !defined(VAR(value)) 642c3632d1SSimon J. Gerraty. error 652c3632d1SSimon J. Gerraty.endif 662c3632d1SSimon J. Gerraty 672c3632d1SSimon J. Gerraty# Braces do not have any special meaning when parsing arguments. 682c3632d1SSimon J. Gerraty.if !defined(VAR{value}) 692c3632d1SSimon J. Gerraty. error 702c3632d1SSimon J. Gerraty.endif 712c3632d1SSimon J. Gerraty 72e2eeea75SSimon J. Gerraty# Braces do not have any special meaning when parsing arguments. 73e2eeea75SSimon J. Gerraty# They don't need to be balanced. 74e2eeea75SSimon J. Gerraty.if !defined(VAR{{{value) 75e2eeea75SSimon J. Gerraty. error 76e2eeea75SSimon J. Gerraty.endif 77e2eeea75SSimon J. Gerraty 78956e45f6SSimon J. Gerraty# There may be spaces around the operators and parentheses, and even 79956e45f6SSimon J. Gerraty# inside the parentheses. The spaces inside the parentheses are not 80c1d01b5fSSimon J. Gerraty# allowed for the 'empty' function (see cond-func-empty.mk), therefore 81956e45f6SSimon J. Gerraty# they are typically omitted for the other functions as well. 82956e45f6SSimon J. Gerraty.if ! defined ( DEF ) 83956e45f6SSimon J. Gerraty. error 84956e45f6SSimon J. Gerraty.endif 85956e45f6SSimon J. Gerraty 86*22619282SSimon J. Gerraty# Before cond.c 1.366 from 2024-07-06, the following condition was 87*22619282SSimon J. Gerraty# interpreted as defined(A) && defined(B). Each kind of .if directive has a 88e2eeea75SSimon J. Gerraty# default function that is called when a bare word is parsed. For the plain 89*22619282SSimon J. Gerraty# .if directive, this function is 'defined'; see "struct If ifs" in cond.c. 90*22619282SSimon J. Gerraty# expect+1: Unknown operator '&' 91e2eeea75SSimon J. Gerraty.if A&B 92e2eeea75SSimon J. Gerraty. error 93e2eeea75SSimon J. Gerraty.endif 94e2eeea75SSimon J. Gerraty 95*22619282SSimon J. Gerraty# The empty variable is never defined. 96e2eeea75SSimon J. Gerraty.if defined() 97e2eeea75SSimon J. Gerraty. error 98e2eeea75SSimon J. Gerraty.endif 99e2eeea75SSimon J. Gerraty 1009f45a3c8SSimon J. Gerraty# The plain word 'defined' is interpreted as 'defined(defined)', see 1019f45a3c8SSimon J. Gerraty# CondParser_ComparisonOrLeaf. 102e2eeea75SSimon J. Gerraty# That variable is not defined (yet). 103e2eeea75SSimon J. Gerraty.if defined 104e2eeea75SSimon J. Gerraty. error 105e2eeea75SSimon J. Gerraty.else 106148ee845SSimon J. Gerraty# expect+1: A plain function name is parsed as defined(...). 1079f45a3c8SSimon J. Gerraty. info A plain function name is parsed as defined(...). 108e2eeea75SSimon J. Gerraty.endif 109e2eeea75SSimon J. Gerraty 1109f45a3c8SSimon J. Gerraty# If a variable named 'defined' is actually defined, the bare word 'defined' 1119f45a3c8SSimon J. Gerraty# is interpreted as 'defined(defined)', and the condition evaluates to true. 1129f45a3c8SSimon J. Gerratydefined= # defined but empty 113e2eeea75SSimon J. Gerraty.if defined 114148ee845SSimon J. Gerraty# expect+1: A plain function name is parsed as defined(...). 1159f45a3c8SSimon J. Gerraty. info A plain function name is parsed as defined(...). 116e2eeea75SSimon J. Gerraty.else 117e2eeea75SSimon J. Gerraty. error 118e2eeea75SSimon J. Gerraty.endif 119e2eeea75SSimon J. Gerraty 120e2eeea75SSimon J. Gerraty# A plain symbol name may start with one of the function names, in this case 121e2eeea75SSimon J. Gerraty# 'defined'. 122e2eeea75SSimon J. Gerraty.if defined-var 123e2eeea75SSimon J. Gerraty. error 124e2eeea75SSimon J. Gerraty.else 125148ee845SSimon J. Gerraty# expect+1: Symbols may start with a function name. 126e2eeea75SSimon J. Gerraty. info Symbols may start with a function name. 127e2eeea75SSimon J. Gerraty.endif 128e2eeea75SSimon J. Gerraty 1299f45a3c8SSimon J. Gerratydefined-var= # defined but empty 130e2eeea75SSimon J. Gerraty.if defined-var 131148ee845SSimon J. Gerraty# expect+1: Symbols may start with a function name. 132e2eeea75SSimon J. Gerraty. info Symbols may start with a function name. 133e2eeea75SSimon J. Gerraty.else 134e2eeea75SSimon J. Gerraty. error 135e2eeea75SSimon J. Gerraty.endif 136e2eeea75SSimon J. Gerraty 137148ee845SSimon J. Gerraty# expect+1: Missing closing parenthesis for defined() 138e2eeea75SSimon J. Gerraty.if defined( 139e2eeea75SSimon J. Gerraty. error 140e2eeea75SSimon J. Gerraty.else 141e2eeea75SSimon J. Gerraty. error 142e2eeea75SSimon J. Gerraty.endif 143