#!/bin/sh
grep=egrep
LOGFILENAME=$1
# FIXME: This regexp may not catch all error messages emitted;
# probably should be refined with a more complete regexp.
# The [^-]fail part is to prevent it from interpreting the
# tar "ignore-failed-read" switch as an error message.
errorRegexp="error|[^-]fail|\*\*[^.]"
if [ -f $LOGFILENAME ]
then
  errors=$($grep -i $errorRegexp $LOGFILENAME)
  if [ -z "$errors" ]
  then
    exit 0
  else
    echo
    echo "Possible build problems found:"
    echo
    $grep -i "$errorRegexp" $LOGFILENAME
    echo
    echo "Stopping."
    echo
    exit 1
  fi
else
  echo
  echo "No $LOGFILENAME file found."
  echo "To generate a $LOGFILENAME file, run 'make' like this:"
  echo
  echo "  make all 2>&1 | tee $LOGFILENAME"
  echo
  exit 1
fi
