<?xml version="1.0" encoding="ISO-8859-1"?>
<project name="nextmidas" default="build" basedir=".">
  <description>
        Ant Build script for NeXtMidas. This file is still a work in progress,
        and does not recreate every aspect of the NeXtMidas build system.
    </description>

  <property environment="env" />

  <!-- java version to compile as/target -->
  <property name="JAVA_VERSION" value="1.7" />
  <!-- should compilation include debugging symbols? -->
  <property name="DEBUG" value="false" />

  <path id="nxm.tools.classpath">
    <pathelement path="${env.NMROOT}/tools" />
  </path>

  <path id="nxm.classpath">
    <pathelement path="${env.JAVAHOME}/lib/tools.jar" />
    <path refid="nxm.tools.classpath" />
    <pathelement path="${env.NMROOT}" />
  </path>

  <!-- Main build target for NeXtMidas. -->
  <target name="build" depends="checkenv,
                  compile.tools,
                  generate.libm,
                  copysysjars,
                  compile.bootclasses,
                  copyalljars" />

  <target name="checkenv">
    <fail message="NMROOT not defined" unless="env.NMROOT" />
    <fail message="JAVAHOME not defined" unless="env.JAVAHOME" />
    <!-- probably need to check more -->
  </target>

  <target name="compile.tools">
    <javac includeAntRuntime="no" executable="${env.JAVAHOME}/bin/javac"
      srcdir="${env.NMROOT}/tools" destdir="${env.NMROOT}/tools"
      source="${JAVA_VERSION}" target="${JAVA_VERSION}"
      fork="true" debug="${DEBUG}">
      <include name="**/*.java"/>
    </javac>
  </target>

  <target name="check.sys.libm.Operators.cnf">
    <uptodate property="do.generate.libm"
               srcfile="${env.NMROOT}/nxm/sys/libm/Operators.java"
            targetfile="${env.NMROOT}/nxm/sys/libm/Operators.cnf">
    </uptodate>
  </target>

  <target name="generate.libm" depends="check.sys.libm.Operators.cnf" if="do.generate.libm">
    <java classname="NmClassLoader" fork="true">
      <classpath refid="nxm.tools.classpath" />
      <jvmarg value="-DSHELL=tools.NmMake" />
      <jvmarg value="-DNMROOT=${env.NMROOT}" />
      <arg value="gen" />
    </java>
  </target>

  <target name="copysysjars">
    <copy todir="${env.NMROOT}/jars">
      <fileset dir="${env.NMROOT}/nxm/sys/jars">
        <include name="*.jar" />
      </fileset>
    </copy>
  </target>

  <target name="copyalljars">
    <copy todir="${env.NMROOT}/jars">
      <fileset dir="${env.NMROOT}/nxm">
        <include name="**/jars/*.jar" />
      </fileset>
    </copy>
  </target>

  <target name="compile.bootclasses">
    <javac includeAntRuntime="no" executable="${env.JAVAHOME}/bin/javac"
      srcdir="${env.NMROOT}" destdir="${env.NMROOT}" source="${JAVA_VERSION}"
      target="${JAVA_VERSION}" fork="true" debug="${DEBUG}">
      <compilerarg value="-deprecation" />
      <include name="tools/*.java" />
      <include name="nxm/sys/lib/*.java" />
      <include name="nxm/sys/intr/*.java" />
      <include name="nxm/sys/libm/Generate.java" />
      <classpath>
        <pathelement path="${env.NMROOT}" />
        <pathelement path="${env.NMROOT}/tools" />
        <pathelement path="${env.JAVAHOME}/lib/tools.jar" />
        <fileset dir="${env.NMROOT}/jars">
          <include name="*.jar" />
        </fileset>
      </classpath>
    </javac>
  </target>
</project>
