<?xml version="1.0"?>

<!--
==============================================================================

 Ant build file

Authors:
 Peter Donald <donaldp@apache.org>

Legal:
  Copyright (c) 2000 The Apache Software Foundation. All Rights Reserved.

==============================================================================
-->

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

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

  <property name="name" value="ant"/>
  <property name="Name" value="Ant"/>
  <property name="version" value="0.01-myrmidon"/>
  <property name="year" value="2000"/>

  <!-- 
    these are here only for those who use jikes compiler. For other 
    developers this part makes no difference.
  -->
  <property name="build.compiler.emacs" value="on"/>
  <property name="build.compiler.warnings" value="true"/>
  <property name="build.compiler.pedantic" value="true"/>
  <property name="build.compiler.depend" value="true"/>
  <property name="build.compiler.fulldepend" value="true"/>

  <property name="debug" value="on"/>
  <property name="optimize" value="off"/>
  <property name="deprecation" value="on"/>

  <property name="build.dir" value="build"/>
  <property name="build.lib" value="${build.dir}/lib"/>
  <property name="build.src" value="${build.dir}/src"/>
  <property name="build.classes" value="${build.dir}/classes"/>

  <property name="src.base" value="src"/>
  <property name="manifest.dir" value="${src.base}/manifest"/>
  <property name="java.dir" value="${src.base}/java"/>
  <property name="script.dir" value="${src.base}/script"/>
  <property name="lib.dir" value="lib"/>

  <property name="dist.name" value="${Name}-${version}"/>
  <property name="dist.dir" value="dist"/>
  <property name="dist.bin" value="${dist.dir}/bin"/>
  <property name="dist.lib" value="${dist.dir}/lib"/>
  <property name="dist.ext" value="${dist.dir}/ext"/>

  <property name="constants.file" value="org/apache/myrmidon/Constants.java"/>

  <path id="project.class.path">
    <pathelement path="${java.class.path}" />
    <fileset dir="${lib.dir}">
      <include name="*.jar" />
    </fileset>
    <pathelement path="${build.classes}" />
  </path>

  <!-- Main target -->
  <target name="main" depends="dist" />
 
  <!-- Compiles the source code -->
  <target name="compile">

    <tstamp/>
    <mkdir dir="${build.src}"/>
    <copy file="${java.dir}/${constants.file}" tofile="${build.src}/${constants.file}"/>
    <replace file="${build.src}/${constants.file}" token="@@VERSION@@" value="${version}" />
    <replace file="${build.src}/${constants.file}" token="@@DATE@@" value="${TODAY}" />

    <mkdir dir="${build.classes}"/>
    <javac srcdir="${java.dir}"
           destdir="${build.classes}"
           debug="${debug}"
           optimize="${optimize}"
           deprecation="${deprecation}">
        <classpath refid="project.class.path"/>        
        <exclude name="org/apache/ant/gui/**"/>
        <exclude name="${constants.file}"/>
        <src path="${build.src}" />
    </javac>

  </target>

  <!-- Creates the jars file -->
  <target name="jars" depends="compile">

    <mkdir dir="${build.lib}"/>

    <jar jarfile="${build.lib}/ant.jar" 
         basedir="${build.classes}" 
         manifest="${manifest.dir}/ant-manifest.mf">
      <include name="org/apache/myrmidon/launcher/*" />
    </jar>

    <jar jarfile="${build.lib}/myrmidon.jar" 
         basedir="${build.classes}" 
         manifest="${manifest.dir}/myrmidon-manifest.mf">
      <include name="org/apache/**" />
      <exclude name="org/apache/myrmidon/launcher/*" />
      <exclude name="org/apache/myrmidon/libs/*" />
      <exclude name="org/apache/ant/**" />

      <zipfileset dir="${manifest.dir}" fullpath="META-INF/ant-roles.xml">
        <include name="builtin-ant-roles.xml"/>
      </zipfileset>

      <zipfileset dir="${manifest.dir}" fullpath="META-INF/ant-descriptor.xml">
        <include name="builtin-ant-descriptor.xml"/>
      </zipfileset>

    </jar>

    <jar jarfile="${build.lib}/core.atl" basedir="${build.classes}">
      <include name="org/apache/ant/modules/**" />
      <include name="org/apache/myrmidon/libs/core/**" />
      <zipfileset dir="${manifest.dir}" fullpath="META-INF/ant-descriptor.xml">
        <include name="core-ant-descriptor.xml"/>
      </zipfileset>
    </jar>

    <jar jarfile="${build.lib}/selftest.atl" basedir="${build.classes}">
      <include name="org/apache/myrmidon/libs/selftest/**" />
      <zipfileset dir="${manifest.dir}" fullpath="META-INF/ant-descriptor.xml">
        <include name="selftest-ant-descriptor.xml"/>
      </zipfileset>
    </jar>

    <jar jarfile="${build.lib}/runtime.atl" basedir="${build.classes}">
      <include name="org/apache/myrmidon/libs/runtime/**"/>
      <zipfileset dir="${manifest.dir}" fullpath="META-INF/ant-descriptor.xml">
        <include name="runtime-ant-descriptor.xml"/>
      </zipfileset>
    </jar>

    <jar jarfile="${build.lib}/ant1.atl" basedir="${build.classes}">
      <include name="org/apache/myrmidon/libs/ant1/**"/>
      <zipfileset dir="${manifest.dir}" fullpath="META-INF/ant-descriptor.xml">
        <include name="ant1-ant-descriptor.xml"/>
      </zipfileset>
    </jar>

  </target>

  <!-- Creates the distribution -->
  <target name="dist" depends="jars">

    <mkdir dir="${dist.bin}"/>
    <mkdir dir="${dist.lib}"/>
    <mkdir dir="${dist.ext}"/>

    <copy file="tools/lib/ant.jar" tofile="${dist.lib}/ant1-compat.jar" />

    <copy todir="${dist.lib}">
      <fileset dir="${build.lib}">
        <exclude name="selftest.atl"/>
      </fileset>
    </copy>

    <copy todir="${dist.ext}">
      <fileset dir="${build.lib}">
        <include name="selftest.atl"/>
      </fileset>
    </copy>

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

    <copy todir="${dist.bin}">
      <fileset dir="${script.dir}"/>
    </copy>

    <chmod dir="${dist.dir}" perm="go-rwx" />
    <chmod file="${dist.bin}/ant" perm="u+x"/>
    <fixcrlf srcdir="${dist.bin}" cr="add" includes="**/*.bat" />
    <fixcrlf srcdir="${dist.bin}" cr="remove" includes="**/*.sh" />
    <fixcrlf srcdir="${dist.bin}" cr="remove" includes="ant" />

  </target>

  <!-- Cleans up build and distribution directories -->
  <target name="clean">
    <delete dir="${build.dir}"/>
    <delete dir="${dist.dir}"/>
    <delete>
      <fileset dir="." includes="**/*~" defaultexcludes="no"/>
    </delete>
  </target>

</project>
