1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/makefiles/utils/variables.mk
Gaëtan Harter 2c5eeca47a
makefiles/utils: function to memoize a variable evaluation
This allow deferring a variable evaluation to its usage but still
benefit from only evaluating it once on multiple uses.
2019-06-28 11:34:43 +02:00

34 lines
1.0 KiB
Makefile

# Utilities to set variables and environment for targets
# These functions should help replacing immediate evaluation and global 'export'
# Evaluate a deferred variable only once on its first usage
# Uses after that will be as if it was an immediate evaluation
# This can replace using `:=` by default
#
# The goal is to use it for `shell` commands
#
# variable = $(call memoized,<variable>,<value>)
#
# Parameters
# variable: name of the variable you set
# value: value that should be set when evaluated
memoized = $2$(eval $1:=$2)
# Target specific export the variables for that target
#
# target-export-variables <target> <variables>
#
# Parameters
# target: name of target
# variables: the variables to export
#
# The variable will only be evaluated when executing the target as when
# doing export
target-export-variables = $(foreach var,$(2),$(call _target-export-variable,$1,$(var)))
# '$1: export $2' cannot be used alone
# By using '?=' the variable is evaluated at runtime only
_target-export-variable = $(eval $1: export $2?=)