I am trying to update a variable and then used it as prerequisite for a rule
My code is as following:
OBJ:=origin
.PHONY: all update_variables compile_obj
all: update_variables compile_obj
@echo "rule: $@"
update_variables:
@echo "rule: $@"
@echo " updating OBJ"
$(eval OBJ=updated)
compile_obj: $(OBJ)
@echo "rule: $@"
@echo " OBJ seen from inside rule is $(OBJ)"
@echo " OBJ seen as prerequisite is $^"
$(OBJ):
@touch origin
in this code, I intend for "all" to run "update_variables" first, where $(OBJ) is updated and then compile_obj, where $(OBJ) is used as a prerequisite
After "make all", following lines printed out on my terminal:
rule: update_variables
updating OBJ
rule: compile_obj
OBJ seen from inside rule is updated
OBJ seen as prerequisite is origin
rule: all
It seems to me that the rule order is what I wanted but $(OBJ) value is unexpected in rule "compile_obj":
in the recipe, $(OBJ) is seen as "updated" but $^ is still "origin" while I though they would be the same
I'm still learning make, can you please kindly instruct me why updated value of $(OBJ) are not seen in prerequisite?
question from:
https://stackoverflow.com/questions/65713599/cannot-update-variable-used-as-prerequisites 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…