xref: /freebsd/contrib/bmake/unit-tests/cond-func-commands.mk (revision 6a7405f5a6b639682cacf01e35d561411ff556aa)
1*6a7405f5SSimon J. Gerraty# $NetBSD: cond-func-commands.mk,v 1.6 2025/01/10 23:00:38 rillig Exp $
22c3632d1SSimon J. Gerraty#
32c3632d1SSimon J. Gerraty# Tests for the commands() function in .if conditions.
42c3632d1SSimon J. Gerraty
52c3632d1SSimon J. Gerraty.MAIN: all
62c3632d1SSimon J. Gerraty
7e2eeea75SSimon J. Gerraty# At this point, the target 'target' does not exist yet, therefore it cannot
8e2eeea75SSimon J. Gerraty# have commands.  Sounds obvious, but good to know that it is really so.
92c3632d1SSimon J. Gerraty.if commands(target)
102c3632d1SSimon J. Gerraty.  error
112c3632d1SSimon J. Gerraty.endif
122c3632d1SSimon J. Gerraty
132c3632d1SSimon J. Gerratytarget:
142c3632d1SSimon J. Gerraty
152c3632d1SSimon J. Gerraty# Now the target exists, but it still has no commands.
162c3632d1SSimon J. Gerraty.if commands(target)
172c3632d1SSimon J. Gerraty.  error
182c3632d1SSimon J. Gerraty.endif
192c3632d1SSimon J. Gerraty
202c3632d1SSimon J. Gerratytarget:
212c3632d1SSimon J. Gerraty	# not a command
222c3632d1SSimon J. Gerraty
232c3632d1SSimon J. Gerraty# Even after the comment, the target still has no commands.
242c3632d1SSimon J. Gerraty.if commands(target)
252c3632d1SSimon J. Gerraty.  error
262c3632d1SSimon J. Gerraty.endif
272c3632d1SSimon J. Gerraty
282c3632d1SSimon J. Gerratytarget:
292c3632d1SSimon J. Gerraty	@:;
302c3632d1SSimon J. Gerraty
312c3632d1SSimon J. Gerraty# Finally the target has commands.
322c3632d1SSimon J. Gerraty.if !commands(target)
332c3632d1SSimon J. Gerraty.  error
342c3632d1SSimon J. Gerraty.endif
352c3632d1SSimon J. Gerraty
36*6a7405f5SSimon J. Gerraty# Expressions in the argument of a function call don't have to be defined.
37*6a7405f5SSimon J. Gerraty.if commands(${UNDEF})
38*6a7405f5SSimon J. Gerraty.  error
39*6a7405f5SSimon J. Gerraty.endif
40*6a7405f5SSimon J. Gerraty
412c3632d1SSimon J. Gerratyall:
422c3632d1SSimon J. Gerraty	@:;
43