Skip to content

Instantly share code, notes, and snippets.

@aakbar5
Last active March 6, 2019 22:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aakbar5/824365f5e3165be17c354c49385638ee to your computer and use it in GitHub Desktop.
Save aakbar5/824365f5e3165be17c354c49385638ee to your computer and use it in GitHub Desktop.
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