继续翻译
Thus, you first write the line that states that `clean' is a phony target, then you write the rule, like this: .PHONY: clean clean: rm *.o temp Another example of the usefulness of phony targets is in conjunction with recursive invocations of `make' (for more information, see *note Recursive Use of `make': Recursion.). In this case the makefile will often contain a variable which lists a number of subdirectories to be built. One way to handle this is with one rule whose recipe is a shell loop over the subdirectories, like this: SUBDIRS = foo bar baz subdirs: for dir in $(SUBDIRS); do \ $(MAKE) -C $$dir; \ done There are problems with this method, however. First, any error detected in a submake is ignored by this rule, so it will continue to build the rest of the directories even when one fails. This can be overcome by adding shell commands to note the error and exit, but then it will do so even if `make' is invoked with the `-k' option, which is unfortunate. Second, and perhaps more importantly, you cannot take advantage of `make''s ability to build targets in parallel (*note Parallel Execution: Parallel.), since there is only one rule.
Thus, you first write the line that states that `clean' is a phony
target, then you write the rule, like this:
因此,你先写了生命 clean 是伪目的的行,然后再写规则,像这样:
.PHONY: clean
clean:
rm *.o temp
另一个说明伪目的用途的例子是和 对make 的递归调用合并在一起的。(为了得到更多相关情报,请参阅 *note Recursive Use of 'make': Recursion) 在这个例子里,makefile 经常会包含一个变量值,列出若干个子目录。一种办法是定义一个规则,在其片段里用一个 shell 循环对这些子目录进行处理,像这样:
SUBDIRS = foo bar baz
subdirs:
for dir in $(SUBDIRS); do \
$(MAKE) -C $$dir; \
done
Second, and perhaps more importantly, you cannot take
advantage of `make''s ability to build targets in parallel (*note
Parallel Execution: Parallel.), since there is only one rule.
但是 用这个方法会有问题。首先,在子make中任何错误都会被忽略,所以它将继续执行剩余的指令。这个可以通过shell 命令注意到错误并退出来克服,但是如果make 使用了 -k 选项,很不幸仍然会有退出的问题。第二,也许更为重要的是,你无法利用 make 的并发编译的能力(*note Parallel Execution :Parallel.),因为这里面只有一个规则。
后文待续