#! /bin/sh

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

GLD30=$PIC30_CD/bin/pic30-ld
SCRIPT_PATH=$PIC30_CD/support/gld

#
# END CONFIGURATION
#

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

rm -f temp1 
$GLD30 --verbose > temp1
err=$?
if [ $vflag = "on" ]; then
    echo
    echo "$GLD30 --verbose > temp1"
    echo $err
    echo
fi

rm -rf temp2 temp3 test.out
sed -e '/^$/d' -e '/^.$/d' -e '/^\/\*/d' -e '/^\*\*/d' -e '/vers/d' < temp1 > temp2
sed -e '/^$/d' -e '/^.$/d' -e '/^\/\*/d' -e '/^\*\*/d' -e '/vers/d' < $SCRIPT_PATH/p30sim.gld > temp3
diff -b temp2 temp3 > 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
