#! /bin/sh

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

CC30="$PIC30_CD/bin/xc16-gcc -omf=coff"
GAS30="$PIC30_CD/bin/xc16-as -omf=coff -W"
GLD30="$PIC30_CD/bin/xc16-ld -omf=coff"
OBJDUMP="$PIC30_CD/bin/xc16-objdump -omf=coff"


#
# END CONFIGURATION
#

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

rm -f t1.o t.exe
$CC30 -o t.exe t1.s -mcpu=30F6014 -T p30F6014.gld -save-temps
err=$?
if [ $vflag = "on" ]; then
    echo
    echo "$CC30 -o t.exe t1.s -mcpu=30F6014 -T p30F6014.gld"
    echo $err
fi

rm -f test.out
if [ $vflag = "on" ]; then
    echo
    $OBJDUMP -s t.exe | grep ".ivt"
    $OBJDUMP -s t.exe | grep ".aivt"
fi
$OBJDUMP -h t.exe | grep -w "\.ivt" > test.out
$OBJDUMP -h t.exe | grep -w "\.aivt" >> test.out

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
