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

简介:

继续翻译

复制代码
   The previous example shows two levels of nesting, but any number of
levels is possible.  For example, here are three levels:

     x = y
     y = z
     z = u
     a := $($($(x)))

Here the innermost `$(x)' expands to `y', so `$($(x))' expands to
`$(y)' which in turn expands to `z'; now we have `$(z)', which becomes
`u'.

   References to recursively-expanded variables within a variable name
are reexpanded in the usual fashion.  For example:

     x = $(y)
     y = z
     z = Hello
     a := $($(x))

defines `a' as `Hello': `$($(x))' becomes `$($(y))' which becomes
`$(z)' which becomes `Hello'.

   Nested variable references can also contain modified references and
function invocations (*note Functions for Transforming Text:
Functions.), just like any other reference.  For example, using the
`subst' function (*note Functions for String Substitution and Analysis:
Text Functions.):

     x = variable1
     variable2 := Hello
     y = $(subst 1,2,$(x))
     z = y
     a := $($($(z)))

eventually defines `a' as `Hello'.  It is doubtful that anyone would
ever want to write a nested reference as convoluted as this one, but it
works: `$($($(z)))' expands to `$($(y))' which becomes `$($(subst
1,2,$(x)))'.  This gets the value `variable1' from `x' and changes it
by substitution to `variable2', so that the entire string becomes
`$(variable2)', a simple variable reference whose value is `Hello'.
复制代码

前面的例子展示了两层的嵌套,但是任何层的嵌套都是可能的。例如,这里有三个层次:

x = y
y = z
z = u
a := $($($(x)))

这里,最里层的 `$(x)' 扩展到  `y',于是 `$($(x))' 扩展到`$(y)',进而扩展到`z'; 现在我们拥有`$(z)',它将变为 `u'。

在一个变量里面,对递归式扩展的变量的参照会合正常的扩展一样。例如:

x = $(y)
y = z
z = Hello
a := $($(x))

定义 `a' 为 `Hello': `$($(x))' 为 `$($(y))' ,然后转化为,`$(z)' ,再转化为 `Hello'。

嵌套的变量参照也能包含变化的参照和函数激活(*note Functiosn for Transforming Text: Functions),就像其他的参照一样。例如,使用 subst函数(*Functions for String Substitution and Analysis: Text Functions.):

x = variable1
variable2 := Hello
y = $(subst 1,2,$(x))
z = y
a := $($($(z)))

最终定义 `a' 为 `Hello'。是否会有人写出这样的嵌套式的参照是令人怀疑的,但是它确实可以工作:

`$($($(z)))' 扩展为 `$($(y))' ,它变成 `$($(subst
1,2,$(x)))'. 然后从x 来获得 `variable1' ,再通过变换,把它变成 `variable2', 这样整个字符串就变成了
`$(variable2)', 成为一个简单的变量参照,其值为 `Hello'。

后文待续





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

目录
相关文章
|
Linux C语言
make: gcc:命令未找到
make: gcc:命令未找到
make: gcc:命令未找到
|
C语言 C++ Perl
如何处理错误消息Please install the gcc make perl packages
如何处理错误消息Please install the gcc make perl packages
146 0
|
1月前
|
编译器 Linux 开发工具
|
1月前
|
NoSQL 编译器 开发工具
006.gcc编译器
gcc是什么?
54 0
006.gcc编译器
|
1月前
|
存储 NoSQL 算法
从一个crash问题展开,探索gcc编译优化细节
问题分析的过程也正是技术成长之路,本文以一个gcc编译优化引发的crash为切入点,逐步展开对编译器优化细节的探索之路,在分析过程中打开了新世界的大门……
491 1