#!/bin/sh
#
# RoBIOS batch file for gnu-68000-asm

# Need to do this before we reset the PATH below
files=`echo $*|tr ' ' "\n"|grep -v ^-`
opts=`echo $*|tr ' ' "\n"|grep ^-`

# apapt the following path if necessary
export basedir=/user/res/uwarobot
export gccdir=$basedir/gcc-m68k
export gccparts=$gccdir/lib/gcc-lib/m68k-coff/2.7.2
export libc=$basedir/libc/include
export mc=$basedir/mc

export PATH=$gccdir/bin:/bin

export CC="m68k-coff-gcc -B$gccparts/"
export WARN="-W -Wall -ansi -pedantic"
export CPU=-m68332
export LIBS="-limpro -lmym -lmyc -lmygcc -lrobi"
export TMP=/tmp
export LDSCRIPT=-T$mc/ldfiles/robi-ram.ld

export CFLAGS="$WARN -I$mc/include -I$libc  $CPU -O -msoft-float  $opts"

# run gcc for a list of .c source files

for file in $files; do
    name=`basename $file .c`
    tmpfile=$TMP/$name

    echo FILE $file
    echo c-compiler
    $CC $CFLAGS -S -c $file

    echo 68332-assembler
    m68k-coff-as -o $tmpfile.o $name.s

    echo linker
    m68k-coff-ld $LDSCRIPT -L$mc/lib -o $tmpfile.l $tmpfile.o $LIBS $opts

    echo obj-copy
    m68k-coff-objcopy -O srec $tmpfile.l $name.hex

    /bin/rm $name.s $tmpfile.l $tmpfile.o

    echo " "
done

