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.
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.
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
Use
command || [ $$? -eq v ]
as your command, substituting command with the command, and v with the value returned on success.
(This is just a more compact version of Didier Trosset's answer.)
Depending on how the tool behaves on fail, you could just check for the existence of the output file. something like:
@if test ! -f $(FILE); then exit 2; fi
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