#! /bin/sh

if [ -f $HOME/.antrc ] ; then
  . $HOME/.antrc
fi

if [ "$ANT_HOME" = "" ] ; then
  # try to find ANT
  if [ -d /opt/ant ] ; then
    ANT_HOME=/opt/ant
  fi

  if [ -d ${HOME}/opt/ant ] ; then
    ANT_HOME=${HOME}/opt/ant
  fi

  ## resolve links - $0 may be a link to ant's home
  PRG=$0
  progname=`basename $0`

  while [ -h "$PRG" ] ; do
    ls=`ls -ld "$PRG"`
    link=`expr "$ls" : '.*-> \(.*\)$'`
    if expr "$link" : '.*/.*' > /dev/null; then
	PRG="$link"
    else
	PRG="`dirname $PRG`/$link"
    fi
  done

  ANT_HOME=`dirname "$PRG"`/..

fi

# Allow .antrc to specifiy flags to java cmd
if [ "$JAVACMD" = "" ] ; then
  JAVACMD=java
fi

# Use the original tools.jar if available
if [ ! "$JAVA_HOME" = "" ] ; then
   CLASSPATH=${JAVA_HOME}/lib/tools.jar:$CLASSPATH
   CLASSPATH=${JAVA_HOME}/lib/classes.zip:$CLASSPATH
fi


CLASSPATH=${ANT_HOME}/lib/xml.jar:$CLASSPATH
CLASSPATH=${ANT_HOME}/lib/ant.jar:$CLASSPATH
CLASSPATH=${ANT_HOME}/lib/moo.jar:$CLASSPATH
export CLASSPATH

$JAVACMD -Dant.home=${ANT_HOME} org.apache.tools.ant.Main $@
