代码之家  ›  专栏  ›  技术社区  ›  m1tk4

没有配方的makefile模式规则

  •  9
  • m1tk4  · 技术社区  · 14 年前

    我正在观察make的一个有趣的行为,我想知道除了gmake中的一个bug之外,是否还有一个合理的解释。

    假设makefile中有以下内容:

    %-animal:
            echo "$* is an animal"
    
    %-fox: %-fox-animal
    
    %-wolf: %-wolf-animal
    

    最后两个目标之间的区别是“%-wolf”没有任何配方,“%-fox”有一个空配方(即只有一行开头有一个标签)。

    [root@cv19 tmp]# make freddy-animal
    echo "freddy is an animal"
    freddy is an animal
    [root@cv19 tmp]# make freddy-wolf
    make: *** No rule to make target `freddy-wolf'.  Stop.
    [root@cv19 tmp]# make freddy-fox
    echo "freddy-fox is an animal"
    freddy-fox is an animal
    

    1 回复  |  直到 6 年前
        1
  •  14
  •   John Marshall    14 年前

    完全没有配方的模式规则被记录为与提供配方(甚至是空配方)的规则有很大不同的含义。相反,他们 cancel any pre-existing implicit rule :

    因此,您的“%-wolf”模式实际上用于取消 %-狼 -&燃气轮机; . 反正也没有。