Reputation: 1580
I'm trying to modify variable inside 2nd-level target foo
(Option 2). I'd expect output to be a b c
, but I see a c
, i.e., VAR += b
is never executed. It behaves as if VAR
is local for all
target. But at the same time with Option 1, I see that b
is appended into VAR
. I suspect it is caused by :=
assignment in the target, but I couldn't find anything specific about that.
VAR = a
all: VAR += b
all: foo
# Option 1. with this line output is "a b z"
# foo: VAR += z
# Option 2. with this line output is "a c"
# foo: VAR := $(VAR) c
foo:
@echo $(VAR)
Upvotes: 1
Views: 62
Reputation: 704
The explanation is that expressions with := assignments in target specific variables are evaluated by Make right at the time of reading the makefile and not when executing recipes for targets.
This seems to be not explained at all in the corresponding chapter of Make manual
Upvotes: 1