• GNU make manual 翻译( 一百)


    继续翻译

       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.),因为这里面只有一个规则。

    后文待续

  • 相关阅读:
    python中F/f表达式优于format()表达式
    java8新特性-foreach&lambda
    Java实现多线程的四种方式
    Java中的字符串常量池,栈和堆的概念
    java对象只有值传递,为什么?
    面向对象和面向过程程序设计理解及区别
    String对象为什么不可变
    mybatis_plus插件——生成器
    基于grpc的流式方式实现双向通讯(python)
    Django使用DataTables插件总结
  • 原文地址:https://www.cnblogs.com/gaojian/p/2694793.html
Copyright © 2020-2023  润新知