#!/bin/sh

# This script wraps around m68k-coff-gcc, providing a cross compiler
# interface similar to that provided by gcc for native compilations.
# That is, both single-file compilations and multiple-file builds are
# supported.

# Written by Jason Foo <sentinel@tartarus.uwa.edu.au>
# Last updated on 17 April 2002

# Define the program name.
CC=m68k-coff-gcc

# Define the compiler options.
CFLAGS="-m68332 -I\"$MC/include\""
LDLIBS="-L\"$MC/lib\""
SCRIPT="-Wl,-T\"$MC/ldfiles/robi-ram.ld\",--oformat,srec"

# Abort with an error message if no files were specified.
if test -z "$*"
then
    echo "$0: no input files."
    exit 1
fi

# Determine whether to perform linking or not.
LINK=1
for ARGUMENT in $*
do
    # Don't link if -c option specified.
    if test "${ARGUMENT:0:2}" = -c
    then
	LINK=0
    fi
    # Don't link if -S option specified.
    if test "${ARGUMENT:0:2}" = -S
    then
	LINK=0
    fi
    # Don't link if -E option specified.
    if test "${ARGUMENT:0:2}" = -E
    then
	LINK=0
    fi
    # Don't link if -M option specified.
    if test "${ARGUMENT:0:2}" = -M
    then
	LINK=0
    fi
    # Don't link if -MM option specified.
    if test "${ARGUMENT:0:3}" = -MM
    then
	LINK=0
    fi
done

# Run the compiler.
if test $LINK = 1
then
    eval $CC $CFLAGS -nostdlib $LDLIBS $* $SCRIPT
    exit $?
else
    eval $CC $CFLAGS $*
    exit $?
fi
