#! /bin/sh
#
#  This script automates running clang-analyzer on RTEMS
# 
#  $Id: do_coverity,v 1.2 2010/06/16 18:35:13 joel Exp $
#

#
# TODO:
#   + parse arguments for some of the hard-coded items.
#   + better instructions on setup. Where to download, etc.
#

RTEMS_BIN=/opt/rtems-4.11/bin
RTEMS_TARGET=sparc-rtems4.11
RTEMS_BSP=sis
#RTEMS_TARGET=i386-rtems4.11
#RTEMS_BSP=pc386

#
#  Checks the status returned by executables and exits if it is non-zero.
#
check_fatal()
{
  if [ $1 -ne 0 ] ; then
    shift
    echo "ERROR: $*" >&2
    exit 1
  fi
}

type ${RTEMS_TARGET}-gcc
check_fatal $? "gcc not in path"

type scan-build 2>/dev/null
check_fatal $? "scan-build not in PATH"

# Clean build directory and start over
rm     -rf  b-clang-${RTEMS_TARGET}
check_fatal $? "Could not make build directory"
mkdir       b-clang-${RTEMS_TARGET}
check_fatal $? "Could not make build directory"
cd          b-clang-${RTEMS_TARGET}
check_fatal $? "Could not cd to build directory"

# Configure RTEMS
# XXX
$r/configure --target=${RTEMS_TARGET} --enable-multilib \
  --disable-networking --disable-itron --disable-tests \
  --enable-rtemsbsp=${RTEMS_BSP} >c.log 2>&1
check_fatal $? "could not configure RTEMS"

BASE=`pwd`

# Build RTEMS
#cd ${RTEMS_TARGET}/cpukit
#check_fatal $? "could not cd to build directory"
scan-build --experimental-checks -o ${BASE}/output make >${BASE}/b.log 2>&1
check_fatal $? "could not make RTEMS"

# Ran completed OK
exit 0
