Issue
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.
Solution
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.
Answered By - Barmar