【问题标题】:GNU make not building targetGNU make 不构建目标
【发布时间】:2016-09-14 17:18:17
【问题描述】:

我希望有以下规则:

foo_% bar_%:
        @echo "Complex building instructions for $@"

all: foo_xyz bar_xyz

然后运行'make all'并得到:

Complex building instructions for foo_xyz
Complex building instructions for bar_xyz

但是,因为 '%' 两次匹配同一个字符串 (xyz) 它只是第一次“构建”,所以我得到的只是第一行。

当'$@' 第二次不同时,有没有办法让 GNU make 执行两次'echo'?毕竟由于$@不同,构建指令也不同:/

【问题讨论】:

    标签: gnu-make


    【解决方案1】:

    正如您所注意到的,多个模式目标的行为与正常目标不同:Make 将考虑负责创建所有模式的配方。

    解决这个问题的一种方法是使用定义:

    define complex-rule
    $1:
        @echo "Complex building instructions for $$@"
    endef
    
    $(eval $(call complex-rule,foo_%))
    $(eval $(call complex-rule,bar_%))
    
    all: foo_xyz bar_xyz
    

    请注意,由于它将是evaled,我将$@ 转义为$$@,因为我希望它在配方运行时扩展,而不是在我eval 它时扩展。另一方面,我没有转义 $1,因为我希望第一个参数在 call 上展开。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-01
      • 2013-10-05
      • 1970-01-01
      • 2014-07-08
      • 1970-01-01
      相关资源
      最近更新 更多