counter.mk revision 1.3
11.3Srillig# $NetBSD: counter.mk,v 1.3 2020/09/23 07:50:58 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.1Srillig 91.2Srillig.MAKEFLAGS: -dv 101.2Srillig 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.1Srillig# See parse.c, function Parse_DoVar, 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