动态 Make Dependencies 是否可行?
Are dynamic Make Dependencies possible?
考虑以下示例 Makefile
:
.PHONY: all
all: Coffee_With_Milk Coffee_With_noMilk
%_With_%: Kitchen
# Parse the parts from $@ and do stuff
如您所见,我用它生成 Coffee_With_Milk
和 Coffee_With_noMilk
。
当我不仅可以选择 [Coffee]
和 [Milk, noMilk]
,而且可以选择 [Coffee, Tea, Juice, Vodka, Coke]
和 [Milk, Sugar, Lemon, Marshmallow, nothing]
时,我必须将所有 5x5=25 组合写入 all: <combination1> <combination2> <...>
行。
有什么方法可以动态创建吗?
您可以使用foreach
函数:
BEVERAGE := Coffee Tea Juice Vodka Coke
ADDIN := Milk Sugar Lemon Marshmallow nothing
COMBOS := $(foreach B,$(BEVERAGE),$(foreach A,$(ADDIN),$(B)_With_$(A)))
不过,正如我在评论中提到的,您将无法使用您提到的那种模式规则。
考虑以下示例 Makefile
:
.PHONY: all
all: Coffee_With_Milk Coffee_With_noMilk
%_With_%: Kitchen
# Parse the parts from $@ and do stuff
如您所见,我用它生成 Coffee_With_Milk
和 Coffee_With_noMilk
。
当我不仅可以选择 [Coffee]
和 [Milk, noMilk]
,而且可以选择 [Coffee, Tea, Juice, Vodka, Coke]
和 [Milk, Sugar, Lemon, Marshmallow, nothing]
时,我必须将所有 5x5=25 组合写入 all: <combination1> <combination2> <...>
行。
有什么方法可以动态创建吗?
您可以使用foreach
函数:
BEVERAGE := Coffee Tea Juice Vodka Coke
ADDIN := Milk Sugar Lemon Marshmallow nothing
COMBOS := $(foreach B,$(BEVERAGE),$(foreach A,$(ADDIN),$(B)_With_$(A)))
不过,正如我在评论中提到的,您将无法使用您提到的那种模式规则。