directive-undef.mk revision 1.8 1 1.8 rillig # $NetBSD: directive-undef.mk,v 1.8 2020/12/19 22:10:18 rillig Exp $
2 1.1 rillig #
3 1.2 rillig # Tests for the .undef directive.
4 1.6 rillig #
5 1.6 rillig # See also:
6 1.6 rillig # directive-misspellings.mk
7 1.1 rillig
8 1.3 rillig # As of 2020-07-28, .undef only undefines the first variable.
9 1.3 rillig # All further variable names are silently ignored.
10 1.3 rillig # See parse.c, string literal "undef".
11 1.3 rillig 1= 1
12 1.3 rillig 2= 2
13 1.3 rillig 3= 3
14 1.3 rillig .undef 1 2 3
15 1.3 rillig .if ${1:U_}${2:U_}${3:U_} != _23
16 1.4 rillig . warning $1$2$3
17 1.3 rillig .endif
18 1.1 rillig
19 1.8 rillig
20 1.8 rillig # Without any arguments, until var.c 1.736 from 2020-12-19, .undef tried
21 1.8 rillig # to delete the variable with the empty name, which never exists; see
22 1.8 rillig # varname-empty.mk. Since var.c 1.737 from 2020-12-19, .undef complains
23 1.8 rillig # about a missing argument.
24 1.8 rillig .undef
25 1.8 rillig
26 1.8 rillig
27 1.8 rillig # Trying to delete the variable with the empty name is ok, it just won't
28 1.8 rillig # ever do anything since that variable is never defined.
29 1.8 rillig .undef ${:U}
30 1.8 rillig
31 1.8 rillig
32 1.8 rillig # The argument of .undef is a single word, delimited by whitespace, without
33 1.8 rillig # any possibility of escaping or having variable expressions containing
34 1.8 rillig # spaces. This word is then expanded exactly once, and the expanded string
35 1.8 rillig # is the single variable name. This allows variable names to contain spaces,
36 1.8 rillig # as well as unbalanced single and double quotes.
37 1.8 rillig 1= 1
38 1.8 rillig 2= 2
39 1.8 rillig 3= 3
40 1.8 rillig ${:U1 2 3}= one two three
41 1.8 rillig VARNAMES= 1 2 3
42 1.8 rillig .undef ${VARNAMES} # undefines the variable "1 2 3"
43 1.8 rillig .if defined(${:U1 2 3})
44 1.8 rillig . error
45 1.8 rillig .endif
46 1.8 rillig .if ${1}${2}${3} != "123" # these are still defined
47 1.8 rillig . error
48 1.8 rillig .endif
49 1.8 rillig .undef 1
50 1.8 rillig .undef 2
51 1.8 rillig .undef 3
52 1.5 rillig
53 1.7 rillig
54 1.7 rillig # It must be possible to undefine variables whose name includes spaces.
55 1.7 rillig SPACE= ${:U }
56 1.7 rillig ${SPACE}= space
57 1.7 rillig .if !defined(${SPACE})
58 1.7 rillig . error
59 1.7 rillig .endif
60 1.7 rillig .undef ${SPACE}
61 1.7 rillig .if defined(${SPACE})
62 1.7 rillig . error
63 1.7 rillig .endif
64 1.7 rillig
65 1.7 rillig
66 1.7 rillig # It must be possible to undefine variables whose name includes dollars.
67 1.7 rillig DOLLAR= $$
68 1.7 rillig ${DOLLAR}= dollar
69 1.7 rillig .if !defined(${DOLLAR})
70 1.7 rillig . error
71 1.7 rillig .endif
72 1.7 rillig .undef ${DOLLAR}
73 1.7 rillig .if defined(${DOLLAR})
74 1.7 rillig . error
75 1.7 rillig .endif
76 1.7 rillig
77 1.7 rillig
78 1.1 rillig all:
79 1.1 rillig @:;
80