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

继续翻译

6 How to Use Variables
**********************

A "variable" is a name defined in a makefile to represent a string of
text, called the variable's "value".  These values are substituted by
explicit request into targets, prerequisites, recipes, and other parts
of the makefile.  (In some other versions of `make', variables are
called "macros".)  

   Variables and functions in all parts of a makefile are expanded when
read, except for in recipes, the right-hand sides of variable
definitions using `=', and the bodies of variable definitions using the
`define' directive.

   Variables can represent lists of file names, options to pass to
compilers, programs to run, directories to look in for source files,
directories to write output in, or anything else you can imagine.

   A variable name may be any sequence of characters not containing `:',
`#', `=', or leading or trailing whitespace.  However, variable names
containing characters other than letters, numbers, and underscores
should be avoided, as they may be given special meanings in the future,
and with some shells they cannot be passed through the environment to a
sub-`make' (*note Communicating Variables to a Sub-`make':
Variables/Recursion.).

   Variable names are case-sensitive.  The names `foo', `FOO', and
`Foo' all refer to different variables.

   It is traditional to use upper case letters in variable names, but we
recommend using lower case letters for variable names that serve
internal purposes in the makefile, and reserving upper case for
parameters that control implicit rules or for parameters that the user
should override with command options (*note Overriding Variables:
Overriding.).

   A few variables have names that are a single punctuation character or
just a few characters.  These are the "automatic variables", and they
have particular specialized uses.  *Note Automatic Variables::.

6 如何使用变量
**********************

变量是一个在makefile中定义的名字,来代表一个文本串,这个文本串称为此变量的值。这些值回被显式的请求替换后传递给目的,前提条件,片段或者makefile的其它部分(在某些版本的make中,变量被称为宏)。

 在makefile的各个部分中的变量和函数,当被读取的时候会进行扩展,除了在片段中的时候。扩展的内容是变量定义的=右边,变量定义的内容需要借助于 define 指令。

变量可以代表文件名的列表,传递给编译器的选项,需要运行的程序,寻找源文件的目录,写入的目录或者任何你能想到的东西。

一个变量名字可以包含任何字符,除了:# = 和 头部和尾部的空格。但是变量名中字母数字和下划线之外的符号应当尽量避免,因为他们在将俩也许会被赋予特殊的含义,某些shell 无法把它们传递到子make中(*note Communicating Vairables to a Sub-'make': Variables/Rercursion)

变量名是大小写敏感的,foo, FOO 和 Foo 代表着不同的变量。

在变量名中使用大写字符是传统的方式,但是我们建议为了makefile内部使用的变量名用小写字符,把大写字符变量名用作控制隐式规则或者用户不应该覆盖的命令选项(*note Overriding Variables: Overriding.)

有几个变量名是一个单独的标点符号或者几个字符。这些被称为自动变量,他们有着特殊的用法。*Note Automatic Variables::

后文待续

原文地址:https://www.cnblogs.com/gaojian/p/2710352.html