counter.mk revision 1.2
1# $NetBSD: counter.mk,v 1.2 2020/09/23 03:33:55 rillig Exp $ 2# 3# Demonstrates that it is not easily possible to let make count 4# the number of times a variable is actually accessed, using the 5# ::= variable modifier. 6# 7# As of 2020-08-02, the counter ends up at having 4 words, even 8# though the NEXT variable is only accessed 3 times. This is 9# surprising. 10# 11# A hint to this surprising behavior is that the variables don't 12# get fully expanded. For example, A does not simply contain the 13# value "1" but an additional unexpanded ${COUNTER:...} before it. 14 15.MAKEFLAGS: -dv 16 17RELEVANT= yes (load-time part) # just to filter the output 18 19COUNTER= # zero 20 21NEXT= ${COUNTER::=${COUNTER} a}${COUNTER:[#]} 22 23# This variable is first set to empty and then expanded. 24# See parse.c, function Parse_DoVar, keyword "!Var_Exists". 25A:= ${NEXT} 26B:= ${NEXT} 27C:= ${NEXT} 28 29RELEVANT= no 30 31all: 32 @: ${RELEVANT::=yes (run-time part)} 33 @echo A=${A:Q} B=${B:Q} C=${C:Q} COUNTER=${COUNTER:[#]:Q} 34 @: ${RELEVANT::=no} 35