#! /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=elf"
OBJDUMP="$PIC30_CD/bin/xc16-objdump -omf=elf"
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 t.map
$GCC30 -o t.exe t1.c t2.s -Os -Wa,-W -Wl,-Map=t.map,--no-data-init
err=$?
if [ $vflag = "on" ]; then
    echo
    echo "$GCC30 -o t.exe t1.c t2.s -Wl,-Map=t.map"
    echo $err
    echo
fi

rm -f temp
$OBJDUMP -d -j .text --start=0x100 --stop=0x106 t.exe > test.out
err=$?
if [ $vflag = "on" ]; then
    echo
    echo "$OBJDUMP -d -j .text --start=0x100 --stop=0x106 t.exe > test.out"
    echo $err
    echo
fi

if [ $vflag = "on" ]; then
    cat test.out
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
