如何检查Makefile Shell调用的退出状态? [英] How do I check the exit status of a Makefile shell invocation?
本文介绍了如何检查Makefile Shell调用的退出状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Makefile,它运行一个程序,成功时返回一个非零值,失败时返回另一个非零值.我知道我可以通过在命令前面加上-来忽略退出状态,但这是行不通的,因为我需要知道命令是否成功.
I have a Makefile which runs a program which on success return a non-zero value, and on failure return another non-zero value. I know that I can ignore the exit status by prefixing the command with -, but that does not work because I need to know if the command succeeded.
推荐答案
您可以使用包含最后返回值的shell $?
变量,在同一Makefile行上的第二条命令上测试返回值.
You can test the returned value on a second command on the same Makefile line, using the shell $?
variable that contains the last returned value.
例如,使用false
命令显然会停止编译:
For example with the false
command that would obviously stop the compilation:
test:
/bin/false ; /usr/bin/test "$$?" -eq 1 # <-- make does not stop here
/bin/echo "Continues ..."
/bin/false # <-- make stops here
这篇关于如何检查Makefile Shell调用的退出状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文