从先决条件列表中引用目标名称 [英] Referring to the target name from the list of the prerequisites
本文介绍了从先决条件列表中引用目标名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Makefile中,我想从先决条件列表中引用目标名称并使用它进行构建.形式如下:
In a Makefile, I would like to refer to the target name from the list of prerequisites and to build something with it. Something of the form:
%.foo: $(addsuffix .bar, $(DATA_%))
@echo $<
假设您有:
DATA_test = 1 2 3
当您将其称为:
make test
它将扩展为:
1.bar 2.bar 3.bar
这有可能吗?什么是解决这个问题的更好方法?
Is this somehow possible? What would be a better approach to the problem?
推荐答案
如果您的Make版本具有二次扩展,这可能会起作用(我无法对其进行测试,因为今天我能用的只是一个旧版本).
If your version of Make has secondary expansion, this will probably work (I can't test it because today all I have handy is an old version).
.SECONDEXPANSION:
%.foo: $$(addsuffix .bar, $$(DATA_$$*))
@echo $^
没有这个,我没有比这更好的方法了:
Without that, I don't see any better way to do it than this:
define FOO_RULE
$(1).foo: $(addsuffix .bar,$(DATA_$(1)))
endef
FOO_TYPES = test real whatever
$(foreach t,$(FOO_TYPES),$(eval $(call FOO_RULE,$(t))))
%.foo:
@echo building $@ from $^
这篇关于从先决条件列表中引用目标名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文