skip to content
Alvin Lucillo

Deferred and immediate expansion

/ 1 min read

DEFERRED below contains the text $(NAME), while IMMEDIATE contains the value of the variable (Alice). After a new value is assigned to NAME, DEFERRED evaluates the NAME variable’s value when it’s referenced, that’s why it has the latest value, whereas IMMEDIATE expands the value of the NAME during assignment. This means if you want a stable value, use :=.

NAME = Alice

DEFERRED = $(NAME)
IMMEDIATE := $(NAME)

NAME = Bob

.PHONY: show

show:
	@echo "Deferred: $(DEFERRED)"
	@echo "Immediate: $(IMMEDIATE)"
$ make show
Deferred: Bob
Immediate: Alice