1 1.7 sjg # $NetBSD: varmod-remember.mk,v 1.7 2023/02/09 07:34:15 sjg Exp $ 2 1.1 rillig # 3 1.2 rillig # Tests for the :_ modifier, which saves the current variable value 4 1.2 rillig # in the _ variable or another, to be used later again. 5 1.1 rillig 6 1.7 sjg # this should result in "1=A 2=B 3=C" 7 1.7 sjg ABC= ${A B C:L:_:range:@i@$i=${_:[$i]}@} 8 1.7 sjg 9 1.7 sjg # we compare this with a repeat later 10 1.7 sjg x:= ${ABC} 11 1.7 sjg 12 1.4 rillig .if ${1 2 3:L:_:@var@${_}@} != "1 2 3 1 2 3 1 2 3" 13 1.4 rillig . error 14 1.4 rillig .endif 15 1.4 rillig 16 1.3 rillig # In the parameterized form, having the variable name on the right side of 17 1.3 rillig # the = assignment operator is confusing. In almost all other situations 18 1.3 rillig # the variable name is on the left-hand side of the = operator. Luckily 19 1.3 rillig # this modifier is only rarely needed. 20 1.4 rillig .if ${1 2 3:L:@var@${var:_=SAVED:}@} != "1 2 3" 21 1.4 rillig . error 22 1.4 rillig .elif ${SAVED} != "3" 23 1.4 rillig . error 24 1.4 rillig .endif 25 1.4 rillig 26 1.5 rillig # The ':_' modifier takes a variable name as optional argument. This variable 27 1.5 rillig # name can refer to other variables, though this was rather an implementation 28 1.5 rillig # oversight than an intended feature. The variable name stops at the first 29 1.5 rillig # '}' or ')' and thus cannot use the usual form ${VARNAME} of long variable 30 1.5 rillig # names. 31 1.6 rillig # 32 1.6 rillig # Because of all these edge-casey conditions, this "feature" has been removed 33 1.6 rillig # in var.c 1.867 from 2021-03-14. 34 1.5 rillig S= INDIRECT_VARNAME 35 1.5 rillig .if ${value:L:@var@${var:_=$S}@} != "value" 36 1.5 rillig . error 37 1.6 rillig .elif defined(INDIRECT_VARNAME) 38 1.5 rillig . error 39 1.5 rillig .endif 40 1.5 rillig 41 1.7 sjg # we *should* get the same result as for $x above 42 1.7 sjg X:= ${ABC} 43 1.7 sjg .if $X != $x 44 1.7 sjg . error 45 1.7 sjg .endif 46 1.7 sjg 47 1.1 rillig all: 48