Follow-up Comment #1, bug #54703 (project make):
Hello.
This is not a bug.
Argument of eval is always expanded prior evalation.
Let's see how this works.
---------
ITERATIONS:=1 2 3
ACCUMULATOR:=Macron go home :
WORD_1:=Macron
WORD_2:=go
WORD_3:=home
define ACCUMULATE
WORD:=$(WORD_$(1))
ACCUMULATOR:=$(ACCUMULATOR) $(WORD)
endef
$(foreach ITERATION,$(ITERATIONS),$(eval $(call ACCUMULATE,$(ITERATION))))
---------
* The first foreach iteration is expanded as:
WORD:=Macron
ACCUMULATOR:=Macron go home : <empty>
then evaluated
* second iteration is expanded as:
WORD:=go
ACCUMULATOR:=Macron go home : Macron
then evaluated
* third iteration is expanded as:
WORD:=home
ACCUMULATOR:=Macron go home : Macron go
and then evaluated.
-------
You need to delay expansion of $(WORD) in the ACCUMULATE until eval:
define ACCUMULATE
WORD:=$(WORD_$(1))
ACCUMULATOR:=$(ACCUMULATOR) $$(WORD)
endef
then, while processing assignment operator :=, eval expands the value a second
time
-------
For debugging, it is handy to trace eval calls, e.g.:
trace_eval = $(info $1)$(eval $1)
$(foreach ITERATION,$(ITERATIONS),$(call trace_eval,$(call
ACCUMULATE,$(ITERATION))))
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/bugs/?54703>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
_______________________________________________
Bug-make mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/bug-make