如何从Makefile设置MAKEFLAGS,以删除默认的隐式规则 [英] How to set MAKEFLAGS from Makefile, in order to remove default implicit-rules

查看:900
本文介绍了如何从Makefile设置MAKEFLAGS,以删除默认的隐式规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试以下makefile:

MAKEFLAGS += s
MAKEFLAGS += r

configure:

然后,当我运行make时,按照一些默认隐式规则,会出现以下错误,好像它要编译'configure':

/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 0 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 1 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 2 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 3 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 4 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 5 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 6 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 7 has invalid symbol index 13

如果我跑步:

make -r

我没有得到以上错误,相反,我得到了:

make: Nothing to be done for 'configure'.

我想到了从此处定义MAKEFLAGS的想法:

如果您想拥有'MAKEFLAGS'变量,该变量也很有用 某些选项,例如'-k'(* note选项摘要:选项 摘要.),请在每次运行"make"时进行设置.您只需为 您环境中的"MAKEFLAGS".您也可以在 makefile,用于指定也应生效的其他标志 该makefile. (请注意,您不能以这种方式使用'MFLAGS'.那 仅出于兼容性设置变量; "make"不解释 您以任何方式为其设置的值.)

当"make"解释"MAKEFLAGS"的值时(从 环境或来自makefile),如果该值 还不是以一个开始.然后将值切成单词 用空格分隔,并解析这些单词,就好像它们是选项一样 在命令行上给定("-C",-f",-h",-o",-W"和 它们的长名称版本将被忽略;而且没有错误 选项无效).

解决方案

您没有说,但是可能您使用的是旧版本的GNU make.通过在Makefile中的MAKEFLAGS中添加-r来删除内置规则的功能是在2013年10月上旬发布的GNU make 4.0中添加的.

重要的是要记住,当您查看GNU网站上的手册时,正在查看的是最新版本的GNU make的文档.最好阅读发行版随附的文档,因为这将是与您使用的GNU版本相关的手册的正确版本.

ETA:

您必须在MAKEFLAGS中使用实标记.您不能只使用单字母版本.唯一允许使用单字母选项的时间是在变量值的第一个字中(如果标准不需要的话,我也会删除它).您已写过:

MAKEFLAGS += s
MAKEFLAGS += r

给出MAKEFLAGS的值(如果不带其他选项运行make). Make将在第一个单词(而不是其他任何单词)上添加破折号,因此这被解释为-s r,而r不是-r选项.另外,如果碰巧运行了带有选项的make,请说make -k,然后MAKEFLAGS将是k s r,make会将其解释为-k s r,然后也将不会设置-s标志.

简而言之,当您要修改MAKEFLAGS时,只需在短划线前加上 即可:

MAKEFLAGS += -s
MAKEFLAGS += -r

I try the following makefile:

MAKEFLAGS += s
MAKEFLAGS += r

configure:

Then, when I run make, I get the following errors, as if it wants to compile 'configure', per some default implicit-rule:

/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 0 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 1 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 2 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 3 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 4 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 5 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 6 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 7 has invalid symbol index 13

If I run:

make -r

I do not get the above errors, Instead, I get:

make: Nothing to be done for 'configure'.

I got the idea to define MAKEFLAGS from here:

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).

解决方案

You don't say, but probably you're using a too-old version of GNU make. The ability to remove built-in rules by adding -r to MAKEFLAGS inside a makefile was added in GNU make 4.0, released in early October 2013.

It's important to remember that when you look at the manual on the GNU website you're looking at the documentation for the latest version of GNU make. It's better to read the documentation which comes with your distribution, as that will be the correct version of the manual associated with the version of GNU make that you're using.

ETA:

You have to use real flags in MAKEFLAGS. You can't just use the single letter versions. The only time single-letter options are allowed is in the first word of the variable value (I would have removed that too if it weren't required by the standard). You've written:

MAKEFLAGS += s
MAKEFLAGS += r

which gives a value for MAKEFLAGS (if you run make with no other options) of s r. Make will add a dash to the first word, but not any other words, so this is interpreted as -s r and the r is not the -r option. Also, if you happened to run make with an option, say make -k then MAKEFLAGS would be k s r and make would interpret that as -k s r, and then the -s flag would not be set either.

In short, just prepend your options with dashes always when you want to modify MAKEFLAGS:

MAKEFLAGS += -s
MAKEFLAGS += -r

这篇关于如何从Makefile设置MAKEFLAGS,以删除默认的隐式规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆