似乎Make不会保留变量的值,而是在每次调用它时重新评估它。例如:
我有一个Makefile,其中我定义了一个变量MY_VAR
作为当前日期的哈希版本的前十二个数字。我有三个目标target_1
,target_2
和target_3
:
echo $(MY_VAR)
一次echo $(MY_VAR)
两次target_1
和target_2
当我运行make target_3
时,我希望相同的哈希值将被打印3次。但是相反,我得到了类似的东西:
>>> make target_3
017af0c6483b
9873732118e7
7c78d1e4ba89
完整的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
在Make中保留变量值而不是重新求值的最佳方法是什么?我目前的解决方法是将第一个哈希代码写入文件。