0

Specifically:

make --directory=$1/build
if [ $? -eq 1 ]; then
   echo "Bad build"
   exit 1
else
   echo "Good build"
fi

This does not 'fail' when it actually fails. If it matters...the makefiles are generated by CMake.

1
  • FYI, make exiting with 1 with -q and >1 for any other failure is mandated by the POSIX standard for make, so all standard make's behave this way. In general in POSIX it's wrong to test for an exact error code unless you've read the documentation and want to differentiate between different errors. The assumption is that there's one way to succeed and many ways to fail, so an exit code of 0 means success, and any other exit code means error. If you just want to know "did it work" you should compare $? -ne 0 (or if-condition as in the answer below), not $? -eq 1. Commented Jun 7, 2021 at 18:09

1 Answer 1

2

The GNU make man page says (emphasis added):

GNU make exits with a status of zero if all makefiles were successfully parsed and no targets that were built failed. A status of one will be returned if the -q flag was used and make determines that a target needs to be rebuilt. A status of two will be returned if any errors were encountered.

So you need to check for $? -eq 2 to detect errors.

Since you didn't use -q, you can also just check if the exit status is non-zero:

if make --directory="$1/build"
then
    echo "Good build"
else
    echo "Bad build"
    exit 1
fi

Don't forget to quote $1 in case it contains whitespace.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.