#!/bin/sh
#
# RoBIOS batch file for gnu-68000-asm
#
# Bugs:
# - Linker scripts does not handle exception, using -fno-exceptions.
# - libraries lack __rtti_user and __rtti_si symbols, using -fno-rtti

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

# apapt the following path if necessary
export basedir=/user/res/uwarobot
export gccdir=$basedir/g++-m68k
export gccparts=$gccdir/lib/gcc-lib/m68k-coff/2.95.2

export libc=$basedir/libc/include
export mc=$basedir/mc

export PATH=$gccdir/bin:/bin

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

export CFLAGS="$WARN -I$mc/include -I$libc -I$gccdir/include/g++-3 $CPU -O -fno-exceptions -fno-rtti -msoft-float  $opts"

# run c++ for a list of .cc source files

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

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

    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 $opts $LIBS

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

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

    echo " "
done

