1 1.6 rillig # $NetBSD: cond-func.mk,v 1.6 2020/11/08 21:40:13 rillig Exp $ 2 1.1 rillig # 3 1.1 rillig # Tests for those parts of the functions in .if conditions that are common 4 1.1 rillig # among several functions. 5 1.1 rillig # 6 1.1 rillig # The below test uses the function defined(...) since it has no side-effects, 7 1.1 rillig # the other functions (except empty(...)) would work equally well. 8 1.1 rillig 9 1.1 rillig DEF= defined 10 1.1 rillig ${:UA B}= variable name with spaces 11 1.1 rillig ${:UVAR(value)}= variable name with parentheses 12 1.6 rillig ${:UVAR{value}}= variable name with balanced braces 13 1.6 rillig 14 1.6 rillig # Really strange variable names must be given indirectly via another variable, 15 1.6 rillig # so that no unbalanced braces appear in the top-level expression. 16 1.6 rillig VARNAME_UNBALANCED_BRACES= VAR{{{value 17 1.6 rillig ${VARNAME_UNBALANCED_BRACES}= variable name with unbalanced braces 18 1.1 rillig 19 1.1 rillig .if !defined(DEF) 20 1.4 rillig . error 21 1.1 rillig .endif 22 1.1 rillig 23 1.3 rillig # Horizontal whitespace (space tab) after the opening parenthesis is ignored. 24 1.1 rillig .if !defined( DEF) 25 1.4 rillig . error 26 1.1 rillig .endif 27 1.1 rillig 28 1.3 rillig # Horizontal whitespace (space tab) before the closing parenthesis is ignored. 29 1.1 rillig .if !defined(DEF ) 30 1.4 rillig . error 31 1.1 rillig .endif 32 1.1 rillig 33 1.1 rillig # The argument of a function must not directly contain whitespace. 34 1.1 rillig .if !defined(A B) 35 1.4 rillig . error 36 1.1 rillig .endif 37 1.1 rillig 38 1.1 rillig # If necessary, the whitespace can be generated by a variable expression. 39 1.1 rillig .if !defined(${:UA B}) 40 1.4 rillig . error 41 1.1 rillig .endif 42 1.1 rillig 43 1.1 rillig # Characters that could be mistaken for operators must not appear directly 44 1.1 rillig # in a function argument. As with whitespace, these can be generated 45 1.1 rillig # indirectly. 46 1.1 rillig # 47 1.1 rillig # It's not entirely clear why these characters are forbidden. 48 1.1 rillig # The most plausible reason seems to be typo detection. 49 1.1 rillig .if !defined(A&B) 50 1.4 rillig . error 51 1.1 rillig .endif 52 1.1 rillig .if !defined(A|B) 53 1.4 rillig . error 54 1.1 rillig .endif 55 1.1 rillig 56 1.1 rillig # Even parentheses may appear in variable names. 57 1.1 rillig # They must be balanced though. 58 1.1 rillig .if !defined(VAR(value)) 59 1.4 rillig . error 60 1.1 rillig .endif 61 1.1 rillig 62 1.1 rillig # Braces do not have any special meaning when parsing arguments. 63 1.1 rillig .if !defined(VAR{value}) 64 1.4 rillig . error 65 1.1 rillig .endif 66 1.1 rillig 67 1.6 rillig # Braces do not have any special meaning when parsing arguments. 68 1.6 rillig # They don't need to be balanced. 69 1.6 rillig .if !defined(VAR{{{value) 70 1.6 rillig . error 71 1.6 rillig .endif 72 1.6 rillig 73 1.2 rillig # There may be spaces around the operators and parentheses, and even 74 1.2 rillig # inside the parentheses. The spaces inside the parentheses are not 75 1.2 rillig # allowed for the empty() function (see cond-func-empty.mk), therefore 76 1.2 rillig # they are typically omitted for the other functions as well. 77 1.2 rillig .if ! defined ( DEF ) 78 1.2 rillig . error 79 1.2 rillig .endif 80 1.2 rillig 81 1.5 rillig # The following condition is interpreted as defined(A) && defined(B). 82 1.5 rillig # In lack of a function call expression, each kind of .if directive has a 83 1.5 rillig # default function that is called when a bare word is parsed. For the plain 84 1.5 rillig # .if directive, this function is defined(); see "struct If ifs" in cond.c. 85 1.5 rillig .if A&B 86 1.5 rillig . error 87 1.5 rillig .endif 88 1.5 rillig 89 1.1 rillig all: 90 1.1 rillig @:; 91