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
162 0
|
6月前
|
编译器 Linux 开发工具
|
3月前
|
前端开发 C语言
gcc动态库升级
gcc动态库升级
|
23天前
|
编译器 Linux C语言
gcc的编译过程
GCC(GNU Compiler Collection)的编译过程主要包括四个阶段:预处理、编译、汇编和链接。预处理展开宏定义,编译将代码转换为汇编语言,汇编生成目标文件,链接将目标文件与库文件合并成可执行文件。
51 11