1 1.8 rillig # $NetBSD: cond-func-exists.mk,v 1.8 2025/01/10 23:00:38 rillig Exp $ 2 1.1 rillig # 3 1.2 rillig # Tests for the exists() function in .if conditions. 4 1.1 rillig 5 1.4 rillig .if !exists(.) 6 1.5 rillig . error 7 1.3 rillig .endif 8 1.3 rillig 9 1.3 rillig # The argument to the function must not be enclosed in quotes. 10 1.3 rillig # Neither double quotes nor single quotes are allowed. 11 1.3 rillig .if exists(".") 12 1.5 rillig . error 13 1.3 rillig .endif 14 1.3 rillig 15 1.3 rillig .if exists('.') 16 1.5 rillig . error 17 1.3 rillig .endif 18 1.3 rillig 19 1.3 rillig # The only way to escape characters that would otherwise influence the parser 20 1.7 rillig # is to enclose them in an expression. For function arguments, 21 1.3 rillig # neither the backslash nor the dollar sign act as escape character. 22 1.3 rillig .if exists(\.) 23 1.5 rillig . error 24 1.3 rillig .endif 25 1.3 rillig 26 1.4 rillig .if !exists(${:U.}) 27 1.5 rillig . error 28 1.3 rillig .endif 29 1.3 rillig 30 1.7 rillig # The argument to the function can have several expressions. 31 1.3 rillig # See cond-func.mk for the characters that cannot be used directly. 32 1.4 rillig .if !exists(${.PARSEDIR}/${.PARSEFILE}) 33 1.5 rillig . error 34 1.4 rillig .endif 35 1.4 rillig 36 1.4 rillig # Whitespace is trimmed on both sides of the function argument. 37 1.4 rillig .if !exists( . ) 38 1.5 rillig . error 39 1.3 rillig .endif 40 1.1 rillig 41 1.8 rillig # Expressions in the argument of a function call don't have to be defined. 42 1.8 rillig .if exists(${UNDEF}) 43 1.8 rillig . error 44 1.8 rillig .endif 45 1.8 rillig 46 1.6 rillig # The exists function does not really look up the file in the file system, 47 1.6 rillig # instead it uses a cache that is preloaded very early, before parsing the 48 1.6 rillig # first makefile. At that time, the file did not exist yet. 49 1.6 rillig _!= > cond-func-exists.just-created 50 1.6 rillig .if exists(cond-func-exists.just-created) 51 1.6 rillig . error 52 1.6 rillig .endif 53 1.6 rillig _!= rm cond-func-exists.just-created 54 1.6 rillig 55 1.1 rillig all: 56 1.1 rillig @:; 57