2021-06-25 18:16:24 +00:00
|
|
|
# $NetBSD: counter.mk,v 1.6 2021/04/04 10:13:09 rillig Exp $
|
2020-09-05 16:11:04 +00:00
|
|
|
#
|
2020-11-07 19:39:21 +00:00
|
|
|
# Demonstrates how to let make count the number of times a variable
|
|
|
|
# is actually accessed, using the ::= variable modifier.
|
2020-09-05 16:11:04 +00:00
|
|
|
#
|
2020-11-07 19:39:21 +00:00
|
|
|
# This works since 2020-09-23. Before that, the counter ended up at having
|
|
|
|
# 4 words, even though the NEXT variable was only accessed 3 times.
|
|
|
|
# The cause for this surprising behavior was that the ::= variable modifiers
|
|
|
|
# returned an error marker instead of a simple empty string.
|
2020-09-05 16:11:04 +00:00
|
|
|
|
|
|
|
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.
|
2021-06-25 18:16:24 +00:00
|
|
|
# See parse.c, function Parse_Var, keyword "!Var_Exists".
|
2020-09-05 16:11:04 +00:00
|
|
|
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}
|