xref: /freebsd/contrib/bmake/unit-tests/directive-ifdef.mk (revision 06c3fb2749bda94cb5201f81ffdb8fa6c3161b2e)
1# $NetBSD: directive-ifdef.mk,v 1.5 2022/01/23 21:48:59 rillig Exp $
2#
3# Tests for the .ifdef directive, which evaluates bare words by calling
4# 'defined(word)'.
5
6DEFINED=	defined
7
8# There is no variable named 'UNDEF', therefore the condition evaluates to
9# false.
10.ifdef UNDEF
11.  error
12.endif
13
14# There is a variable named 'DEFINED', so the condition evaluates to true.
15.ifdef DEFINED
16.else
17.  error
18.endif
19
20# Since a bare word is an abbreviation for 'defined(word)', these can be
21# used to construct complex conditions.
22.ifdef UNDEF && DEFINED
23.  error
24.endif
25.ifdef UNDEF || DEFINED
26.else
27.  error
28.endif
29
30# It looks redundant to have a call to defined() in an .ifdef, but it's
31# possible.  The '.ifdef' only affects bare words, not function calls.
32.ifdef defined(DEFINED)
33.else
34.  error
35.endif
36
37# String literals are handled the same in all variants of the '.if' directive,
38# they evaluate to true if they are not empty, therefore this particular
39# example looks confusing and is thus not found in practice.
40.ifdef ""
41.  error
42.else
43.endif
44
45# Whitespace counts as non-empty as well.
46.ifdef " "
47.else
48.  error
49.endif
50
51all: .PHONY
52