使所有规则取决于 Makefile 本身
当我更改 Makefile 时,它的规则可能已更改,因此应该重新评估它们,但 make 似乎并不这么认为。
有没有什么办法可以说,在 Makefile 中,它的所有目标,无论是哪个,都依赖于 Makefile 本身? (不管它的名字是什么。)
我正在使用 GNU make。
When I change a Makefile, its rules may have changed, so they should be reevaluated, but make doesn't seem to think so.
Is there any way to say, in a Makefile, that all of its targets, no matter which, depend on the Makefile itself?
(Regardless of its name.)
I'm using GNU make.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这看起来像是 Make 应该能够做到的一件更简单、有用、合乎逻辑的事情,但事实并非如此。
这是一个解决方法。如果
clean
规则设置正确,只要 makefile 被更改,Make 就可以使用空的dummy
文件作为标记来执行它。这适用于大多数目标,即是实际文件并被 clean 删除的目标,以及依赖于它们的任何目标。副作用目标和一些
PHONY
目标会漏网。This looks like one more simple, useful, logical thing that Make should be able to do, but isn't.
Here is a workaround. If the
clean
rule is set up correctly, Make can execute it whenever the makefile has been altered, using an emptydummy
file as a marker.This will work for most targets, that is targets that are actual files and that are removed by clean, and any targets that depend on them. Side-effect targets and some
PHONY
targets will slip through the net.自 GNU make 4.3 版本以来,现在可以使用这两个 特殊变量:
让每个目标都依赖于当前的 make 文件:
将以下行放在文件顶部附近(在任何包含之前,因为它会影响 MAKEFILE_LIST):
让每个目标都依赖于当前的 make 文件以及包含的 make 文件
将以下行放在文件末尾:
Since GNU make version 4.3 it is now possible with the use of those two special variable:
To have every target depend on the current make file:
Put near the top of the file (before any include since it would affect the MAKEFILE_LIST) the following line:
To have every target depend on the current make file and also the make files which were included
Put the following line at the end of your file:
我知道的唯一答案是将 makefile 显式添加到依赖项中。例如,
The only answer I know to this is to add makefile explicitly to the dependencies. For example,