#! /bin/sh

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

GCC30="$PIC30_CD/bin/xc16-gcc -omf=coff"

#
# END CONFIGURATION
#

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

rm -f t.exe t.map
$GCC30 -o t.exe -Wl,-p30F6014 t1.s -Tp30F2010.gld > temp 2>&1
err=$?
if [ $vflag = "on" ]; then
    echo
    echo "$GCC30 -o t.exe -Wl,-p30F6014 t1.s -Tp30F2010.gld"
    echo $err
    echo
fi

# keep part of the expected error message
grep -o "Warning.*" temp > test.out
rm -f temp

if [ $vflag = "on" ]; then
    echo
    echo "Output from linker:"
    echo
    cat test.out
    echo
fi

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
