<?xml version="1.0"?>

<project name="Antidote" default="main" basedir=".">

  <!-- Give user a chance to override without editing this file 
       (and without typing -D each time it compiles it) -->
  <property file="${user.home}/.ant.properties" />

  <property name="Name" value="Antidote"/>
  <property name="name" value="antidote"/>
  <property name="version" value="0.1"/>

  <property name="ant.home" value="../../"/>
  <property name="src.bin.dir" value="bin"/>
  <property name="src.etc.dir" value="etc"/>
  <property name="src.dir" value="."/>
  <property name="docs.dir" value="docs"/>
  <property name="build.dir" value="../../../build/antidote"/>
  <property name="ant.build.dir" value="../../../build/ant"/>
  <property name="lib.dir" value="${ant.build.dir}/lib"/>
  <property name="bin.dir" value="${ant.build.dir}/bin"/>
  <property name="build.classes" value="${build.dir}/classes"/>
  <property name="build.javadocs" value="${build.dir}/javadocs"/>
  <property name="ant.dist.dir" value="../../../dist/ant"/>

  <path id="classpath">
    <pathelement location="${lib.dir}/ant.jar"/>
  </path>
  <property name="packages" value="org.apache.tools.ant.gui.*"/>
  <property name="manifest" value="etc/manifest"/>

  <!-- =================================================================== -->
  <!-- Set some the defaults the user can override in .ant.properties      -->
  <!-- =================================================================== -->
  <property name="build.compiler" value="modern"/>
  <property name="build.compiler.emacs" value="on"/>

  <!-- =================================================================== -->
  <!-- Define a global set of patterns that can be referenced by           -->
  <!-- its id attribute                                                    -->
  <!-- =================================================================== -->
  <patternset id="chmod.patterns">
    <include name="**/antidote" />
  </patternset>

  <!-- =================================================================== -->
  <!-- Prepares the build directory                                        -->
  <!-- =================================================================== -->
  <target name="prepare">
    <mkdir dir="${build.dir}"/>
    <mkdir dir="${ant.build.dir}"/>
    <tstamp />
  </target>

  <!-- =================================================================== -->
  <!-- Compiles the source code                                            -->
  <!-- =================================================================== -->
  <target name="compile" depends="prepare">
    <mkdir dir="${build.classes}"/>

    <javac srcdir="${src.dir}"
           destdir="${build.classes}"
           debug="on"
           deprecation="on"
           optimize="off" >
      <classpath refid="classpath" />
    </javac>
 
    <copy todir="${build.classes}">
      <fileset dir="${src.dir}">
        <include name="**/*.properties" />
        <include name="**/*.gif" />
      </fileset>
    </copy>

    <filter token="VERSION" value="${version}" />
    <filter token="DATE" value="${TODAY}" />
    <filter token="TIME" value="${TSTAMP}" />
    <copy    todir="${build.classes}" 
             overwrite="true"
             filtering="on">
      <fileset dir="${src.dir}">
        <include name="**/version.txt" />
      </fileset>
    </copy>
  </target>

  <!-- =================================================================== -->
  <!-- Creates the jar archive                                             -->
  <!-- =================================================================== -->
  <target name="jar" depends="compile">
    <mkdir dir="${lib.dir}"/>
    <jar jarfile="${lib.dir}/${name}.jar"
         basedir="${build.classes}"
         includes="org/**"
         manifest="${manifest}"
    />
  </target>

  <!-- =================================================================== -->
  <!-- Creates the binary structure                                        -->
  <!-- =================================================================== -->
  <target name="main" depends="jar" description="Creates the binary structure">
     <mkdir dir="${bin.dir}"/>
     <copy todir="${bin.dir}">
       <fileset dir="${src.bin.dir}"/>
     </copy>
     <chmod perm="+x">
       <fileset dir="${bin.dir}">
         <patternset refid="chmod.patterns"/>
       </fileset>
     </chmod>
     <fixcrlf srcdir="${bin.dir}" includes="antidote" cr="remove"/>
     <fixcrlf srcdir="${bin.dir}" includes="*.bat" cr="add"/>
  </target>

  <!-- =================================================================== -->
  <!-- Creates the API documentation                                       -->
  <!-- =================================================================== -->
  <target name="javadocs" depends="prepare" description="Creates the API documentation">
    <mkdir dir="${build.javadocs}"/>
    <javadoc packagenames="${packages}"
             sourcepath="${basedir}/${src.dir}"
             destdir="${build.javadocs}"
             author="true"
             private="true"
             version="true"
             windowtitle="${Name} API"
             doctitle="${Name}"
             bottom="Copyright &#169; 2000 Apache Software Foundation. All Rights Reserved.">
      <group title="Antidote" packages="org.apache.tools.ant.gui*" />
    </javadoc>
  </target>

  <!-- =================================================================== -->
  <!-- Creates the distribution                                            -->
  <!-- =================================================================== -->
  <target name="dist" depends="main,jar,javadocs" description="Creates the distribution">
     <mkdir dir="${ant.dist.dir}"/>
     <mkdir dir="${ant.dist.dir}/bin"/>
     <mkdir dir="${ant.dist.dir}/lib"/>
     <mkdir dir="${ant.dist.dir}/docs"/>
     <mkdir dir="${ant.dist.dir}/docs/api"/>
     <mkdir dir="${ant.dist.dir}/src"/>

     <copy todir="${ant.dist.dir}/src">
       <fileset dir="${src.dir}"/>
     </copy>
     <copy todir="${ant.dist.dir}/lib">
       <fileset dir="${lib.dir}"/>
     </copy>

     <copy todir="${ant.dist.dir}/bin">
       <fileset dir="bin"/>
     </copy>
     <copy todir="${ant.dist.dir}/docs">
       <fileset dir="${docs.dir}"/>
     </copy>
     <copy todir="${ant.dist.dir}/docs/api">
       <fileset dir="${build.javadocs}"/>
     </copy>

     <fixcrlf srcdir="${ant.dist.dir}/bin" includes="antidote" cr="remove"/>
     <fixcrlf srcdir="${ant.dist.dir}/bin" includes="*.bat" cr="add"/>
     <chmod perm="+x">
       <fileset dir="${ant.dist.dir}/bin">
         <patternset refid="chmod.patterns"/>
       </fileset>
     </chmod>

     <copy file="README" tofile="${ant.dist.dir}/README"/>
     <copy file="WHATSNEW" tofile="${ant.dist.dir}/WHATSNEW"/>
     <copy file="TODO" tofile="${ant.dist.dir}/TODO"/>
     <copy file="LICENSE" tofile="${ant.dist.dir}/LICENSE"/>
  </target>

  <!-- =================================================================== -->
  <!-- Packages the distribution with ZIP                                  -->
  <!-- =================================================================== -->
  <target name="dist-zip" depends="dist">
    <zip zipfile="${Name}-${version}.zip" basedir="${ant.dist.dir}" includes="**"/>
  </target>

  <!-- =================================================================== -->
  <!-- Packages the distribution with TAR-GZIP                             -->
  <!-- =================================================================== -->
  <target name="dist-tgz" depends="dist">
    <tar tarfile="${Name}-${version}.tar" basedir="${ant.dist.dir}" includes="**"/>
    <gzip zipfile="${Name}-${version}.tar.gz" src="${Name}-${version}.tar"/>
  </target>

  <!-- =================================================================== -->
  <!-- Cleans up generated stuff                                           -->
  <!-- =================================================================== -->
  <target name="clean">
    <delete dir="${build.dir}"/>
    <delete dir="${ant.dist.dir}"/>
  </target>

  <!-- =================================================================== -->
  <!-- Total cleanup                                                       -->
  <!-- =================================================================== -->
  <target name="total-clean" depends="clean">
    <delete dir="${bin.dir}"/>
    <delete file="${lib.dir}/${name}.jar"/>
    <delete file="${Name}-${version}.zip"/>
    <delete file="${Name}-${version}.tar"/>
    <delete file="${Name}-${version}.tar.gz"/>
  </target>


</project>

