1 1.10 rillig # $NetBSD: var-op-append.mk,v 1.10 2023/06/21 07:30:50 rillig Exp $ 2 1.1 rillig # 3 1.10 rillig # Tests for the '+=' variable assignment operator, which appends to a 4 1.10 rillig # variable, creating it if necessary. 5 1.10 rillig # 6 1.10 rillig # See also 7 1.10 rillig # var-op.mk 8 1.10 rillig # 9 1.10 rillig # Standards 10 1.10 rillig # The '+=' variable assignment operator is planned to be added in 11 1.10 rillig # POSIX.1-202x. 12 1.10 rillig # 13 1.10 rillig # This implementation does not support the immediate-expansion macros 14 1.10 rillig # specified in POSIX.1-202x. All variables are delayed-expansion. 15 1.10 rillig # 16 1.10 rillig # History 17 1.10 rillig # The '+=' variable assignment operator was added before 1993-03-21. 18 1.1 rillig 19 1.5 rillig # Appending to an undefined variable is possible. 20 1.5 rillig # The variable is created, and no extra space is added before the value. 21 1.5 rillig VAR+= one 22 1.5 rillig .if ${VAR} != "one" 23 1.5 rillig . error 24 1.5 rillig .endif 25 1.5 rillig 26 1.5 rillig # Appending to an existing variable adds a single space and the value. 27 1.5 rillig VAR+= two 28 1.5 rillig .if ${VAR} != "one two" 29 1.5 rillig . error 30 1.5 rillig .endif 31 1.5 rillig 32 1.5 rillig # Appending an empty string nevertheless adds a single space. 33 1.5 rillig VAR+= # empty 34 1.5 rillig .if ${VAR} != "one two " 35 1.5 rillig . error 36 1.5 rillig .endif 37 1.5 rillig 38 1.5 rillig # Variable names may contain '+', and this character is also part of the 39 1.5 rillig # '+=' assignment operator. As far as possible, the '+' is interpreted as 40 1.5 rillig # part of the assignment operator. 41 1.5 rillig # 42 1.9 rillig # See Parse_Var 43 1.6 rillig C++= value 44 1.5 rillig .if ${C+} != "value" || defined(C++) 45 1.5 rillig . error 46 1.5 rillig .endif 47 1.1 rillig 48 1.8 rillig # Before var.c 1.793 from 2021-02-03, the variable name of a newly created 49 1.8 rillig # variable was expanded two times in a row, which was unexpected but 50 1.8 rillig # irrelevant in practice since variable names containing dollars lead to 51 1.8 rillig # strange side effects in several other places as well. 52 1.7 rillig .MAKEFLAGS: -dv 53 1.7 rillig VAR.${:U\$\$\$\$\$\$\$\$}+= dollars 54 1.7 rillig .MAKEFLAGS: -d0 55 1.8 rillig .if ${VAR.${:U\$\$\$\$\$\$\$\$}} != "dollars" 56 1.7 rillig . error 57 1.7 rillig .endif 58 1.7 rillig 59 1.1 rillig all: 60