我有一个情况,我需要一个小程序通过检查文件来确定文件的先决条件。具体:
%.bar: $(shell python get_preqs.py %.foo) # % in shell is not substituted
python gen_bar.py $^ $@
但是,这不起作用,因为 shell 命令中的%
不会被 make 替换。有什么办法可以做到这一点吗?
您可以使用 .GNU的二次扩展特性:
.SECONDEXPANSION:
%.bar: $$(shell python get_prereqs.py $$*.foo)
python gen_bar.py $^ $@
另一种选择是使用更适合动态目标的构建工具。 例如,我编写了一个类似 Gnu Make 的工具,其中包含了 DJB ReDo 中的一些概念,称为 GoodMake。 等效的生成文件将是:
#? *.bar
preqs=$(python get_preqs.py ${1%.bar}.foo)
$0 $preqs
python gen_bar.py $preqs $1