GNU make manual 翻译( 一百三十一)
继续翻译
5.1.2 Using Variables in Recipes -------------------------------- The other way in which `make' processes recipes is by expanding any variable references in them (*note Basics of Variable References: Reference.). This occurs after make has finished reading all the makefiles and the target is determined to be out of date; so, the recipes for targets which are not rebuilt are never expanded. Variable and function references in recipes have identical syntax and semantics to references elsewhere in the makefile. They also have the same quoting rules: if you want a dollar sign to appear in your recipe, you must double it (`$$'). For shells like the default shell, that use dollar signs to introduce variables, it's important to keep clear in your mind whether the variable you want to reference is a `make' variable (use a single dollar sign) or a shell variable (use two dollar signs). For example: LIST = one two three all: for i in $(LIST); do \ echo $$i; \ done results in the following command being passed to the shell: for i in one two three; do \ echo $i; \ done which generates the expected result: one two three
5.1.2 在片段中使用变量
--------------------------------
make 处理片段的另一个方式是通过扩展任何的片段中的变量参照(*note Basics of Variable References: Reference.) 。这发生在当make 读取完毕所有的makefile并且目的被认为是过期的时候;因此,未被重新构建的目的的片段不会被展开。
makefile中的片段的变量和函数参照有着相同的语法和语义。它们也有同样的引用规则。如果你想要你的片段中出现一个美元符号,你必须使用$$。
对于缺省shell那样的shell, 使用美元符号来引入变量,保持头脑清醒地了解你所要使用的变量是否是 make 的变量(使用一个美元符)还是说是shell 的变量(使用两个美元符),是很重要的。例如:
LIST = one two three
all:
for i in $(LIST); do \
echo $$i; \
done
形成如下传递给shell的命令:
for i in one two three; do \
echo $i; \
done
得到如下的结果:
one
two
three
后文待续