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