曲径通幽论坛

标题: Makefile 中的 error 函数 [打印本页]

作者: beyes    时间: 2010-11-25 13:06
标题: Makefile 中的 error 函数
Makefile 中 error 函数表示产生了一个致命错误,当它执行后,编译会停止。
它的使用方法是:
$(error <错误消息>)


测试代码:

KBUILD_VERBOSE := 1
TEST_MSG := "are you ok?"
ifeq ($(KBUILD_VERBOSE), 1)   
$(error KBUILD_VERBOSE is $(KBUILD_VERBOSE), we will stop here)   
quite =   
Q =
else   
quite = quiet_   
Q = @
endif
all:         
               $(Q)echo $(TEST_MSG)

运行输出:
beyes@debian:~/makefile_test/error$ make
Makefile:7: *** KBUILD_VERBOSE is 1, we will stop here。 停止。

由输出可见,all: 目标下的 echo 语句并没有执行输出,整个编译在 error 函数执行后停止了。如果将上面的 KBUILD_VERBOSE 的值改为 0 ,那么再 make 时输出:
beyes@debian:~/makefile_test/error$ make
are you ok?





欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) Powered by Discuz! X3.2