GNU make manual 翻译( 一百七十二)

简介:

继续翻译

复制代码
6.12 Pattern-specific Variable Values
=====================================

In addition to target-specific variable values (*note Target-specific
Variable Values: Target-specific.), GNU `make' supports
pattern-specific variable values.  In this form, the variable is
defined for any target that matches the pattern specified.

   Set a pattern-specific variable value like this:

     PATTERN ... : VARIABLE-ASSIGNMENT
   where PATTERN is a %-pattern.  As with target-specific variable
values, multiple PATTERN values create a pattern-specific variable
value for each pattern individually.  The VARIABLE-ASSIGNMENT can be
any valid form of assignment.  Any command line variable setting will
take precedence, unless `override' is specified.

   For example:

     %.o : CFLAGS = -O

will assign `CFLAGS' the value of `-O' for all targets matching the
pattern `%.o'.

   If a target matches more than one pattern, the matching
pattern-specific variables with longer stems are interpreted first.
This results in more specific variables taking precedence over the more
generic ones, for example:

     %.o: %.c
             $(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@

     lib/%.o: CFLAGS := -fPIC -g
     %.o: CFLAGS := -g

     all: foo.o lib/bar.o

   In this example the first definition of the `CFLAGS' variable will
be used to update `lib/bar.o' even though the second one also applies
to this target. Pattern-specific variables which result in the same
stem length are considered in the order in which they were defined in
the makefile.

   Pattern-specific variables are searched after any target-specific
variables defined explicitly for that target, and before target-specific
variables defined for the parent target.
复制代码

6.12 模式特定的变量值
=====================================

除了目的特定的变量值(*note Target-specific Variable Values: Target-specific.),GNU make 还支持模式特定的变量值。此时,变量会为所有匹配的目的定义变量。

设置模式特定的变量看起来像这个样子:

PATTERN ... : VARIABLE-ASSIGNMENT

PATTERN 是一个 %-模式。多模式的值为每一个模式特定的变量单独赋予一个值。VARIABLE-ASSIGNMENT 可以是任何有效的赋值表达式。命令行变量优先级高于这些变量,除非使用了 override。

例如:

%.o : CFLAGS = -O

对任何匹配%.o的目的,将会给 `CFLAGS' 赋值为`-O' 。

如果一个目的匹配了多于一个的模式,拥有更长的枝干的模式特定的变量会首先被翻译。这导致更加特定的变量比更加通用的变量优先级高,例如:

%.o: %.c
$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@

lib/%.o: CFLAGS := -fPIC -g
%.o: CFLAGS := -g

all: foo.o lib/bar.o

在这个例子中,对 CFLAGS 的第一个定义,将要被运用来更改 lib/bar.o,尽管第二次的定义也满足此目的。拥有同样长度的枝干的模式特定的变量,则按照出现的顺序来确定优先级。

模式特定的变量是在显式定义的目的特定的变量之后,在父目的的目的特定的变量之前被搜索的。

后文待续





本文转自健哥的数据花园博客园博客,原文链接:http://www.cnblogs.com/gaojian/archive/2012/10/05/2712106.html,如需转载请自行联系原作者


目录
相关文章
|
Linux C语言
make: gcc:命令未找到
make: gcc:命令未找到
make: gcc:命令未找到