<?xml version="1.0" standalone="yes"?>
<!-- build configuration -->
<project name="narya" default="compile" basedir=".">

  <!-- import overriding properties -->
  <property file="build.properties"/>

  <!-- configuration parameters -->
  <property name="app.name"       value="narya"/>
  <property name="build.compiler" value="jikes"/>
  <property name="build.optimize" value="off"/>
  <property name="deploy.dir"     value="dist"/>

  <!-- derived properties -->  
  <property name="dist.jar"       value="${app.name}.jar"/>
  <property name="javadoc.home"   value="${deploy.dir}/docs"/>

  <!-- we want to access the environment -->
  <property environment="env"/>
  <property name="java.libraries" value="${env.JAVA_LIBS}"/>

  <!-- declare our classpath -->
  <path id="classpath">
    <pathelement location="${deploy.dir}/classes"/>
    <fileset dir="lib" includes="**/*.jar"/>
    <fileset dir="${java.libraries}" includes="**/*.jar"/>
  </path>

  <!-- generates .java files for all .dobj files -->
  <target name="gendobj">
    <apply executable="bin/gendobj" failonerror="true">
      <srcfile/>
      <fileset dir="src/java" includes="**/*.dobj"/>
    </apply>
  </target>

  <!-- prepares the application directories -->
  <target name="prepare" depends="gendobj">
    <mkdir dir="${deploy.dir}"/>
    <mkdir dir="${deploy.dir}/classes"/>
    <mkdir dir="${deploy.dir}/classes/rsrc"/>
    <mkdir dir="${javadoc.home}"/>
    <copy todir="${deploy.dir}/classes">
      <fileset dir="src/java" includes="**/*.properties"/>
    </copy>
    <copy todir="${deploy.dir}/classes/rsrc">
      <fileset dir="rsrc" includes="**/*" excludes="**/bundles/**"/>
    </copy>
  </target>

  <!-- cleans out the installed application -->
  <target name="clean">
    <delete dir="${deploy.dir}"/>
  </target>

  <!-- build the java class files -->
  <target name="compile" depends="prepare">
    <javac srcdir="src/java" destdir="${deploy.dir}/classes"
           debug="on" optimize="{$build.optimize}" deprecation="off">
      <classpath refid="classpath"/>
    </javac>
  </target>

  <!-- build the javadoc documentation -->
  <target name="javadoc" depends="prepare">
    <javadoc sourcepath="src/java"
             packagenames="com.threerings.*"
             destdir="${javadoc.home}"
             additionalparam="-breakiterator">
      <classpath refid="classpath"/>
      <link href="http://java.sun.com/j2se/1.4/docs/api/"/>
    </javadoc>
    <copy todir="${javadoc.home}">
      <fileset dir="src/java" includes="**/*.png"/>
    </copy>
  </target>

  <!-- a target for rebuilding everything -->
  <target name="all" depends="clean,prepare,compile,javadoc,dist"/>

  <!-- builds our distribution files (war and jar) -->
  <target name="dist" depends="prepare,compile">
    <jar destfile="${deploy.dir}/${dist.jar}"
         basedir="${deploy.dir}/classes"/>
  </target>

  <!-- generate a class hierarchy diagram -->
  <target name="hierviz" depends="prepare,compile">
    <taskdef name="viztool" classname="com.samskivert.viztool.DriverTask"/>
    <viztool visualizer="com.samskivert.viztool.hierarchy.HierarchyVisualizer"
      pkgroot="com.threerings"
      classes="com.threerings.*"
      output="hierviz.ps">
      <classpath refid="classpath"/>
    </viztool>
  </target>

  <!-- generate a class hierarchy diagram -->
  <target name="sumgen" depends="prepare,compile">
    <taskdef name="viztool" classname="com.samskivert.viztool.DriverTask"/>
    <viztool visualizer="com.samskivert.viztool.summary.SummaryVisualizer"
      pkgroot="com.threerings"
      classes=".*Director$"
      output="summary.ps">
      <classpath refid="classpath"/>
    </viztool>
  </target>

</project>
