继续翻译
5.7.3 Communicating Options to a Sub-`make' ------------------------------------------- Flags such as `-s' and `-k' are passed automatically to the sub-`make' through the variable `MAKEFLAGS'. This variable is set up automatically by `make' to contain the flag letters that `make' received. Thus, if you do `make -ks' then `MAKEFLAGS' gets the value `ks'. As a consequence, every sub-`make' gets a value for `MAKEFLAGS' in its environment. In response, it takes the flags from that value and processes them as if they had been given as arguments. *Note Summary of Options: Options Summary. Likewise variables defined on the command line are passed to the sub-`make' through `MAKEFLAGS'. Words in the value of `MAKEFLAGS' that contain `=', `make' treats as variable definitions just as if they appeared on the command line. *Note Overriding Variables: Overriding. The options `-C', `-f', `-o', and `-W' are not put into `MAKEFLAGS'; these options are not passed down. The `-j' option is a special case (*note Parallel Execution: Parallel.). If you set it to some numeric value `N' and your operating system supports it (most any UNIX system will; others typically won't), the parent `make' and all the sub-`make's will communicate to ensure that there are only `N' jobs running at the same time between them all. Note that any job that is marked recursive (*note Instead of Executing Recipes: Instead of Execution.) doesn't count against the total jobs (otherwise we could get `N' sub-`make's running and have no slots left over for any real work!) If your operating system doesn't support the above communication, then `-j 1' is always put into `MAKEFLAGS' instead of the value you specified. This is because if the `-j' option were passed down to sub-`make's, you would get many more jobs running in parallel than you asked for. If you give `-j' with no numeric argument, meaning to run as many jobs as possible in parallel, this is passed down, since multiple infinities are no more than one.
5.7.3 向子make通信的选项
-------------------------------------------
诸如 -s 或者 -k 这样的标志会通过变量 MAKEFLAGS自动地传递到子make中。这个变量是由make自动设置的,用来包含make所接受到的标志。因此如果你使用的 make -ks ,那么MKAKEFLAGS中就包含了值ks。
作为一个序列,每一个子make在其环境中获得一个MAKEFLAGS的值。作为回应,它拿到这些标志,然后处理它们,就好像它们作为参数一般。*Note Summary of Options: Options Summary
类似的,在命令行中的定义的变量会通过 MAKEFLAGS 传递到子make中。对于在MAKEFLAGS中包含 = 的单词,make 把它当作变量定义对待,就如同从命令行中出现一样。 *Note Overriding Varaables:Overriding
选项 -C ,-f ,-o 和 -W 不会放到 MAKEFLAGS里,这些选项不会向下传递。
-j选项是一个特殊的情况(*note Parallel Execution: Parallel.) 如果你把它设置为某些数值N并且你的操作系统支持这么做(很多UNIX系统支持,但是其他系统不会),父make和所有的子make将会通信以确保只有N个任务在所有make之间同时运行。
请注意任何被标记为 递归(*note Instead of Executing Recipes: Instead of Execution.)的任务不会记入到总的任务数(否则我们没有办法获得'N'个 子make 运行并且会没有槽留给剩下的真正的工作)中。
如果你的操作系统不支持这种通信,那么 -j1 而不是你指定的值将会总是传递给 MAKEFLAGS里。这是因为 如果-j 选项向下传递到 子make里, 你会获得比你请求的还要夺得任务并行执行。如果你给出没有参数的 -j,意味着尽可能地并行运行任务,这会被传递下去,因为多个无穷大也未必大过一个无穷大。
后文待续
本文转自健哥的数据花园博客园博客,原文链接:http://www.cnblogs.com/gaojian/archive/2012/10/02/2710097.html,如需转载请自行联系原作者