11.6Srillig# $NetBSD: counter.mk,v 1.6 2021/04/04 10:13:09 rillig Exp $
21.1Srillig#
31.3Srillig# Demonstrates how to let make count the number of times a variable
41.3Srillig# is actually accessed, using the ::= variable modifier.
51.1Srillig#
61.3Srillig# This works since 2020-09-23.  Before that, the counter ended up at having
71.3Srillig# 4 words, even though the NEXT variable was only accessed 3 times.
81.5Srillig# The cause for this surprising behavior was that the ::= variable modifiers
91.5Srillig# returned an error marker instead of a simple empty string.
101.1Srillig
111.1SrilligRELEVANT=	yes (load-time part)	# just to filter the output
121.1Srillig
131.1SrilligCOUNTER=	# zero
141.1Srillig
151.1SrilligNEXT=		${COUNTER::=${COUNTER} a}${COUNTER:[#]}
161.1Srillig
171.1Srillig# This variable is first set to empty and then expanded.
181.6Srillig# See parse.c, function Parse_Var, keyword "!Var_Exists".
191.1SrilligA:=		${NEXT}
201.1SrilligB:=		${NEXT}
211.1SrilligC:=		${NEXT}
221.1Srillig
231.1SrilligRELEVANT=	no
241.1Srillig
251.1Srilligall:
261.1Srillig	@: ${RELEVANT::=yes (run-time part)}
271.1Srillig	@echo A=${A:Q} B=${B:Q} C=${C:Q} COUNTER=${COUNTER:[#]:Q}
281.1Srillig	@: ${RELEVANT::=no}
29