<?xml version="1.0"?>

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

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

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

  <path id="libs-build-classpath">
    <fileset dir="../../lib">
      <include name="*.jar"/>
    </fileset>
    <fileset dir="../../build">
      <include name="fop.jar"/>
    </fileset>
    <fileset dir="lib">
      <include name="*.jar"/>
    </fileset>
  </path>

  <!-- =================================================================== -->
  <!-- Initialization target                                               -->
  <!-- =================================================================== -->
  <target name="init">
    <tstamp/>
    <property name="Name" value="MathML-FOP"/>
    <property name="name" value="mathml-fop"/>
    <property name="version" value="0.1-CVS"/>
    <filter  token="version" value="${version}"/>
    <property name="year" value="2002"/>

    <echo message="------------------- ${Name} ${version} [${year}] ----------------"/>

    <property name="build.compiler" value="classic"/>
    <property name="debug" value="on"/>
    <property name="optimize" value="off"/>
    <property name="deprecation" value="on"/>

    <property name="src.dir" value="./src"/>
    <property name="lib.dir" value="./lib"/>
    <property name="packages" value="org.apache.fop.*"/>

    <property name="build.dir" value="./build"/>
    <property name="build.src" value="./build/src"/>
    <property name="build.dest" value="./build/classes"/>

    <property name="resource.dir" value="resources"/>
    <property name="mathml.dir" value="org/apache/fop/mathml"/>

    <available property="jeuclid.present" classname="net.sourceforge.jeuclid.MathBase" classpathref="libs-build-classpath"/>
  </target>
  <target name="jeuclid-check" depends="init" unless="jeuclid.present">
    <echo message="============================================================================="/>
    <echo message="jeuclid.jar is missing in the lib directory."/>
    <echo message="You can download it at: http://sourceforge.net/projects/jeuclid/"/>
    <echo message="============================================================================="/>
    <fail message="Dependecy check failed."/>
  </target>

  <!-- =================================================================== -->
  <!-- Help on usage                                                       -->
  <!-- =================================================================== -->
  <target name="usage">
    <echo message="Use the -projecthelp option instead"/>
  </target>

  <!-- =================================================================== -->
  <!-- Prepares the build directory                                        -->
  <!-- =================================================================== -->
  <target name="prepare" depends="init, jeuclid-check">
    <!-- create directories -->
    <echo message="Preparing the build directories"/>
    <mkdir dir="${build.dir}"/>
    <mkdir dir="${build.src}"/>
    <mkdir dir="${build.src}/${mathml.dir}"/>
  </target>

  <!-- =================================================================== -->
  <!-- Prepares the source code                                            -->
  <!-- =================================================================== -->
  <target name="prepare-src" depends="prepare">
    <!-- copy src files -->
    <copy todir="${build.src}">
      <fileset dir="${src.dir}"
         excludes="**/Makefile*, **/package.html"/>
    </copy>
    <copy todir="${build.dest}/">
      <fileset dir="${resource.dir}"/>
    </copy>
  </target>

  <!-- =================================================================== -->
  <!-- Compiles the source directory                                       -->
  <!-- =================================================================== -->
  <target name="compile" depends="prepare-src" description="Compile the Java sources">
    <echo message="Compiling the sources "/>
    <!-- create directories -->
    <mkdir dir="${build.dest}"/>

    <javac srcdir="${build.src}"
           destdir="${build.dest}"
           debug="${debug}"
           deprecation="${deprecation}"
           optimize="${optimize}"
           excludes="">
      <classpath refid="libs-build-classpath"/>
    </javac>
  </target>

  <!-- =================================================================== -->
  <!-- Creates the class package                                           -->
  <!-- =================================================================== -->
  <target name="package" depends="compile" description="Create jar file">
    <echo message="Creating the jar file ${build.dir}/${name}.jar"/>
    <tstamp>
      <format property="ts" pattern="yyyyMMdd-HHmmss-z"/>
    </tstamp>

    <jar jarfile="${build.dir}/${name}.jar"
         basedir="${build.dest}"
         includes="**">
    <manifest>
        <attribute name="Implementation-Title" value="${Name}"/>
        <attribute name="Implementation-Version" value="${version}"/>
        <attribute name="Implementation-Vendor" value="Apache Software Foundation (http://xml.apache.org/fop/)"/>
        <attribute name="Build-Id" value="${ts} (${user.name} [${os.name} ${os.version} ${os.arch}])"/>
    </manifest>
    </jar>
  </target>

  <!-- =================================================================== -->
  <!-- Clean targets                                                       -->
  <!-- =================================================================== -->
  <target name="clean" depends="init" description="Cleans the build directory">
    <delete dir="${build.dir}"/>
  </target>

</project>