varname-empty.mk revision 1.5
11.5Srillig# $NetBSD: varname-empty.mk,v 1.5 2020/08/22 21:22:24 rillig Exp $
21.1Srillig#
31.1Srillig# Tests for the special variable with the empty name.
41.1Srillig#
51.1Srillig# The variable "" is not supposed to be assigned any value.
61.1Srillig# This is because it is heavily used in the .for loop expansion,
71.1Srillig# as well as to generate arbitrary strings, as in ${:Ufallback}.
81.1Srillig
91.2Srillig# Until 2020-08-22 it was possible to assign a value to the variable with
101.2Srillig# the empty name, leading to all kinds of unexpected effects.
111.3Srillig?=	default
121.4Srillig=	assigned	# undefined behavior until 2020-08-22
131.3Srillig+=	appended
141.3Srillig:=	subst
151.5Srillig!=	echo 'shell-output'
161.1Srillig
171.1Srillig# The .for loop expands the expression ${i} to ${:U1}, ${:U2} and so on.
181.1Srillig# This only works if the variable with the empty name is guaranteed to
191.1Srillig# be undefined.
201.1Srillig.for i in 1 2 3
211.1SrilligNUMBERS+=	${i}
221.1Srillig.endfor
231.1Srillig
241.1Srilligall:
251.5Srillig	@echo out: ${:Ufallback}
261.5Srillig	@echo out: ${NUMBERS}
27