继续翻译
5.1.1 Splitting Recipe Lines ---------------------------- One of the few ways in which `make' does interpret recipes is checking for a backslash just before the newline. As in normal makefile syntax, a single logical recipe line can be split into multiple physical lines in the makefile by placing a backslash before each newline. A sequence of lines like this is considered a single recipe line, and one instance of the shell will be invoked to run it. However, in contrast to how they are treated in other places in a makefile, backslash-newline pairs are _not_ removed from the recipe. Both the backslash and the newline characters are preserved and passed to the shell. How the backslash-newline is interpreted depends on your shell. If the first character of the next line after the backslash-newline is the recipe prefix character (a tab by default; *note Special Variables::), then that character (and only that character) is removed. Whitespace is never added to the recipe. For example, the recipe for the all target in this makefile: all : @echo no\ space @echo no\ space @echo one \ space @echo one\ space consists of four separate shell commands where the output is: nospace nospace one space one space As a more complex example, this makefile: all : ; @echo 'hello \ world' ; echo "hello \ world" will invoke one shell with a command of: echo 'hello \ world' ; echo "hello \ world" which, according to shell quoting rules, will yield the following output: hello \ world hello world Notice how the backslash/newline pair was removed inside the string quoted with double quotes (`"..."'), but not from the string quoted with single quotes (`'...''). This is the way the default shell (`/bin/sh') handles backslash/newline pairs. If you specify a different shell in your makefiles it may treat them differently.
5.1.1 分割片段行
----------------------------
make 确实检查片段的少数几种方法之一是 检查新行之前的反斜线,在正常的makefile语法中,一个单独的逻辑片段行可以通过反斜线,被分割成多个物理行。像这样的一系列的行被认为是一个单独的行,并且一个shell的实例会被激活来运行它。
但是,与之相对的,在它们如何被对待的问题上,反斜线-新行 对不会被从片段中移出。反斜线和新行符号都是被保留并且传递给shell。shell 如何解析反斜线要依赖于你的shell。如果下一行的反斜线后的第一个符号是片断的前缀符号(缺省是 tab符号,*note Special Variables::),那么此符号会被移出,空格键永远也不会加到片段里。
例如,下面这个makefile的 片段:
all :
@echo no\
space
@echo no\
space
@echo one \
space
@echo one\
space
生成如下的四个输出:
nospace
nospace
one space
one space
这里我插入下:
第一个是 no 直接跟反斜线,下一行无空格,也无tab符号,直接space,输出 nospace
第二个是 no 直接跟反斜线,下一行,有tab符号,然后跟space,输出 nospace
第三个是 one 后有一个空格,然后是跟反斜线,下一行,有tab符号,然后跟space,输出 one space
第四个是 one 后跟反斜线,下一行,有tab符号,然后跟一个空格,然后跟space,输出 one space
下面的makefile的更复杂的例子:
all : ; @echo 'hello \
world' ; echo "hello \
world"
会激活一个shell,执行下列指令:
echo 'hello \
world' ; echo "hello \
world"
根据shell对 反斜线的解释,会形成下列输出:
hello \
world
hello world
请注意反斜线和新行对视如何在双引号内被移出德。但是在单引号中,却没有移出来,缺省shell /bin/sh的处理方式就是这样,如果你指定了别的shell, 可能处理方式会不一样。
后文待续