#!/bin/sh
# Run experimental Modula-3 compiler, connected to Energize if "-Xez" given.
#	6/26/94 D.N.G.
echo + $0 $*
args=""
o_arg=""
a_arg=""
ez=""
c_arg="no"
source=""
make_pgm=""
bc="$*"
comp_args="-c"
while [ $# -gt 0 ]
do
  case "$1" in
    -o)		o_arg="$2"; shift;;
    -a)		a_arg="$2"; args="$args $1 $2" ; shift;;
    -Xez*)	ez="${1}:"; comp_args="$comp_args $1";;
    -c)		c_arg=yes; args="$args $1";;
    *.m3|*.i3)	source="$1"; args="$args $1"; comp_args="$comp_args $1";;
    -Y0*)	;;
    -Y2*)	;;
    -Y3*)	;;
    -A|-D*|-w?|-g*|-O*) args="$args $1"; comp_args="$comp_args $1";;
    -make-wrapper) make_pgm="$2" ; shift;;
    *)		args="$args $1";;
  esac
  shift
done
if [ "$o_arg" != "" ]
then
  args="-o $o_arg $args"
  if [ "$make_pgm" != "" -a "$ez" != "" -a -z "$ENERGIZE_UNDER_BUILD" ]
    then energize_make_target "$o_arg" -Xez -type Executable \
	-build-option 'do not build sub-targets' \
	-build-command "$make_pgm -Xez"
  fi
fi

#  The following is what should be done, but the Energize Server is currently
#  having trouble with it (bug 20810):
#if [ "$a_arg" != "" ]
#then
#  if [ "$make_pgm" != "" -a "$ez" != "" -a -z "$ENERGIZE_UNDER_BUILD" ]
#    then energize_make_target "$a_arg" -Xez -type Library \
#	-build-option 'do not build sub-targets' \
#	-build-command "$make_pgm -Xez"
#  fi
#fi

if [ "$ez" = "" ]
  then bc=""
  else 
    if [ $c_arg = no ]
    then bc="-c $bc"
    fi
    if [ "$source" = "" ]
      then bc="$comp_args"
    fi
    bc="-BC=`basename $0` ${bc}:"
fi
set -x
exec /u/gray/modula-3-release-3.3/installation/lib/m3/SPARC/m3 \
	"-Y0:/u/gray/modula-3-release-3.3/installation/lib/m3/SPARC/m3c-ez:-tSPARC:$ez$bc" \
	"-Y2:lcc:-Xk:$ez" "-Y3:energize_ar:${ez}cru:" $args
