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.
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.
-qand >1 for any other failure is mandated by the POSIX standard formake, 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 of0means 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.