Makefile: value assignment to variable

Makefile: Exploring different ways to set value of a variable
# Ref: https://www.gnu.org/software/make/manual/html_node/Setting.html#Setting
########
# Setting variables:
# ?= Set variable if it is empty
# := Expand value variable before assignment,
# NOTE: (1) The behaviour of ::= is same as :=
# (2) Expansion of value variable will be only once at the of value assignment.
# = Simple variable assignment, value will evaluated/expanded on its usage
# += Append value to variable
# != Value variable will be evaluated before assignment.
# override directive
########
# UnComment following line NOT_SET_VAR will have VAL_0
# otherwise VAL_1
# NOT_SET_VAR = VAL_0
# Only set value to VAL_1 if NOT_SET_VAR hasn't got any value
NOT_SET_VAR ?= VAL_1
########
########
# EXPAND_VAR_ASSIGNMENT should be set to ZERO
VAR_0 := 10
VAR_1 := $(VAR_0)
ifeq ($(VAR_1),10)
EXPAND_VAR_ASSIGNMENT := ZERO
else
EXPAND_VAR_ASSIGNMENT := ONE
endif
########
# Simple assignment
VAR_X = 100
VAR_Y = 200
VAR_Z = $(VAR_X),$(VAR_Y),300 # On usage of VAR_Z, it will be expanded
# and it will end up with 100,200,300
# UnComment following line, the VAR_Z will show 200,200,300
# VAR_X = 200
########
# Appending
VAR_APPEND := 1
VAR_APPEND += 2 # VAR_APPEND will have 1 2
########
# Override: If a var has been set with command argument then
# simple assignment will not change its value.
# make -f variables.mk VAR_OVERRIDE_0=300
override VAR_OVERRIDE_0 = 200
override VAR_OVERRIDE_1 := 200
override VAR_OVERRIDE_APPEND += 200
all:
@echo "NOT_SET_VAR is having $(NOT_SET_VAR)"
@echo "EXPAND_VAR_ASSIGNMENT is having $(EXPAND_VAR_ASSIGNMENT)"
@echo "VAR_Z is having $(VAR_Z)"
@echo "VAR_APPEND is having $(VAR_APPEND)"
@echo "VAR_OVERRIDE_0 is having $(VAR_OVERRIDE_0)"
@echo "VAR_OVERRIDE_1 is having $(VAR_OVERRIDE_1)"
@echo "VAR_OVERRIDE_APPEND is having $(VAR_OVERRIDE_APPEND)"

Setting env variables in makefile

Makefile: Setting up environment variables globally as well as from a 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)"