var-op-append.mk revision 1.6 1 # $NetBSD: var-op-append.mk,v 1.6 2020/10/24 08:50:17 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 all:
36 @:;
37