【问题标题】:GNU make: “Nothing to be done for 'target'” vs. “'target' is up to date”GNU make:“'target' 没什么可做的”与“'target' 是最新的”
【发布时间】:2011-04-20 17:18:40
【问题描述】:

GNU 如何决定发出哪些消息?我使用的 Makefile 会导致 Nothing to be done for 'target' 当目标更新时发出消息。但我认为'target'是最新的会更合适。

【问题讨论】:

  • 为什么会出现这个问题?您想要关于如何修补 make 的建议吗?
  • "Nothing to be done" 从makes 的角度来看可能更准确。它所知道的只是依赖关系。没有比目标更新的依赖项,因此“无事可做”。
  • 这不是问题。我只是好奇。

标签: makefile gnu-make


【解决方案1】:

主要区别在于 gmake 是否有构建目标的规则。如果目标没有规则,但是目标存在,那么 gmake 会说,“Nothing to be done”,例如,“我不知道如何更新这个东西,但它已经存在,所以我猜有无计可施。”如果有规则,但目标已经是最新的,那么 gmake 会说,“是最新的”,例如,“我确实有更新这个东西的说明,但它似乎已经是最新的——到目前为止,所以我不会做任何事情。”

这是一个具体的例子:

$ echo "upToDate: older ; @echo done" > Makefile
$ touch older ; sleep 2 ; touch upToDate ; touch nothingToDo
$ ls --full-time -l older upToDate nothingToDo
-rw-r--r-- 1 ericm ericm 0 2011-04-20 11:13:04.970243002 -0700 nothingToDo
-rw-r--r-- 1 ericm ericm 0 2011-04-20 11:13:02.960243003 -0700 older
-rw-r--r-- 1 ericm ericm 0 2011-04-20 11:13:04.960243001 -0700 upToDate
$ gmake upToDate
gmake: `upToDate' is up to date.
$ gmake nothingToDo
gmake: Nothing to be done for `nothingToDo'.

由于 gmake 没有“nothingToDo”规则,但文件已经存在,您会收到“无事可做”消息。如果“nothingToDo”不存在,您会收到熟悉的“无规则制定”消息。

相反,因为 gmake 有“upToDate”规则,并且文件似乎是最新的,所以您会收到“是最新的”消息。

【讨论】:

  • 这不太对,如果你添加all: upToDate,那么make all 会产生与make nothingToDo 相同的消息。
  • @o11c 本质上是一样的,真​​的:gmake 没有关于如何构建“all”的说明,所以它说“nothing to do”。
  • @EricMelski 但在这种情况下不存在它不是错误。
  • @o11c 如果您觉得我的答案非常错误,请随时提交您自己的答案。
【解决方案2】:

我研究了这个问题,测试了很多场景,得到的结果是:

如果目标没有配方并且没有任何先决条件的配方被执行,那么Nothing to be done for "top target"将被打印

如果目标有recipe,但recipe没有执行,则打印is up to date

如果现有文件没有规则,则将该现有文件作为目标也打印Nothing to be done for "xxx"

【讨论】:

    猜你喜欢
    • 2016-10-23
    • 2012-09-17
    • 1970-01-01
    • 1970-01-01
    • 2011-06-25
    • 2016-06-12
    • 1970-01-01
    • 2020-02-14
    • 2021-01-01
    相关资源
    最近更新 更多