gpt4 book ai didi

linux - 不评估带有百分号的 Makefile 规则

转载 作者:IT王子 更新时间:2023-10-29 01:21:42 24 4
gpt4 key购买 nike

我正在尝试将 linux 内核的 kconfig 实用程序移植到我的产品中

编译时出现下一个错误:

make[6]: *** No rule to make target `zconf.tab.c', needed by `zconf.tab.o'.  Stop.

我在 Makefile.lib 中找到了这个文件的下一条规则

$(obj)/%: $(src)/%_shipped
$(call cmd,shipped)

它对我来说看起来不错,它只适用于内核,但不适用于我的产品。

然后我在前一个规则之后添加了另一个规则。

$(obj)/%c: $(src)/%c_shipped
$(call cmd,shipped)

现在它工作得很好。

谁能给我解释一下原来的规则有什么问题?

在我的例子中,obj=.src=.(均 = 点)。当前目录包含适当的 *_shipped 文件。

最佳答案

我的猜测是 $(obj)/%: $(src)/%_shipped 符合 match-anything pattern rule 的条件. (该手册没有提及如何处理目录组件的目标和先决条件,但它是有道理的。)

注意手册中的以下内容:

A non-terminal match-anything rule cannot apply to a file name that indicates a specific type of data. A file name indicates a specific type of data if some non-match-anything implicit rule target matches it.

因为已经有用于创建 .c 文件的内置隐式规则(例如使用解析器生成器),所以永远不会考虑 match-anything 规则。

内核 makefile 没有发生错误的原因是它们使用 -r 运行 make,这消除了内置的隐式规则。这是通过设置 MAKEFLAGS 变量在顶级 makefile 中完成的:

# Do not use make's built-in rules and variables
# (this increases performance and avoids hard-to-debug behaviour);
MAKEFLAGS += -rR

作为一个简单的实验,我创建了一个文件 test.c_foo 和以下 makefile:

MAKEFLAGS += -r

%: %_foo
@echo building

make test.c 没有第一行给出

make: *** No rule to make target 'test.c'. Stop.

第一行,它打印“building”。

关于linux - 不评估带有百分号的 Makefile 规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29349120/

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