zoukankan      html  css  js  c++  java
  • GNU make manual 翻译( 一百一十四)

    继续翻译

    4.10 Multiple Targets in a Rule
    ===============================
    
    A rule with multiple targets is equivalent to writing many rules, each
    with one target, and all identical aside from that.  The same recipe
    applies to all the targets, but its effect may vary because you can
    substitute the actual target name into the recipe using `$@'.  The rule
    contributes the same prerequisites to all the targets also.
    
       This is useful in two cases.
    
       * You want just prerequisites, no recipe.  For example:
    
              kbd.o command.o files.o: command.h
    
         gives an additional prerequisite to each of the three object files
         mentioned.
    
       * Similar recipes work for all the targets.  The recipes do not need
         to be absolutely identical, since the automatic variable `$@' can
         be used to substitute the particular target to be remade into the
         commands (*note Automatic Variables::).  For example:
    
              bigoutput littleoutput : text.g
                      generate text.g -$(subst output,,$@) > $@
         
         is equivalent to
    
              bigoutput : text.g
                      generate text.g -big > bigoutput
              littleoutput : text.g
                      generate text.g -little > littleoutput
    
         Here we assume the hypothetical program `generate' makes two types
         of output, one if given `-big' and one if given `-little'.  *Note
         Functions for String Substitution and Analysis: Text Functions,
         for an explanation of the `subst' function.
    
       Suppose you would like to vary the prerequisites according to the
    target, much as the variable `$@' allows you to vary the recipe.  You
    cannot do this with multiple targets in an ordinary rule, but you can
    do it with a "static pattern rule".  *Note Static Pattern Rules: Static
    Pattern.

    4.10 一个规则中的多个目的
    ===============================

    和写多个规则,每个规则一个目的的做法比较起来,带有多个目的规则更加便利。同样的片段作用于所有的目的,但是其作用范围可能会变化,因为你可以在片段中通过 $@来替换世纪的目的名。规则也会把同样的前提条件作用于所有的目的。

    这在两种情况下有用。

    *你只需要 前提条件,不需要片段。例如:

    kdo.o command.o files.o: command.h

    对这三个目标文件,给出了一个额外的前提条件。

    *为所有目的工作的同样的片段。片段不需要绝对唯一,因为自动变量 $@能够替换特定的目的,来重新建立指令(*note Automatic Variables::),例如:

    bigoutput littleoutput : text.g
      generate text.g -$(subst output,,$@) > $@

    等价于:

    bigoutput : text.g
      generate text.g -big > bigoutput

    littleoutput : text.g
      generate text.g -little > littleoutput

    在此书,我们假定假想的程序 generate 生成两个类型的输出,一个是给出 big 选项的时候,一个是给出little选项的时候。可以参照 *Note Functions for String Substitution and Analysis: Text Functions 中对 subst 函数的解释。

    设想一下你将为目的而变换前提条件。正如你用 $@的变量来对片段进行变化那样;你在一个普通的带有多个目的的规则里是不能达成的,但是你可以用 静态模式规则来做到这一点。*Note Static Pattern Rules: Static Pattern。

    后文待续

  • 相关阅读:
    Web自动化测试之滑动验证码的解决方案
    设计模式之单例
    设计模式之原型
    设计模式之建造者
    DG环境RMAN删除归档报错RMAN-08137: archived log not deleted【转载】
    RFS[3]: No standby redo logfiles available for thread 1
    spring-boot之webflux简单入门
    spring-boot-security组件总结补充
    spring-boot启用security组件 · 下
    spring-boot启用security组件 · 中
  • 原文地址:https://www.cnblogs.com/gaojian/p/2701758.html
Copyright © 2011-2022 走看看