#! /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"

#
# END CONFIGURATION
#

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

rm -f t1.out t2.out
$GCC30 t1.s -o t.exe -Tt.gld -Wa,-W -Wl,-Map=t.map,--no-check-sections
err=$?
if [ $vflag = "on" ]; then
    echo
    echo "$GCC30 t1.s -o t.exe -Tt.gld -Wl,-Map=t.map,--no-check-sections"
    echo $err
    echo
    head -31 t.map
fi

echo
echo `head -1 info.txt`

if [ $err -ne 0 ]; then
    echo "ERROR Detected!!"
    echo
    exit 99
fi

echo "All Tests Pass"
echo
exit 0
