If my program has to return different values (e.g. 0, 1, 2, 3, etc) for different outcomes (mostly errors), the makefile that calls this program would have to stop executing the rest of the makefile commands. Is there a way to continue executing the makefile even if that command produced an error (return a non-zero value)?
Thank you all.
mycommand; test $? -gt 3
Change the test as appropriate. I don't think using -
or -k
is a good idea, as it will stop make
from detecting errors.
Note the 2 commands MUST be on the same line, when in a makefile.
Added after comment feedback: You can also do the following, to allow you to unconditionally run follow-on commands before reacting to an error:
mycommand; status=$PIPESTATUS; follow-on-command && test $status -gt 3
To test a command that I know will return a non-zero exit code, I use like this:
test: mybadcommand
mybadcommand; test $$? -eq 1
This tests that mybadcommand returns a 1 exit value. Note that in Makefiles, you are required to escape the shell variable which refers to exit statuses, because in the world of make $? means dependencies that are newer than the target.
Thus, in the above snippet, be careful to use $$? rather than $?.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With