[英]Makefile match wildcard prerequisites for a rule
我想将一些配方传递给makefile,例如comp1.mt comp2.mt comp3.mt
并让makefile将它们汇总到一个MT列表中(也可以是mt.compN
)以批量运行它们。
%.mt:
@echo $* >> list_of_mts.txt
mt: %.mt
@cat list_of_mts.txt
我想以任何顺序将这些配方传递给makefile,因此调用make comp1.mt comp2.mt mt
的特定情况是不可取的。
我不明白为什么需要在makefile中实现此功能,但是您在这里:
MT_TARGETS:=$(filter %.mt,$(MAKECMDGOALS))
.PHONY: $(MT_TARGETS)
$(MT_TARGETS):
@echo $@ | sed -e "s:.mt$$::" >> list_of_mts.txt
mt: $(MT_TARGETS)
@cat list_of_mts.txt
测试:
$ make mt comp1.mt comp2.mt comp3.mt
comp1
comp2
comp3
make: `comp1.mt' is up to date.
make: `comp2.mt' is up to date.
make: `comp3.mt' is up to date.
这是使用特殊变量MAKECMDGOALS
。
注意:list_of_mts.txt将不断增长...
注意2:在并行执行中写入list_of_mts.txt是不安全的(list_of_mts.txt文件可能会损坏)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.