<?xml version="1.0"?>
<!DOCTYPE project PUBLIC "-//ANT//DTD project//EN" "tools/ant.dtd">
<!-- ============================================================= -->
<!-- Generic ANT build file                                        -->
<!--   this file is used for Samurai Graph                         -->
<!--                                                               -->
<!--                                                               -->
<!-- Author: Yoshihiro OKUMURA                                     -->
<!-- $Id: build.xml,v 1.43 2005/08/18 15:24:25 orrisroot Exp $      -->
<!--                                                               -->
<!-- ============================================================= -->

<project name="samurai-graph" default="default" basedir=".">

  <description>
      SAMURAI GRAPH Project
  </description>

  <!-- project name -->
  <property name="project" value="samurai-graph"/>

  <!-- directory definition -->
  <property name="SG.srcdir"          value="src"/>
  <property name="SG.dstdir"          value="dist"/>
  <property name="SG.dst.libdir"      value="${SG.dstdir}/lib"/>
  <property name="SG.dst.docdir"      value="${SG.dstdir}/doc"/>
  <property name="SG.dst.examplesdir" value="${SG.dstdir}/examples"/>
  <property name="SG.mfdir"           value="${SG.srcdir}/META-INF"/>
  <property name="SG.resdir"          value="${SG.srcdir}/resources"/>
  <property name="SG.classes"         value="classes"/>
  <property name="SG.src.distdir"     value="srcdist"/>
  <property name="SG.javadoc.dstdir"  value="javadoc"/>
  <property name="SG.examplesdir"     value="examples/data"/>
  <property name="SG.src.basedir"     value="${SG.srcdir}/jp/riken/brain/ni/samuraigraph"/>

  <!-- samurai-graph jar properties -->
  <property name="SG.samurai-graph.mf"      value="${SG.mfdir}/MANIFEST.MF"/>
  <property name="SG.samurai-graph.basedir" value="${SG.classes}/samurai-graph"/>
  <property name="SG.samurai-graph.jar"  value="${SG.dstdir}/${project}.jar"/>

  <!-- vectorgraphics -->
  <property name="VG.src.basedir" value="contrib/vectorgraphics"/>
  <property name="VG.src.libdir"  value="${VG.src.basedir}/lib"/>
  <property name="VG.src.docdir"  
    value="${VG.src.basedir}/web/freehep/vectorgraphics/"/>
  <property name="VG.dst.libdir" value="${SG.dst.libdir}/vectorgraphics"/>
  <property name="VG.dst.docdir" value="${SG.dst.docdir}/vectorgraphics"/>

  <!-- classpath -->
  <path id="VG.classpath">
    <pathelement path="${classpath}"/>
    <fileset dir="${VG.src.libdir}">
      <include name="freehep-*.jar"/>
    </fileset>
  </path>

  <!-- default -->
  <target name="default" depends="jar,windows"/>

  <!-- all -->
  <target name="all" depends="jar,javadoc"/>

  <!-- prepare -->
  <target name="prepare">
    <!-- clean up distribution direction -->
    <delete dir="${SG.dstdir}"/>
    <!-- distribution image -->
    <mkdir dir="${SG.dstdir}"/>
    <mkdir dir="${SG.dst.libdir}"/>
    <mkdir dir="${SG.dst.docdir}"/>
    <mkdir dir="${SG.dst.examplesdir}"/>
    <mkdir dir="${VG.dst.libdir}"/>
    <mkdir dir="${VG.dst.docdir}"/>

    <!-- copy samurai-graph static contents -->
    <copy file="COPYING.txt" todir="${SG.dstdir}"/>
    <copy file="LICENSE.txt" todir="${SG.dstdir}"/>
    <copy todir="${SG.dst.examplesdir}">
      <fileset dir="${SG.examplesdir}">
        <include name="**/*.txt"/>
        <include name="**/*.sgp"/>
      </fileset>
    </copy>

    <!-- copy vectorgraphics libraries -->
    <copy todir="${VG.dst.libdir}">
      <fileset dir="${VG.src.libdir}">
        <include name="**/freehep-*.jar"/>
      </fileset>
    </copy>
    <copy 
      file="${VG.src.docdir}/ReleaseNotes-1.2.2.xhtml"
      tofile="${VG.dst.docdir}/ReleaseNotes-1.2.2.html"
    />
    <copy file="${VG.src.basedir}/LGPL.txt" todir="${VG.dst.docdir}"/>
    <copy file="${VG.src.basedir}/LICENSE.txt" todir="${VG.dst.docdir}"/>
    <copy file="${VG.src.basedir}/SAMURAIGRAPH-ChangeLog.txt" todir="${VG.dst.docdir}"/>

    <!-- for jar -->
    <mkdir dir="${SG.classes}"/>
    <mkdir dir="${SG.samurai-graph.basedir}"/>
    <mkdir dir="${SG.samurai-graph.basedir}/resources"/>
    <copy todir="${SG.samurai-graph.basedir}/resources">
      <fileset dir="${SG.resdir}">
        <include name="**/*.properties"/>
        <include name="**/*.gif"/>
        <include name="**/*.png"/>
        <include name="**/*.html"/>
      </fileset>
    </copy>

  </target>

  <!-- compile -->
  <target name="compile" depends="prepare">
    <javac
       srcdir="${SG.src.basedir}/base"
       destdir="${SG.samurai-graph.basedir}"
       encoding="SJIS"
       classpathref="VG.classpath"
    />
    <javac
       srcdir="${SG.src.basedir}/data"
       destdir="${SG.samurai-graph.basedir}"
       encoding="SJIS"
       classpathref="VG.classpath"
    />
    <javac
       srcdir="${SG.src.basedir}/figure"
       destdir="${SG.samurai-graph.basedir}"
       encoding="SJIS"
       classpathref="VG.classpath"
    />
    <javac
       srcdir="${SG.src.basedir}/figure/java2d"
       destdir="${SG.samurai-graph.basedir}"
       encoding="SJIS"
       classpathref="VG.classpath"
    />
    <javac
       srcdir="${SG.src.basedir}/application"
       destdir="${SG.samurai-graph.basedir}"
       encoding="SJIS"
       classpathref="VG.classpath"
    />
  </target>

  <!-- jar file creation -->
  <target name="jar" depends="compile">
    <jar
      jarfile="${SG.samurai-graph.jar}"
      basedir="${SG.samurai-graph.basedir}"
      manifest="${SG.samurai-graph.mf}"
    />
  </target>

  <!-- JavaDoc creation -->
  <target name="javadoc" depends="prepare">
    <mkdir dir="${SG.javadoc.dstdir}"/>
    <javadoc 
       encoding="SJIS"
       docencoding="iso-2022-jp"
       locale="ja"
       destdir="${SG.javadoc.dstdir}">
       <fileset dir="${SG.src.basedir}/base"/>
       <fileset dir="${SG.src.basedir}/data"/>
       <fileset dir="${SG.src.basedir}/figure"/>
       <fileset dir="${SG.src.basedir}/figure/java2d"/>
       <fileset dir="${SG.src.basedir}/application"/>
    </javadoc>
  </target>

  <!-- JavaDoc creation -->
  <target name="srcdst">
    <mkdir dir="${SG.src.dstdir}"/>
    <copy file="COPYING.txt" todir="${SG.src.dstdir}"/>
    <copy file="LICENSE.txt" todir="${SG.src.dstdir}"/>
    <copy todir="${SG.src.dstdir}/examples">
      <fileset dir="${SG.examplesdir}" excludes="**/CVS*"/>
    </copy>
    <copy todir="${SG.src.dstdir}/examples/data">
      <fileset dir="${SG.examplesdir}" excludes="**/CVS*"/>
    </copy>
  </target>


  <!-- clean -->
  <target name="clean">
    <delete dir="${SG.dstdir}"/>
    <delete dir="${SG.classes}"/>
    <delete dir="${SG.javadoc.dstdir}"/>
    <delete dir="${HP.classes}"/>
    <delete dir="${HP.src.libdir}"/>
    <delete dir="${OSX.classes}"/>
    <delete dir="${OSX.src.libdir}"/>
  </target>

  <!-- run -->
  <target name="run" depends="jar">
    <java fork="true" jar="dist/samurai-graph.jar"/>
  </target>

  <!-- *************** for windows *************** -->
  <!-- compile sources of helper applications -->
  <!-- helper properties -->
  <property name="HP.src.basedir"     value="helper"/>
  <property name="HP.classes"         value="${SG.classes}/helper"/>
  <property name="HP.mfdir"           value="${HP.src.basedir}/META-INF"/>
  <!-- helper jar properties -->
  <property name="HP.src.libdir"              value="${HP.src.basedir}/lib"/>
  <property name="HP.upgrade-helper.mf"       value="${HP.mfdir}/UPGRADE.MF" />
  <property name="HP.upgrade-helper.basedir"  value="${HP.classes}"/>
  <property name="HP.upgrade-helper.jar"      value="${HP.src.libdir}/upgrade-helper.jar"/>
  <target name="windows">
    <!-- create dist directory -->
    <mkdir dir="${HP.classes}"/>
    <mkdir dir="${HP.upgrade-helper.basedir}"/>
    <mkdir dir="${HP.src.libdir}"/>
    <!-- compile sources of helper applications -->
    <javac
       srcdir="${HP.src.basedir}/jp/riken/brain/ni/helper"
       destdir="${HP.upgrade-helper.basedir}"
       encoding="SJIS"
    />
    <!-- create jar file -->
    <jar
     jarfile="${HP.upgrade-helper.jar}"
     basedir="${HP.classes}"
     manifest="${HP.upgrade-helper.mf}"
    />
  </target>

  <!-- *************** for macosx *************** -->
  <!-- maxos x application adapter properties -->
  <property name="OSX.src.basedir"     value="macosx"/>
  <property name="OSX.classes"         value="${SG.classes}/macosx"/>
  <!-- maxos x application adapter jar properties -->
  <property name="OSX.src.libdir"            value="${OSX.src.basedir}/lib"/>
  <property name="OSX.macosx-adapter.basedir"  value="${OSX.classes}"/>
  <property name="OSX.macosx-adapter.jar"      value="${OSX.src.libdir}/macosx-adapter.jar"/>
  <!-- maxos x depending jar -->
  <path id="OSX.classpath">
    <pathelement path="${classpath}"/>
    <fileset dir="${SG.dstdir}">
      <include name="samurai-graph.jar"/>
    </fileset>
  </path>

  <target name="macosx" depends="jar">
    <!-- create dist directory -->
    <mkdir dir="${OSX.classes}"/>
    <mkdir dir="${OSX.macosx-adapter.basedir}"/>
    <mkdir dir="${OSX.src.libdir}"/>
    <!-- compile sources of macosx application adapter -->
    <javac
       srcdir="${OSX.src.basedir}/jp/riken/brain/ni/samuraigraph/platform/macosx"
       destdir="${OSX.macosx-adapter.basedir}"
       classpathref="OSX.classpath"
       encoding="SJIS"
    />
    <!-- create jar file -->
    <jar
     jarfile="${OSX.macosx-adapter.jar}"
     basedir="${OSX.classes}"
    />
  </target>

</project>
