counter.mk revision 1.1
11.1Srillig# $NetBSD: counter.mk,v 1.1 2020/08/02 14:53:02 rillig Exp $
21.1Srillig#
31.1Srillig# Demonstrates that it is not easily possible to let make count
41.1Srillig# the number of times a variable is actually accessed.
51.1Srillig#
61.1Srillig# As of 2020-08-02, the counter ends up at having 4 words, even
71.1Srillig# though the NEXT variable is only accessed 3 times.  This is
81.1Srillig# surprising.
91.1Srillig#
101.1Srillig# A hint to this surprising behavior is that the variables don't
111.1Srillig# get fully expanded.  For example, A does not simply contain the
121.1Srillig# value "1" but an additional unexpanded ${COUNTER:...} before it.
131.1Srillig
141.1SrilligRELEVANT=	yes (load-time part)	# just to filter the output
151.1Srillig
161.1SrilligCOUNTER=	# zero
171.1Srillig
181.1SrilligNEXT=		${COUNTER::=${COUNTER} a}${COUNTER:[#]}
191.1Srillig
201.1Srillig# This variable is first set to empty and then expanded.
211.1Srillig# See parse.c, function Parse_DoVar, keyword "!Var_Exists".
221.1SrilligA:=		${NEXT}
231.1SrilligB:=		${NEXT}
241.1SrilligC:=		${NEXT}
251.1Srillig
261.1SrilligRELEVANT=	no
271.1Srillig
281.1Srilligall:
291.1Srillig	@: ${RELEVANT::=yes (run-time part)}
301.1Srillig	@echo A=${A:Q} B=${B:Q} C=${C:Q} COUNTER=${COUNTER:[#]:Q}
311.1Srillig	@: ${RELEVANT::=no}
32