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