如何从Makefile设置MAKEFLAGS,以删除默认的隐式规则

时间:2015-08-03 07:30:23

标签: makefile

我尝试以下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'.

我有了从here定义MAKEFLAGS的想法:

  

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

     

当'make'解释'MAKEFLAGS'的值时(来自。)   环境或从makefile),它首先添加一个连字符,如果值   还没有开始。然后它将值切换为单词   由空格分隔,并解析这些单词,就好像它们是选项一样   在命令行中给出(除了'-C',' - f',' - h',' - o',' - W'和   他们的长命名版本被忽略了;而且没有错误   无效选项)。

1 个答案:

答案 0 :(得分:1)

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

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

ETA:

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

MAKEFLAGS

MAKEFLAGS += s MAKEFLAGS += r 提供了MAKEFLAGS(如果您运行make而没有其他选项)的值s r。 Make会在第一个单词中添加短划线,但不会添加任何其他单词,因此这被解释为-s rr不是-r选项。此外,如果您碰巧使用选项运行make,请说make -k,然后MAKEFLAGSk s r,make会将其解释为-k s r,然后-s } flag也不会被设置。

简而言之,当你想要修改MAKEFLAGS时,只需在破折号总是前面加上你的选项:

MAKEFLAGS += -s
MAKEFLAGS += -r