GNU make manual 翻译( 一百六十)

简介:

继续翻译

复制代码
 
 

The only restriction on this sort of use of nested variable
references is that they cannot specify part of the name of a function
to be called. This is because the test for a recognized function name
is done before the expansion of nested references. For example,

 
 

ifdef do_sort
func := sort
else
func := strip
endif

 
 

bar := a d b g q c

 
 

foo := $($(func) $(bar))

 
 

attempts to give `foo' the value of the variable `sort a d b g q c' or
`strip a d b g q c', rather than giving `a d b g q c' as the argument
to either the `sort' or the `strip' function. This restriction could
be removed in the future if that change is shown to be a good idea.

 
 

You can also use computed variable names in the left-hand side of a
variable assignment, or in a `define' directive, as in:

 
 

dir = foo
$(dir)_sources := $(wildcard $(dir)/*.c)
define $(dir)_print =
lpr $($(dir)_sources)
endef

 
 

This example defines the variables `dir', `foo_sources', and
`foo_print'.

 
 

Note that "nested variable references" are quite different from
recursively expanded variables (*note The Two Flavors of Variables:
Flavors.), though both are used together in complex ways when doing
makefile programming.

 
复制代码

对于这种对嵌套式变量参照使用的唯一的限制是他们不能指定一个要调用的函数名称的部分。这是因为对一个被认识的函数名称的测试已经在嵌套参照之前完成了。例如,

ifdef do_sort

  func := sort
else
func := strip
endif

bar := a d b g q c

foo := $($(func) $(bar))

试图给出 `foo' 变量值为 `sort a d b g q c' 或 `strip a d b g q c', 而不是给出`a d b g q c' 作为 `sort' 或者 `strip' 函数的参数。如果未来考虑到改变此限制会更好,也许未来会进行改变。

你可以在一个变量赋值或define指令的左边得左边使用被计算的变量名,就像是这样:

dir = foo

$(dir)_sources := $(wildcard $(dir)/*.c)
define $(dir)_print =
lpr $($(dir)_sources)
endef

这个例子定义了变量 `dir', `foo_sources', 和`foo_print'。

要注意这个 "嵌套变量参照" 是和 递归式扩展变量很不一样的。(*note The Two Flavors of Variables: Flavors.) 尽管它们都在 makefile 编程时以复杂的方式进行使用。 

这里我插入一句,

dir = foo

$(dir)_sources := $(wildcard $(dir)/*.c)

相当于 把  foo目录下的 所有的.c 文件名 获得后,赋值为 foo_sources

后文待续





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

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