Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
makefile: setting variables globally as well as under phony target
GLOBAL_VAR=GOLBAL_VAR_VALUE # This value will be set as it is global
export GLOBAL_VAR_EXPORT=GLOBAL_VAR_EXPORT_VALUE # This value will be set as it is global
# @$(foreach var, $(filter GB_ENV_%, $(.VARIABLES)), $(eval export $(subst GB_ENV_,,$(var))=$($(var))))
all:
# Following two vars remain unset as Makefile doesn't set var under phony target
@LOCAL_VAR=LOCAL_VAR_VALUE
@export LOCAL_VAR_EXPORT=LOCAL_VAR_EXPORT_VALUE
# Following two vars will be set using eval
@$(eval LOCAL_VAR_EVAL=LOCAL_VAR_EVAL_VALUE)
@$(eval export LOCAL_VAR_EXPORT_EVAL=LOCAL_VAR_EXPORT_EVAL_VALUE)
@echo "GLOBAL_VAR : $(GLOBAL_VAR)"
@echo "GLOBAL_VAR_EXPORT : $(GLOBAL_VAR_EXPORT)"
@echo "LOCAL_VAR : $(LOCAL_VAR)"
@echo "LOCAL_VAR_EXPORT : $(LOCAL_VAR_EXPORT)"
@echo "LOCAL_VAR_EVAL : $(LOCAL_VAR_EVAL)"
@echo "LOCAL_VAR_EXPORT_EVAL : $(LOCAL_VAR_EXPORT_EVAL)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment