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