<?xml version="1.0" encoding="utf-8" ?>
<project default="all">
  <property name="package.prefix" value="de/tuberlin/polymake" />
  <property name="build.sysclasspath" value="ignore" />

  <property name="jreality.path" value="${polymake.top}/bundled/jreality/external/jreality"/>

  <target name="build.jreality">
    <sequential>
      <ant
          dir="${jreality.path}"
          antfile="build.xml">
        <target name="core"/>
        <target name="io"/>
        <target name="jogl"/>
        <target name="soft"/>
        <target name="plugin"/>
      </ant>
      <copy todir="${build.dir}/jars"
            preservelastmodified="yes">
        <fileset dir="${jreality.path}/dist" includes="*.jar" />
      </copy>
    </sequential>
  </target>

  <target name="clean.jreality">
    <ant
        dir="${jreality.path}"
        antfile="build.xml"
        target="clean"/>
  </target>

  <target name="init" depends="build.jreality">
    <!-- Create the time stamp -->
    <tstamp/>
    <mkdir dir="${build.dir}/bundled/jreality/java" />
  </target>

  <path id="compile.classpath">
    <fileset dir="${jreality.path}/lib" includes="*.jar" />
    <fileset dir="${build.dir}/jars" erroronmissingdir="yes">
      <include name="polymake_java.jar" />
      <include name="jReality-*.jar" />
    </fileset>
  </path>

  <target name="compile" depends="init">
    <sequential>
      <javac
             executable="${javac}"
             srcdir="src"
             destdir="${build.dir}/bundled/jreality/java"
             failonerror="true"
             debug="${debug}"
             encoding="UTF8">
        <include name="${package.prefix}/**"/>
        <classpath refid="compile.classpath"/>
      </javac>
      <copy todir="${build.dir}/bundled/jreality/java"
            preservelastmodified="yes">
        <fileset
                dir="src"
                includes="**/*.html,**/*.txt"
                excludes="**/*.java" />
      </copy>
    </sequential>
  </target>

  <target name="all" depends="compile">
    <jar destfile="${build.dir}/jars/${jar.name}">
        <fileset
                 dir="${build.dir}/bundled/jreality/java"
        	 includes="${package.prefix}/**" />
    </jar>
    <touch file="${build.dir}/jars/${jar.name}" />
  </target>

  <target name="clean" depends="clean.jreality">
    <delete quiet="true">
      <fileset dir="${build.dir}/bundled/jreality/java" />
      <fileset dir="${build.dir}/jars" includes="jReality-*.jar" />
    </delete>
  </target>
</project>
