#!/bin/sh
#
# $Id: gontc,v 1.1 2001/11/12 09:42:53 malekith Exp $
#
# Driver program for Gont compiler
#

ksi_compiler=xgcc
gont_compiler=./gontc1
ksi_flags=
compile_only=
output=

while [ "$1" != "" ] ; do
  case "$1" in
    -O* | -f* )
      ksi_flags="$ksi_flags $1"
      ;;
    -c )
      compile_only=-c
      ;;
    -o )
      output="$2"
      shift
      ;;
    *.g )
      if [ "$output" = "" ] ; then
        if test "$compile_only" ; then
          output=$(basename $1 .g).o
	else
	  output=a.out
	fi
      fi
      $gont_compiler < $1 | $ksi_compiler $ksi_flags $compile_only -o $output -x ksi -
      if [ $? != 0 ] ; then
        if test -f $output ; then
          echo 1>&2 "rm -f $output"
	  rm -f $output
	fi
	exit $?
      fi
      ;;
    -* )
      echo 1>&2 "$0: unknown option '$1'"
      exit 1
      ;;
    * )
      echo 1>&2 "$0: don't know what to do with '$1'"
      exit 1
      ;;
  esac
  shift
done
