【问题标题】:Are dynamic Make Dependencies possible?动态 Make Dependencies 可能吗?
【发布时间】:2020-10-13 15:27:36
【问题描述】:

考虑以下示例Makefile

.PHONY: all

all: Coffee_With_Milk Coffee_With_noMilk

%_With_%: Kitchen
    # Parse the parts from $@ and do stuff

如你所见,我用它生成了Coffee_With_MilkCoffee_With_noMilk

当我不仅可以选择[Coffee][Milk, noMilk],还可以选择[Coffee, Tea, Juice, Vodka, Coke][Milk, Sugar, Lemon, Marshmallow, nothing] 时,我必须将所有5x5=25 组合写入all: <combination1> <combination2> <...> 行。

有什么方法可以动态创建吗?

【问题讨论】:

  • 首先,这个目标模式%_With_%是不合法的。一个模式中只能有一个 %。第二个(以及后续)% 不是模式匹配器,它们只是文字 % 字符。
  • 谢谢,我还不知道。 :-)

标签: bash makefile gnu-make


【解决方案1】:

你可以使用foreach函数:

BEVERAGE := Coffee Tea Juice Vodka Coke
ADDIN := Milk Sugar Lemon Marshmallow nothing

COMBOS := $(foreach B,$(BEVERAGE),$(foreach A,$(ADDIN),$(B)_With_$(A)))

不过,正如我在评论中提到的,您将无法使用您提到的模式规则。

【讨论】:

    猜你喜欢
    • 2011-04-07
    • 2019-07-15
    • 2011-04-06
    • 2014-01-18
    • 2023-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-30
    相关资源
    最近更新 更多