Makefile不会在每次调用时重新评估变量

时间:2019-09-16 07:20:51

标签: makefile

似乎Make不会保留变量的值,而是在每次调用它时重新评估它。例如:

我有一个Makefile,其中我定义了一个变量MY_VAR作为当前日期的哈希版本的前十二个数字。我有三个目标target_1target_2target_3

  • echo $(MY_VAR)一次
  • echo $(MY_VAR)两次
  • 致电target_1target_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中保留变量值而不是重新求值的最佳方法是什么?我目前的解决方法是将第一个哈希代码写入文件。

0 个答案:

没有答案
相关问题