#! /bin/sh

#
# CONFIGURATION SECTION
#
if [ -z "$PIC30_CD" ]; then
    echo "Environmental variable PIC30_CD must be set up.";
    exit 1;
fi


XGCC=$PIC30_CD/bin/pic30-gcc
INC_PATH=$PIC30_CD/include
LIB_PATH=$PIC30_CD/lib

#
# END CONFIGURATION
#

# process args
vflag=off
while [ $# -gt 0 ]
do
    case "$1" in
        -v)  vflag=on;;
    esac
    shift
done

rm -f t.exe
$XGCC -o t.exe t1.c -I$INC_PATH -L$LIB_PATH 2>temp
err=$?
if [ $vflag = "on" ]; then
    echo
    echo "$XGCC -o t.exe t1.o 2>temp"
    echo $err
fi


if [ $vflag = "on" ]; then
    echo
    echo "Output from pic30-gcc:"
    echo
    cat temp
fi

STR="Error"
grep -q "Error" temp
if [ $? -eq 0 ]; then
    echo $STR > test.out
else
    cp temp test.out
fi
rm -f temp

echo
echo `head -1 info.txt`

if [ $vflag = "on" ]; then
    diff -b -B test.out expect.out
else
    diff -b -B test.out expect.out > /dev/null
fi


if [ $? -ne 0 ]; then
    echo "ERRORs Detected!!"
    echo
    exit 199
fi

echo "All Tests Pass"
echo
exit 0
