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

继续翻译

5.9 Using Empty Recipes

=======================



It is sometimes useful to define recipes which do nothing.  This is done

simply by giving a recipe that consists of nothing but whitespace.  For

example:



     target: ;



defines an empty recipe for `target'.  You could also use a line

beginning with a recipe prefix character to define an empty recipe, but

this would be confusing because such a line looks empty.



   You may be wondering why you would want to define a recipe that does

nothing.  The only reason this is useful is to prevent a target from

getting implicit recipes (from implicit rules or the `.DEFAULT' special

target; *note Implicit Rules:: and *note Defining Last-Resort Default

Rules: Last Resort.).



   You may be inclined to define empty recipes for targets that are not

actual files, but only exist so that their prerequisites can be remade.

However, this is not the best way to do that, because the prerequisites

may not be remade properly if the target file actually does exist.

*Note Phony Targets: Phony Targets, for a better way to do this.

5.9 使用空片段
=======================

有时候定义什么也不做的片段也是有用的。这是由给出一个只有空格的片段来实现。例如:

target: ;

定义了了对'target' 的空片段。你可以用一个开头有片段前缀符的行来开始一个空片段,但是这样会造成困扰因为这个行看起来像空的。

你也许会奇怪,为何你需要定义一个什么也不做的片段。唯一的原因是可以防止一个目的获得隐式的片段(从隐式规则或者从 .DEFAULT 特殊目的中获得;*note Implicit Rules:: 和 *note Defining Last-Resort Default Rules: Last Resort)

为不是实际文件的目的而定义空片段也许比较怪异,但是仅仅是当它们的前提条件可以被重新建立时才应该这么做。但是这不是最佳的方式,因为,如果目的文件真实存在,前提脚尖可能不会被正确的重建。更好地办法,应当参考:*Note Phony Targets: Phony Targets。

后文待续

你可能感兴趣的:(Make)