aboutsummaryrefslogtreecommitdiff
path: root/contrib/bmake/unit-tests/directive-ifndef.mk
blob: 44eec55b4a87fc6bb3c98d95ceaf770a281e2ce6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# $NetBSD: directive-ifndef.mk,v 1.9 2023/10/19 18:24:33 rillig Exp $
#
# Tests for the .ifndef directive, which can be used for multiple-inclusion
# guards.  In contrast to C, where #ifndef and #define nicely line up the
# macro name, there is no such syntax in make.  Therefore, it is more
# common to use .if !defined(GUARD) instead.
#
# See also:
#	directive-include-guard.mk

.ifndef GUARD
GUARD=	# defined
# expect+1: guarded section
.  info guarded section
.endif

.ifndef GUARD
GUARD=	# defined
.  info guarded section
.endif

.if !defined(GUARD)
GUARD=	# defined
.  info guarded section
.endif


# The '.ifndef' directive can be used with multiple arguments, even negating
# them.  Since these conditions are confusing for humans, they should be
# replaced with easier-to-understand plain '.if' directives.
DEFINED=
.ifndef UNDEFINED && UNDEFINED
.else
.  error
.endif
.ifndef UNDEFINED && DEFINED
.  error
.endif
.ifndef DEFINED && DEFINED
.  error
.endif
.ifndef !UNDEFINED && !UNDEFINED
.  error
.endif
.ifndef !UNDEFINED && !DEFINED
.  error
.endif
.ifndef !DEFINED && !DEFINED
.else
.  error
.endif


# The negation from the 'if-not-defined' directive only applies to bare words,
# but not to numbers, quoted strings or expressions.  Those are evaluated
# without extra negation, just like in a plain '.if' directive.
.ifndef 0
.  error
.endif
.ifndef 1
.else
.  error
.endif
.ifndef ""
.  error
.endif
.ifndef "word"
.else
.  error
.endif
.ifndef ${:UUNDEFINED}
.else
.  error
.endif
.ifndef ${:UDEFINED}
.  error
.endif
.ifndef ${:U0}
.  error
.endif
.ifndef ${:U1}
.else
.  error
.endif


all: