Error checking make file behavior

If my program should return different values ​​(for example, 0, 1, 2, 3, etc.) for different results (mostly errors), the makefile calling this program would have to stop executing the rest of the makefile commands. Is there a way to continue executing the makefile even if this command throws an error (returns a nonzero value)?

Thanks to everyone.

+4
source share
2 answers
mycommand; test $? -gt 3 

Modify the test accordingly. I don't think using - or -k is a good idea, as this will prevent detection of make errors.

Note that 2 commands MUST be on the same line when in the makefile.

Added after comments: You can also do the following so that you can unconditionally run the following commands before reacting to the error:

 mycommand; status=$PIPESTATUS; follow-on-command && test $status -gt 3 
+3
source

To test the command that I know will return a non-zero exit code, I use like this:

 test: mybadcommand mybadcommand; test $$? -eq 1 

This checks that mybadcommand returns a value of 1 output. Note that in Make files you are required to avoid a shell variable that refers to exit statuses, because in the world of make $? means addictions that are newer than the goal.

So, in the above snippet, be careful to use $$? , not $ ?.

+3
source

All Articles