counter.mk revision 1.4
1# $NetBSD: counter.mk,v 1.4 2020/09/23 07:54:08 rillig Exp $
2#
3# Demonstrates how to let make count the number of times a variable
4# is actually accessed, using the ::= variable modifier.
5#
6# This works since 2020-09-23.  Before that, the counter ended up at having
7# 4 words, even though the NEXT variable was only accessed 3 times.
8
9RELEVANT=	yes (load-time part)	# just to filter the output
10
11COUNTER=	# zero
12
13NEXT=		${COUNTER::=${COUNTER} a}${COUNTER:[#]}
14
15# This variable is first set to empty and then expanded.
16# See parse.c, function Parse_DoVar, keyword "!Var_Exists".
17A:=		${NEXT}
18B:=		${NEXT}
19C:=		${NEXT}
20
21RELEVANT=	no
22
23all:
24	@: ${RELEVANT::=yes (run-time part)}
25	@echo A=${A:Q} B=${B:Q} C=${C:Q} COUNTER=${COUNTER:[#]:Q}
26	@: ${RELEVANT::=no}
27