var-op-append.mk revision 1.7 1 # $NetBSD: var-op-append.mk,v 1.7 2020/10/30 20:36:33 rillig Exp $
2 #
3 # Tests for the += variable assignment operator, which appends to a variable,
4 # creating it if necessary.
5
6 # Appending to an undefined variable is possible.
7 # The variable is created, and no extra space is added before the value.
8 VAR+= one
9 .if ${VAR} != "one"
10 . error
11 .endif
12
13 # Appending to an existing variable adds a single space and the value.
14 VAR+= two
15 .if ${VAR} != "one two"
16 . error
17 .endif
18
19 # Appending an empty string nevertheless adds a single space.
20 VAR+= # empty
21 .if ${VAR} != "one two "
22 . error
23 .endif
24
25 # Variable names may contain '+', and this character is also part of the
26 # '+=' assignment operator. As far as possible, the '+' is interpreted as
27 # part of the assignment operator.
28 #
29 # See Parse_DoVar
30 C++= value
31 .if ${C+} != "value" || defined(C++)
32 . error
33 .endif
34
35 # Try out how often the variable name is expanded when appending to a
36 # nonexistent variable.
37 # As of 2020-10-30, that's two times.
38 # XXX: That's one time too often.
39 # See Var_Append, the call to Var_Set.
40 .MAKEFLAGS: -dv
41 VAR.${:U\$\$\$\$\$\$\$\$}+= dollars
42 .MAKEFLAGS: -d0
43 .if ${VAR.${:U\$\$\$\$}} != "dollars"
44 . error
45 .endif
46
47 all:
48 @:;
49