不评估带有百分号的 Makefile 规则
Makefile rule with percent symbol is not evaluated
我正在尝试将 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
文件的内置隐式规则(例如使用解析器生成器),因此永远不会考虑匹配任何规则。
内核 makefile 没有发生错误的原因是它们 运行 make
和 -r
,这消除了内置的隐式规则。它是通过设置 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 内核的 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
文件的内置隐式规则(例如使用解析器生成器),因此永远不会考虑匹配任何规则。
内核 makefile 没有发生错误的原因是它们 运行 make
和 -r
,这消除了内置的隐式规则。它是通过设置 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"。