#!/bin/sh
# 
# This shell script invokes the Gofer compiler `gofc' to produce a C file,
# followed by the `gcc' C compiler to produce an executable. Arguments are as
# for `gofer' and `gofc'. Like `gofc', it uses the last argument to form the
# program name, but ensures that this has an extension to avoid overwriting.
#
# Ian Holyer,  October 1993  (now uses sh, not csh)

args=$*
while test $# -gt 1; do shift; done
case $1 in
   *.gs)      prog=`dirname $1`/`basename $1 .gs` ;;
   *.gof)     prog=`dirname $1`/`basename $1 .gof` ;;
   *.lgs)     prog=`dirname $1`/`basename $1 .lgs` ;;
   *.gp)      prog=`dirname $1`/`basename $1 .gp` ;;
   *.prj)     prog=`dirname $1`/`basename $1 .prj` ;;
   *.prelude) prog=`dirname $1`/`basename $1 .prelude` ;;
   *.hs)      prog=`dirname $1`/`basename $1 .hs` ;;
   *.has)     prog=`dirname $1`/`basename $1 .has` ;;
   *.lhs)     prog=`dirname $1`/`basename $1 .lhs` ;;
   *.lit)     prog=`dirname $1`/`basename $1 .lit` ;;
   *.verb)    prog=`dirname $1`/`basename $1 .verb` ;;
   *)
      echo The source program $1 does not have one of the standard
      echo extensions for Gofer or Haskell program or project files:
      echo '(.gs .gof .lgs .gp .prj .prelude .hs .has .lhs .lit or .verb)'
      exit
      ;;
esac

GOFER=/usr/local/lib/Gofer/standard.prelude
export GOFER
/usr/local/lib/Gofer/gofc $args
echo '[Compiling with gcc]'
gcc -o $prog -O $prog.c /usr/local/lib/Gofer/runtime.o -lm
strip $prog
rm $prog.c
