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

继续翻译

5.1 Recipe Syntax
================= Makefiles have the unusual property that there are really two distinct syntaxes in one file. Most of the makefile uses `make' syntax (*note Writing Makefiles: Makefiles.). However, recipes are meant to be interpreted by the shell and so they are written using shell syntax. The `make' program does not try to understand shell syntax: it performs only a very few specific translations on the content of the recipe before handing it to the shell. Each line in the recipe must start with a tab (or the first character in the value of the `.RECIPEPREFIX' variable; *note Special Variables::), except that the first recipe line may be attached to the target-and-prerequisites line with a semicolon in between. _Any_ line in the makefile that begins with a tab and appears in a "rule context" (that is, after a rule has been started until another rule or variable definition) will be considered part of a recipe for that rule. Blank lines and lines of just comments may appear among the recipe lines; they are ignored. Some consequences of these rules include: * A blank line that begins with a tab is not blank: it's an empty recipe (*note Empty Recipes::). * A comment in a recipe is not a `make' comment; it will be passed to the shell as-is. Whether the shell treats it as a comment or not depends on your shell. * A variable definition in a "rule context" which is indented by a tab as the first character on the line, will be considered part of a recipe, not a `make' variable definition, and passed to the shell. * A conditional expression (`ifdef', `ifeq', etc. *note Syntax of Conditionals: Conditional Syntax.) in a "rule context" which is indented by a tab as the first character on the line, will be considered part of a recipe and be passed to the shell.

5.1 片段语法
=================

makefile 有着罕有的属性,在一个文件中期时有两种独立的语法。多数的makefile 使用 make 语法(*note Writing Makefiles: Makefiles.) 但是,片段要被shell 所翻译,所以它们使用shell 的语法写成。make 程序并不试图去理解 shell 的语法:在把片段传递给shell 之前,它仅仅对几个特定内容进行翻译。

片段中的每一行都需要开始于一个 tab 键(或者第一个字符是 .RECIPEPREFIX 变量的值; *note Special Variables::),除了第一行的片断行可以用一个分号连接在 目的-前提条件行之后。makefile中的任何开始于tab键的一行,并且出现在"规则上下文"(就是直到另一个规则或者变量定义出现之前)中的,将会被认为是那个规则的片段的一部分。空行和注释行可以出现在片段中,它们被忽略。

某些规则的推论如下:

*以tab 开始的空行不是真的空行:它是一个空片段(*note Empty Recipes::)

*片段中的注释不是 make 的注释;它会原样传递到shell中。shell 是否把它按照注释对待取决于你的shell。

*在一个 "规则上下文"中的 变量定义,如果是以tab键开头,将被认为是片段的部分,不会被认为是变量定义,会被传递到shell。

*一个条件性的表达式(ifdef, ifeq 等等 *note Syntax of Conditionals: Conditional Syntax) 在一个"规则上下文"中,如果有tab健开头,将会被认为是片段的一部分,将要被传递到shell。

后文待续

posted @ 2012-09-27 12:35  健哥的数据花园  阅读(199)  评论(0编辑  收藏  举报