Referring to the target name from the list of the prerequisites

隐身守侯 提交于 2019-12-08 09:03:44

问题


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 $<

So that, supposing you have:

DATA_test = 1 2 3

When you call it as:

make test

That will expand to:

1.bar 2.bar 3.bar

Is this somehow possible? What would be a better approach to the problem?


回答1:


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 $^


来源:https://stackoverflow.com/questions/9705974/referring-to-the-target-name-from-the-list-of-the-prerequisites

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!