Makefile在foreach循环中使用ifeq条件

时间:2011-12-14 10:36:35

标签: linux makefile

我有很多变量叫做 allow_xxx其中xxx是一个特征。

我想在makefile中创建一个包含所有允许值的变量。

这是我尝试做的事情:

allow_feat1 := 1
allow_feat2 := 1
allow_feat3 := 1
list_features := feat1 feat2 feat3

allowed := $(foreach V, $(list_features), $(ifeq ($(allow_$V),1),$V))

这不起作用...... 知道如何正确地做到这一点?

谢谢!

2 个答案:

答案 0 :(得分:8)

没有ifeq函数这样的东西,它只是一个条件指令。请改用iffilter

allowed := $(foreach V, $(list_features), $(if $(filter 1,$(allow_$V)),$V))

答案 1 :(得分:0)

如果您想减少或创建迭代次数的范围,您可以这样做

MAX_RANGE := 4
vector_0_10 := 0 1 2 3 4 5 6 7 8 9 10 
vector_reduced := $(wordlist 1,$(MAX_RANGE),$(vector_0_10))
$(info $$vector_reduced is printed as [$(vector_reduced)])
//will print 0 1 2 3
FLAGS += $(foreach V, $(vector_reduced), -sdf min:$(ANOTHERVAR).test.text[$(V)].more_text:$(var2)/moretext )
$(info $$FLAGS is printed as [$(FLAGS )])`  
相关问题