How to get exit status of a shell command used in GNU Makefile?

后端 未结 3 1106
-上瘾入骨i
-上瘾入骨i 2020-12-14 14:59

I have a makefile rule in while I am executing a linux tool. I need to check the exit status of the tool command, and if that command fails the make has to be aborted.

3条回答
  •  失恋的感觉
    2020-12-14 15:16

    In the makefile-:

    mycommand || (echo "mycommand failed $$?"; exit 1)
    

    Each line in the makefile action invokes a new shell - the error must be checked in the action line where the command failed.

    If mycommand fails the logic branches to the echo statement then exits.

提交回复
热议问题