It seems like Make does not persist the value of a variable but instead re-evaluates it every time you call it. For example:
I have a Makefile where I define a variable MY_VAR as the first twelve digits of a hashed version of the current date. I have three targets target_1, target_2 and target_3 that:
echo $(MY_VAR)onceecho $(MY_VAR)twice- call
target_1andtarget_2
When I run make target_3, I expect the same hash to be printed three times. But instead, I get something like:
>>> make target_3
017af0c6483b
9873732118e7
7c78d1e4ba89
Here the complete Makefile:
MY_VAR=$(shell date +%s%N | sha1sum | cut -c1-12)
target_1:
@echo $(MY_VAR)
target_2:
@echo $(MY_VAR)
@echo $(MY_VAR)
target_3: target_1 target_2
What's the best way for persisting the value of a variable in Make, instead of re-evaluating? My current work around is that I write the first hash code into a file.