GNU make manual 翻译( 一百四十八)

继续翻译

   A similar variable `MFLAGS' exists also, for historical
compatibility.  It has the same value as `MAKEFLAGS' except that it
does not contain the command line variable definitions, and it always
begins with a hyphen unless it is empty (`MAKEFLAGS' begins with a
hyphen only when it begins with an option that has no single-letter
version, such as `--warn-undefined-variables').  `MFLAGS' was
traditionally used explicitly in the recursive `make' command, like
this:

     subsystem:
             cd subdir && $(MAKE) $(MFLAGS)

but now `MAKEFLAGS' makes this usage redundant.  If you want your
makefiles to be compatible with old `make' programs, use this
technique; it will work fine with more modern `make' versions too.

   The `MAKEFLAGS' variable can also be useful if you want to have
certain options, such as `-k' (*note Summary of Options: Options
Summary.), set each time you run `make'.  You simply put a value for
`MAKEFLAGS' in your environment.  You can also set `MAKEFLAGS' in a
makefile, to specify additional flags that should also be in effect for
that makefile.  (Note that you cannot use `MFLAGS' this way.  That
variable is set only for compatibility; `make' does not interpret a
value you set for it in any way.)

   When `make' interprets the value of `MAKEFLAGS' (either from the
environment or from a makefile), it first prepends a hyphen if the value
does not already begin with one.  Then it chops the value into words
separated by blanks, and parses these words as if they were options
given on the command line (except that `-C', `-f', `-h', `-o', `-W',
and their long-named versions are ignored; and there is no error for an
invalid option).

   If you do put `MAKEFLAGS' in your environment, you should be sure not
to include any options that will drastically affect the actions of
`make' and undermine the purpose of makefiles and of `make' itself.
For instance, the `-t', `-n', and `-q' options, if put in one of these
variables, could have disastrous consequences and would certainly have
at least surprising and probably annoying effects.

 

也有一个类似的变量 MFLAGS,是为了向后兼容性的考虑。它和MAKEFLAGS 一样拥有同样的值,但是它不包含命令行变量定义,并且总是开始于一个连字符除非它是空(MAKEFLAGS 仅当它开始于一个非单字母的时候才开始于一个连字符,例如 --warn-undefined-variables)。MFLAGS在递归make命令中是显式地被传统地使用的,例如像这样:

subsystem:

cd subdir && $(MAKE) $(MFLAGS)

但是现在 MAKEFLAGS 使得这种用法冗余了。如果你想要你的makefile和旧的make兼容,可以使用这个技巧;它也可以和很多现代的make版本一起工作。

如果你想每次在你运行make的时候,用特定的选项,比如 -k(*note Summary of Options: Options Summary),MAKEFLAGS 变量也是有用的。你简单地在环境中给 MAKEFLAGS 设置一个值。

你也可以在一个makefile中设置 MAKEFLAGS ,来指定需要在此makefile中生效的附加标志。(注意你不能用这种方式来用 MFLAGS,那个变量只是为了兼容性;make 不会翻译你一个你给MFLAGS设置的值)

当make翻译了MAKEFLAGS的值,如果这个值之前没有连线符,它首先就插入一个连线符。然后它把这个值用空格分成两半。如果这些值在命令行有选项还解析这些词(-C -f -h -o -W除外,它们的长名字版本被忽略;对一个无效的选项不报错)。

如果你在环境中设置了 MAKEFLAGS,你需要确定不要包含任何严重影响到 make 的动作或者削弱了makefile目的的选项。例如,-t -n 和 -q 选项,如果送入了这样的变量,可能会带来灾难性的后果,至少也是令人惊讶或升起的后果。

后文待续

posted @ 2012-10-02 12:37  健哥的数据花园  阅读(315)  评论(0编辑  收藏  举报