var-op-append.mk revision 1.9 1 # $NetBSD: var-op-append.mk,v 1.9 2021/04/04 10:13:09 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_Var
30 C++= value
31 .if ${C+} != "value" || defined(C++)
32 . error
33 .endif
34
35 # Before var.c 1.793 from 2021-02-03, the variable name of a newly created
36 # variable was expanded two times in a row, which was unexpected but
37 # irrelevant in practice since variable names containing dollars lead to
38 # strange side effects in several other places as well.
39 .MAKEFLAGS: -dv
40 VAR.${:U\$\$\$\$\$\$\$\$}+= dollars
41 .MAKEFLAGS: -d0
42 .if ${VAR.${:U\$\$\$\$\$\$\$\$}} != "dollars"
43 . error
44 .endif
45
46 all:
47