gpt4 book ai didi

makefile - 如何解析makefile

转载 作者:行者123 更新时间:2023-12-02 21:37:53 30 4
gpt4 key购买 nike

在制作手册中说:

During the first phase it reads all the makefiles, included makefiles, etc. and internalizes all the variables and their values, implicit and explicit rules, and constructs a dependency graph of all the targets and their prerequisites.

我不明白依赖图是如何构建的?考虑以下 makefile:

%.o: %.z
echo This is overriden implicit rule
default: foo.o

clean:
rm -f fmake test_second
%.o: %.c
echo This is customized implicit rule

make命令之后

echo This is customized implicit rule
This is customized implicit rule

已显示,但我预计

echo This is overriden implicit rule
This is overriden implicit rule

将会,因为在 make 规则中,仅当目标模式和先决条件模式匹配时才会覆盖。在这种情况下,我认为 %.o: %.z 隐式规则已经与模式匹配。

最佳答案

在过去一年左右的时间里,我在一个非常非常大的代码库中使用 Makefile 做了很多工作。我已经厌倦了 make(1s)!

一般来说,答案是“最后的声明获胜”。你也得去争使用默认的 make 后缀规则(在 Solaris 上,这些规则可在/usr/share/lib/make/make.rules 中找到)。

因此,如果您希望覆盖的隐式规则有效,请将其放在最后Makefile 层次结构。如果你想刷新后缀列表,你可以这样做或两者兼而有之

1 添加.SUFFIXES:

写入 Makefile,

2 使用 -r 调用 make

在 MAKEFLAGS (env var) 中或在 make 调用命令行上。

[此外,您可以在命令开头添加“@”以查看输出它,而不是

回显[输出在此处]

以及实际情况

[此处输出]

您还可以通过使用以下调试选项之一来收集见解:make(1s) 允许。在 Solaris 上,即 -d、-dd、-D 或 -DD。对于 GNU Make 来说,它是-d 或 --debug。但请注意,请将命令的输出转储到文件中,因为它的数量很多

您可能想阅读http://freecode.com/articles/what-is-wrong-with-make ,作为一 block 侧面照明。

关于makefile - 如何解析makefile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20990904/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com