#!/bin/sh
#
# A script for compiling a kernel C file.
#
# Usage:
#
#	llkcc name target_dir source_dir -d {debug|standard} [ options... ]
#


usage="llkcc name target_dir source_dir -d {debug|standard} [ options ... ]"

if [ $# -lt 3 ]
then
  echo $usage
  exit 1
fi

name=$1
tdir=$2
sdir=$3
shift;shift;shift

if [ "x$1" = "x-d" ]
then
  level=$2
  shift;shift
else
  level=standard
fi

options=$*

if [ "$level" = "debug" ]
then
  copt="-O -g"
else
  copt="-O"
fi

# Work around speed degradation when assembling to a file over NFS
tmpo=${TMPDIR-/var/tmp}/iltobj$$.o


gcc $copt \
	-I$ILT_DIR/talk/common -I$ILT_DIR/talk/i86_linux1.2_gnu2.7  \
	 -fPIC $options \
	-c $sdir/$name.c -o $tmpo && mv $tmpo $tdir/$name.o
