是否可以将警告视为 Makefile 中的错误(从而在 Makefile 继续之前退出)
此外,是否可以过滤掉哪个警告会产生错误?
我的用例:我想使用--warn-undefined-variables
与此结合,当变量未定义时,Makefile 将退出,这是一个非常常见的错误来源。显然我不想手动检查每个变量,因为这很容易出错/乏味。我找不到任何相关内容,但这是一个非常重要/基本的功能。
注:我不是在寻找-Werror
这是 gcc 特定命令,不适用于我的用例。
如果您准备向每个目标添加依赖项,则可以将警告变为错误。
这是一个包含错误的 make 文件(“SRCS”而不是“SRC”):
# Turn on the warning we want
MAKEFLAGS += --warn-undefined-variables
# Make sure MAKECMDGOALS is defined, so it doesn't cause an error itself
ifndef MAKECMDGOALS
MAKECMDGOALS = all
endif
SRC=hello.c
all: compile
# Fails if the Makefile contains any warnings.
# Run this Makefile with the same goals, but with the -n flag.
# Grep for warnings, and fail if any are found.
no-make-warnings:
! make -n $(MAKECMDGOALS) 2>&1 >/dev/null | grep warning
# Targets you want to check must depend on no-make-warnings
compile: no-make-warnings
gcc -o hello $(SRCS)
当我运行它时,我看到这个:
$ make
! make -n all 2>&1 >/dev/null | grep warning
Makefile:17: warning: undefined variable `SRCS'
make: *** [no-make-warnings] Error 1
你只需要让你想要检查的每个目标都依赖于目标no-make-warnings
.
如果有人知道如何自动执行此操作,请插话。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)