xref: /freebsd/contrib/bmake/unit-tests/cond-func-exists.mk (revision 6a7405f5a6b639682cacf01e35d561411ff556aa)
1*6a7405f5SSimon J. Gerraty# $NetBSD: cond-func-exists.mk,v 1.8 2025/01/10 23:00:38 rillig Exp $
22c3632d1SSimon J. Gerraty#
32c3632d1SSimon J. Gerraty# Tests for the exists() function in .if conditions.
42c3632d1SSimon J. Gerraty
52c3632d1SSimon J. Gerraty.if !exists(.)
62c3632d1SSimon J. Gerraty.  error
72c3632d1SSimon J. Gerraty.endif
82c3632d1SSimon J. Gerraty
92c3632d1SSimon J. Gerraty# The argument to the function must not be enclosed in quotes.
102c3632d1SSimon J. Gerraty# Neither double quotes nor single quotes are allowed.
112c3632d1SSimon J. Gerraty.if exists(".")
122c3632d1SSimon J. Gerraty.  error
132c3632d1SSimon J. Gerraty.endif
142c3632d1SSimon J. Gerraty
152c3632d1SSimon J. Gerraty.if exists('.')
162c3632d1SSimon J. Gerraty.  error
172c3632d1SSimon J. Gerraty.endif
182c3632d1SSimon J. Gerraty
192c3632d1SSimon J. Gerraty# The only way to escape characters that would otherwise influence the parser
20d5e0a182SSimon J. Gerraty# is to enclose them in an expression.  For function arguments,
212c3632d1SSimon J. Gerraty# neither the backslash nor the dollar sign act as escape character.
222c3632d1SSimon J. Gerraty.if exists(\.)
232c3632d1SSimon J. Gerraty.  error
242c3632d1SSimon J. Gerraty.endif
252c3632d1SSimon J. Gerraty
262c3632d1SSimon J. Gerraty.if !exists(${:U.})
272c3632d1SSimon J. Gerraty.  error
282c3632d1SSimon J. Gerraty.endif
292c3632d1SSimon J. Gerraty
30d5e0a182SSimon J. Gerraty# The argument to the function can have several expressions.
312c3632d1SSimon J. Gerraty# See cond-func.mk for the characters that cannot be used directly.
322c3632d1SSimon J. Gerraty.if !exists(${.PARSEDIR}/${.PARSEFILE})
332c3632d1SSimon J. Gerraty.  error
342c3632d1SSimon J. Gerraty.endif
352c3632d1SSimon J. Gerraty
362c3632d1SSimon J. Gerraty# Whitespace is trimmed on both sides of the function argument.
372c3632d1SSimon J. Gerraty.if !exists(	.	)
382c3632d1SSimon J. Gerraty.  error
392c3632d1SSimon J. Gerraty.endif
402c3632d1SSimon J. Gerraty
41*6a7405f5SSimon J. Gerraty# Expressions in the argument of a function call don't have to be defined.
42*6a7405f5SSimon J. Gerraty.if exists(${UNDEF})
43*6a7405f5SSimon J. Gerraty.  error
44*6a7405f5SSimon J. Gerraty.endif
45*6a7405f5SSimon J. Gerraty
4606b9b3e0SSimon J. Gerraty# The exists function does not really look up the file in the file system,
4706b9b3e0SSimon J. Gerraty# instead it uses a cache that is preloaded very early, before parsing the
4806b9b3e0SSimon J. Gerraty# first makefile.  At that time, the file did not exist yet.
4906b9b3e0SSimon J. Gerraty_!=	> cond-func-exists.just-created
5006b9b3e0SSimon J. Gerraty.if exists(cond-func-exists.just-created)
5106b9b3e0SSimon J. Gerraty.  error
5206b9b3e0SSimon J. Gerraty.endif
5306b9b3e0SSimon J. Gerraty_!=	rm cond-func-exists.just-created
5406b9b3e0SSimon J. Gerraty
552c3632d1SSimon J. Gerratyall:
562c3632d1SSimon J. Gerraty	@:;
57