您能帮我理解 GNU Make(版本 3.81)如何处理简单的 Makefile 吗?这是文件:
.PHONY: a b c e f
a : b c
@echo "> a(b,c)"
e : a
@echo "> e(a)"
e : f
@echo "> e(f)"
f :
@echo "> f()"
b :
@echo "> b()"
c :
@echo "> c()"
现在我运行命令
make e
构建“e”目标。 Make 的输出如下所示:
Makefile:7: warning: overriding commands for target `e'
Makefile:5: warning: ignoring old commands for target `e'
> f()
> b()
> c()
> a(b,c)
> e(f)
http://www.gnu.org/software/make/manual/html_node/Error-Messages.html给出下一个解释:
‘warning: overriding recipe for target `xxx'’
‘warning: ignoring old recipe for target `xxx'’
GNU make allows only one recipe to be specified per target (except for double-colon rules). If you give a recipe for a target which already has been defined to have one, this warning is issued and the second recipe will overwrite the first.
但是从输出中我们可以看到构建“a”目标的命令也被执行。我认为根据“错误消息”页面 make 的描述,在处理此 Makefile 并尝试构建“e”目标(make e)时,应该首先决定“e”依赖于“a”,然后覆盖此'e' 取决于 'f'。输出应如下所示:
Makefile:7: warning: overriding commands for target `e'
Makefile:5: warning: ignoring old commands for target `e'
> f()
> e(f)
但看起来 make 仍然记得“e”依赖于“a”并且根本不覆盖配方。
请帮助我理解这种行为。为什么即使在配方覆盖之后,构建“a”目标的命令仍然执行?
最佳答案
依赖关系与命令不同。对 a
的依赖不会被忘记,但命令会被忘记。
关于makefile - GNU 制造商 : warning: ignoring old commands for target `xxx' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22127119/