GNU Make:旨在为规则生成先决条件的罐头食谱导致错误 "No rule to make target"
GNU Make: Canned recipe which is meant to generate prerequisites for rule causes error "No rule to make target"
我有这个简单的 Makefile:
define some_canned_recipe
find 'foobar' -print
endef
run-something: $(call some_canned_recipe)
@$(info ** [Make] run-something)
@touch $@
当且仅当子目录 'foobar' 下的一个或多个文件或目录已更改时,我希望 'run-something' 规则为 运行。但是,当我在 WSL2 中调用 'make run-something' 时出现此错误:
make: *** No rule to make target 'find', needed by 'run-something'. Stop.
有没有办法实现我想要的(在动态生成 'run-something' 规则的先决条件方面)?
PS:我知道一个愚蠢的解决方案是:
define some_canned_recipe
$(shell find 'foobar' -print)
endef
尽管这可行,但它并不是一个好主意,因为 $(shell ...) 将 运行 即使规则 'run-something' 未被定位。
您可以使用 secondary expansion 结合隐式规则来做到这一点:
.SECONDEXPANSION:
run-something:
run-%: $$(shell find 'foobar' -print)
@$(info ** [Make] $@)
@touch $@
(注意shell
函数前的$$
)
我不评论我是否认为这是最好的方法:)。
我有这个简单的 Makefile:
define some_canned_recipe
find 'foobar' -print
endef
run-something: $(call some_canned_recipe)
@$(info ** [Make] run-something)
@touch $@
当且仅当子目录 'foobar' 下的一个或多个文件或目录已更改时,我希望 'run-something' 规则为 运行。但是,当我在 WSL2 中调用 'make run-something' 时出现此错误:
make: *** No rule to make target 'find', needed by 'run-something'. Stop.
有没有办法实现我想要的(在动态生成 'run-something' 规则的先决条件方面)?
PS:我知道一个愚蠢的解决方案是:
define some_canned_recipe
$(shell find 'foobar' -print)
endef
尽管这可行,但它并不是一个好主意,因为 $(shell ...) 将 运行 即使规则 'run-something' 未被定位。
您可以使用 secondary expansion 结合隐式规则来做到这一点:
.SECONDEXPANSION:
run-something:
run-%: $$(shell find 'foobar' -print)
@$(info ** [Make] $@)
@touch $@
(注意shell
函数前的$$
)
我不评论我是否认为这是最好的方法:)。