GNU make manual 翻译( 一百一十五)

继续翻译

4.11 Multiple Rules for One Target
==================================

One file can be the target of several rules.  All the prerequisites
mentioned in all the rules are merged into one list of prerequisites for
the target.  If the target is older than any prerequisite from any rule,
the recipe is executed.

   There can only be one recipe to be executed for a file.  If more than
one rule gives a recipe for the same file, `make' uses the last one
given and prints an error message.  (As a special case, if the file's
name begins with a dot, no error message is printed.  This odd behavior
is only for compatibility with other implementations of `make'... you
should avoid using it).  Occasionally it is useful to have the same
target invoke multiple recipes which are defined in different parts of
your makefile; you can use "double-colon rules" (*note Double-Colon::)
for this.

   An extra rule with just prerequisites can be used to give a few extra
prerequisites to many files at once.  For example, makefiles often have
a variable, such as `objects', containing a list of all the compiler
output files in the system being made.  An easy way to say that all of
them must be recompiled if `config.h' changes is to write the following:

     objects = foo.o bar.o
     foo.o : defs.h
     bar.o : defs.h test.h
     $(objects) : config.h

   This could be inserted or taken out without changing the rules that
really specify how to make the object files, making it a convenient
form to use if you wish to add the additional prerequisite
intermittently.

   Another wrinkle is that the additional prerequisites could be
specified with a variable that you set with a command line argument to
`make' (*note Overriding Variables: Overriding.).  For example,

     extradeps=
     $(objects) : $(extradeps)

means that the command `make extradeps=foo.h' will consider `foo.h' as
a prerequisite of each object file, but plain `make' will not.

   If none of the explicit rules for a target has a recipe, then `make'
searches for an applicable implicit rule to find one *note Using
Implicit Rules: Implicit Rules.).

4.11 一个目的的多个规则
==================================

一个文件可以作为多个规则的目的。所有的规则中所提到的所有的前提条件,被合并到此目的的一个前提条件列表中。如果目的比某个规则中的某个前提条件旧,则其片段被执行。

对一个文件而言,可以只有一个片段来执行。如果有多个规则给出了对同一个文件的片段, make 会使用最后一个片段并且打印出一条出错信息。(特例,如果文件名字以. 开始,没有出错信息出现。这种古怪的行为只是为了和其他make实现的兼容, 你应该避免此种使用方式)。在某些场合下,让同一个目的激活在你的makefile种不同位置定义的多个片段是有益的,你可以使用 双冒号规则(*note Duouble-Colon::)

只有前提条件的增强型规则可以被用来一次性给出很多前提条件文件。例如,makefiel常常有一个变量,比如 objects, 包含了所有编译器输出文件的列表。一个表明如果config.h 发生变化则所有这些文件都需要重新编译的简单方法是这样的:

objects = foo.o bar.o
foo.o : defs.h
bar.o : defs.h test.h
$(objects) : config.h

这一段可以被插入或者拿出而不会影响到世纪定义如何创建目标文件的规则。如果你想要间歇性地追加额外的前提条件,这是一个方便的方式。

另一个窍门是,额外的前提条件可以通过make 的命令行参数来指定(*note Overriding Variables:Overriding.),例如,

extradeps=
$(objects) : $(extradeps)

意味着 指令 make extradeps=foo.h 会把 foo.h 当作每一个目标文件的前提条件,但是仅仅运行 make 则不会。

 如果对一个目的而言,没有一个显式规则包含片段,那么make 就会搜索合适的隐式规则。*note Using Implicit Rules: Implicit Rules.

后文待续

原文地址:https://www.cnblogs.com/gaojian/p/2701890.html