如何将警告视为Makefile中的错误? [英] How to treat a warning as an error in a Makefile?
问题描述
-
是否可以将警告视为Makfile中的错误(从而在Makefile进行之前退出)
Is it possible to treat warnings as errors in a Makfile (and thus exit before Makefile proceeds)
此外,是否可以过滤出哪个警告会产生错误?
Furthermore, is it possible to filter out which warning yields an error?
我的用例:我想与此结合使用--warn-undefined-variables
,以便在未定义变量时退出Makefile,这是一个非常常见的错误源.显然,我不想手动检查每个变量,因为这容易出错/乏味.我对此一无所获,但这是一个非常重要/基本的功能.
My use case: I want to use --warn-undefined-variables
in combination with this so that Makefile will exit when a variable is undefined, which is a very common source of error. Obviously I don't want to manually check for each variable as this is error-prone/tedious. I couldn't find anything on this, but it's a pretty important/basic feature.
注意:我不是要查找-Werror
,这是不适用于我的用例的特定于gcc的命令.
Note: I'm not looking for -Werror
which is a gcc specific command not applicable to my use case.
推荐答案
make的标准版本不支持您要查找的内容.但是,构建自己的make版本来满足用例应该并不困难.
The standard version of make does not support what you are looking for. However, it should not be difficult to build your own version of make to fulfill your use case.
查看make 3.82的源代码,在variable.h中检出宏warn_undefined
:
Looking at the source code of make 3.82, check out the macro warn_undefined
in variable.h:
214 /* Warn that NAME is an undefined variable. */
215
216 #define warn_undefined(n,l) do{\
217 if (warn_undefined_variables_flag) \
218 error (reading_file, \
219 _("warning: undefined variable `%.*s'"), \
220 (int)(l), (n)); \
221 }while(0)
我还没有尝试过,但是我认为用fatal
替换error
应该足够了.
I have not tried this, but I think it should be sufficient to replace error
with fatal
.
这篇关于如何将警告视为Makefile中的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!