#! /bin/sh
#
# This is a simple script that makes sure that checkbuilds can be 
# created and then runs it
# The cb suffix is for "check build"
srcdir=/home/gropp/projects/mpich2
if [ -z "$tmpdir" ] ; then tmpdir=/sandbox/gropp ; fi
if [ -z "$rundir" ] ; then rundir=$tmpdir/cb/mpich2 ; fi
if [ -z "$mpichtestdir" ] ; then mpichtestdir=$tmpdir/cb/mpitest ; fi
if [ -z "$mpicxxtestdir" ] ; then mpicxxtestdir=$tmpdir/cb/mpicxxtest ; fi
if [ -z "$inteltestdir" ] ; then inteltestdir=$tmpdir/cb/MPITEST ; fi

outdir=/home/gropp/projects/mpich2-tests
date=`date "+%Y-%m-%d"`
# default outfile
outfile=testbuild.xml
tests="mpich;mpicxx;intel;mpich2"
#
# Option options to checkbuild
other_opts=""
#
# Get options
for arg in $@ ; do
    argval=""
    case $arg in 
        -*=*) argval=`echo "$arg" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
    esac

    case $arg in 
    -outfile=*) outfile=$argval ;;
    -outdir=*)  outdir=$argval ;;
    -tests=*)   tests=$argval ;;
    -echo) set -x ;;
    *) other_opts="$other_opts $arg" ;;
    esac
done

# Construct the full outfile name from the dir and file
outfile="$outdir/$outfile"

if [ ! -d $rundir ] ; then 
    # Assume that we have mkdir -p
    mkdir -p $rundir
fi
if [ ! -d $outdir ] ; then 
    # Assume that we have mkdir -p
    mkdir -p $outdir
fi
if [ ! -d "$rundir/maint" ] ; then
    mkdir "$rundir/maint"
fi
if [ ! -d $mpichtestdir ] ; then
    mkdir $mpichtestdir
fi
if [ ! -d $mpicxxtestdir ] ; then
    mkdir $mpicxxtestdir
fi
if [ ! -d $inteltestdir ] ; then
    mkdir $inteltestdir
fi
# We don't need to build the mpich2testdir because it is part of the mpich2
# distribution
# Build the current version of checkbuilds
(cd $rundir/maint && $srcdir/maint/configure 2>&1 >/dev/null)
if [ ! -x $rundir/maint/checkbuilds ] ; then
    echo "Could not build checkbuilds"
    exit 1
fi
#
#
# -tests="mpich;mpicxx;intel"
# Use -tests="mpich;mpicxx" to get a smaller list of tests.
$rundir/maint/checkbuilds -rundir=$rundir \
			  -envopt="CC;cc;gcc" -envopt="FC;f77;g77" \
			  -tests="$tests" -tmpdir=$tmpdir \
			  -xml -maxcount=1 -outfile=$outfile $other_opts

