#!/bin/sh
##
##  ecj.sh -- Eclipse Compiler for Java (ECJ) Frontend
##

#   determine Java platform
ECJ_JAVA_PLATFORM=""
if [ $# -gt 0 ]; then
    case "$1:$2" in
        -V*:* )
            ECJ_JAVA_PLATFORM=`echo "X$1" | sed -e 's;^X-V;;'`
            shift
            ;;
        -V:* )
            ECJ_JAVA_PLATFORM="$2"
            shift; shift
            ;;
    esac
fi

#   determine java(1)
if [ ".$ECJ_JAVA_PLATFORM" = .gnu-gcj ] ||\
   [ ".`@l_prefix@/bin/java-toolkit -l`" = . ]; then
    #   special case for bootstrapping without a
    #   complete Java infrastructure installed, so
    #   short-circuit to GCC/GCJ's gij(1) directly
    #   (BOOTSTRAPPING)
    _java="@l_prefix@/bin/gij"
elif [ ".$ECJ_JAVA_PLATFORM" != . ]; then
    #   regular case with the complete
    #   Java infrastructure installed and
    #   an explicitly requested platform
    _java="@l_prefix@/bin/java -V$ECJ_JAVA_PLATFORM"
else
    #   regular case with the complete
    #   Java infrastructure installed and
    #   NO explicitly requested platform
    #   (DEFAULT)
    _java="@l_prefix@/bin/java"
fi

#   pass-through execution to the Java interpreter
exec $_java \
    -jar @l_prefix@/libexec/ecj/ecj.jar \
    "$@"

