<?xml version="1.0" encoding="UTF-8"?>

<project basedir="." default="all" name="HFSExplorer">
  <property environment="env"/>
  <property name="debuglevel" value="source,lines,vars"/>
  <condition property="java.target.level" value="1.5">
    <or>
      <equals arg1="${ant.java.version}" arg2="1.5"/>
      <equals arg1="${ant.java.version}" arg2="1.6"/>
      <equals arg1="${ant.java.version}" arg2="1.7"/>
      <equals arg1="${ant.java.version}" arg2="1.8"/>
    </or>
  </condition>
  <property name="java.target.level" value="${ant.java.version}"/>
  <condition property="java.source.level" value="1.5">
    <or>
      <equals arg1="${ant.java.version}" arg2="1.5"/>
      <equals arg1="${ant.java.version}" arg2="1.6"/>
      <equals arg1="${ant.java.version}" arg2="1.7"/>
      <equals arg1="${ant.java.version}" arg2="1.8"/>
    </or>
  </condition>
  <property name="java.source.level" value="${ant.java.version}"/>
  <property name="java.source.dir" value="src/java"/>
  <property name="manifest.source.dir" value="src/META-INF"/>
  <!--<property name="builddir" value=".build~"/>-->
  <property name="builddir" value=".antbuild~"/>
  <!--<property name="java.build.library.dir" value="lib"/>-->
  <property name="java.runtime.library.dir" value="dist/lib"/>
  <!--<property name="manifest.filename" value="${manifest.source.dir}/MANIFEST.MF"/>-->
  <!--<property name="outjar.filename" value="${libdir}/torrenttoolbox.jar"/>-->
  <property name="resources.srcdir" value="resource"/>
  <property name="resources.destdir" value="${builddir}/res"/>
  
  <property name="target.all.jarmanifest" value="${manifest.source.dir}/MANIFEST.MF"/> 
  <property name="target.all.outjarname" value="hfsx.jar"/>
  <property name="target.all.outjar" value="${java.runtime.library.dir}/${target.all.outjarname}"/>
 
  <property name="target.jparted.jarmanifest" value="${manifest.source.dir}/jparted/MANIFEST.MF"/>
  <property name="target.jparted.outjar" value="targets/jparted/lib/jparted.jar"/>

  <property name="target.hfs-jfuse_libhfs.jarmanifest" value="${manifest.source.dir}/hfs-jfuse_libhfs/MANIFEST.MF"/>
  <property name="target.hfs-jfuse_libhfs.outjar" value="targets/hfs-jfuse_libhfs/hfs-jfuse_libhfs.jar"/>
  <property name="target.mkapm.outjar" value="targets/mkapm/mkapm.jar"/>
  <property name="target.mkapm.jarmanifest" value="${manifest.source.dir}/mkapm/MANIFEST.MF"/>
  
  <path id="java.build.classpath">
    <fileset dir="${java.runtime.library.dir}">
      <include name="**/*.jar"/>
      <exclude name="**/${target.all.outjarname}"/>
    </fileset>
    <!--
    <fileset dir="${java.build.library.dir}">
      <include name="**/*.jar"/>
    </fileset>
    -->
  </path>
  
  <path id="javadoc.classpath">
    <path refid="java.build.classpath"/>
  </path>

  
  <target name="all">
    <!-- Ruler (messages start at column 12 because of the leading "     [echo] "        -->
    <!--        10        20        30        40        50        60        70        80 -->
    <!--         |         |         |         |         |         |         |         | -->
    <echo message="Current well defined targets:"/>
    <echo message="  build-all     - Compiles all files in all packages and puts the"/>
    <echo message="                  result in dist/lib/hfsx.jar."/>
    <echo message="  build-jparted - Compiles the org.catacombae.jparted package, "/>
    <echo message="                  subpackages and dependencies and puts the result"/>
    <echo message="                  in targets/jparted/lib/jparted.jar."/>
    <echo message="  build-hfs-jfuse_libhfs -"/>
    <echo message="                  Builds hfs-jfuse_libhfs, which is used by"/>
    <echo message="                  hfs-jfuse."/>
    <echo message="  build-mkapm   - Builds mkapm, a utility for creating Apple"/>
    <echo message="                  Partition Map layouts."/>
    <echo message="  build-csframework -"/>
    <echo message="                  Builds csframework.jar from external/"/>
    <echo message="                  catacombaeframework and copies the result to dist/"/>
    <echo message="                  lib/csframework.jar."/>
    <echo message="  build-hfsx_dmglib -"/>
    <echo message="                  Builds hfsx_dmglib.jar from external/"/>
    <echo message="                  dmgextractor and copies the result to dist/"/>
    <echo message="                  lib/hfsx_dmglib.jar."/>
    <echo message="  javadoc       - Creates the javadoc documentation for the"/>
    <echo message="                  project."/>
    <echo message="  javadoc-internal -"/>
    <echo message="                  Creates the javadoc documentation for the project"/>
    <echo message="                  including internal class members (private and"/>
    <echo message="                  package-private)."/>
  </target>
  
  
  <target name="init">
    <mkdir dir="${builddir}"/>
  </target>
  
  <target name="clean">
    <mkdir dir="${builddir}"/>
    <delete dir="${builddir}"/>
  </target>
  
  <target name="build-all" depends="clean,jar-all"/>
  
  <target name="copyresources-all" depends="init">
    <copy todir="${resources.destdir}">
      <fileset dir="${resources.srcdir}" includes="*.png"/>
    </copy>
  </target>
  
  <target name="compile-all" depends="init">
    <javac srcdir="${java.source.dir}"
	   destdir="${builddir}"
	   includes="**"
	   debug="true"
	   debuglevel="${debuglevel}"
	   encoding="utf-8"
	   source="${java.source.level}"
	   target="${java.target.level}"
	   deprecation="on">
      <compilerarg value="-Xlint:unchecked"/>
      <classpath refid="java.build.classpath"/>
    </javac>
  </target>
  
  <target name="jar-all" depends="copyresources-all,compile-all">
    <jar destfile="${target.all.outjar}" basedir="${builddir}" manifest="${target.all.jarmanifest}"/>
  </target>
  
  <target name="compile-hfsexplorer" depends="init">
    <javac srcdir="${java.source.dir}"
	   destdir="${builddir}"
	   includes="org/catacombae/hfsexplorer/**"
	   debug="true"
	   debuglevel="${debuglevel}"
	   encoding="utf-8"
	   source="${java.source.level}"
	   target="${java.target.level}">
      <classpath refid="java.build.classpath"/>
    </javac>
  </target>
  
  <target name="build-jparted" depends="clean,jar-jparted"/>
  
  <target name="compile-jparted" depends="init">
    <javac srcdir="${java.source.dir}"
	   destdir="${builddir}"
	   includes="org/catacombae/jparted/**"
	   debug="true"
	   debuglevel="${debuglevel}"
	   encoding="utf-8"
	   source="${java.source.level}"
	   target="${java.target.level}">
      <classpath refid="java.build.classpath"/>
    </javac>
  </target>
  
  <target name="jar-jparted" depends="compile-jparted">
    <jar destfile="${target.jparted.outjar}" basedir="${builddir}" manifest="${target.jparted.jarmanifest}"/>
  </target>

  <target name="build-hfs-jfuse_libhfs" depends="clean,jar-hfs-jfuse_libhfs"/>

  <target name="compile-hfs-jfuse_libhfs" depends="init">
    <javac srcdir="${java.source.dir}"
	   destdir="${builddir}"
	   debug="true"
	   debuglevel="${debuglevel}"
	   encoding="utf-8"
	   source="${java.source.level}"
	   target="${java.target.level}">
      <!-- All entry points to the HFSExplorer libraries from hfs-jfuse should be listed here. -->
      <include name="org/catacombae/storage/fs/FSAttributes.java"/>
      <include name="org/catacombae/storage/fs/FSEntry.java"/>
      <include name="org/catacombae/storage/fs/FSFile.java"/>
      <include name="org/catacombae/storage/fs/FSFolder.java"/>
      <include name="org/catacombae/storage/fs/FSFork.java"/>
      <include name="org/catacombae/storage/fs/FSLink.java"/>
      <include name="org/catacombae/storage/fs/FileSystemHandler.java"/>
      <include name="org/catacombae/storage/io/DataLocator.java.java"/>
      <include name="org/catacombae/storage/io/RandomAccessFileDataLocator.java"/>
      <include name="org/catacombae/storage/fs/FileSystemCapability.java"/>
      <include name="org/catacombae/storage/fs/FileSystemHandler.java"/>
      <include name="org/catacombae/storage/fs/FileSystemHandlerFactory.java"/>
      <include name="org/catacombae/storage/fs/hfs/HFSFileSystemHandlerFactory.java"/>
      <include name="org/catacombae/storage/fs/hfsplus/HFSPlusFileSystemHandlerFactory.java"/>
      <include name="org/catacombae/storage/fs/hfsx/HFSXFileSystemHandlerFactory.java"/>
      <classpath refid="java.build.classpath"/>
    </javac>
  </target>

  <target name="jar-hfs-jfuse_libhfs" depends="compile-hfs-jfuse_libhfs">
    <jar destfile="${target.hfs-jfuse_libhfs.outjar}" basedir="${builddir}" manifest="${target.hfs-jfuse_libhfs.jarmanifest}"/>
  </target>

  <target name="build-mkapm" depends="clean,jar-mkapm"/>

  <target name="compile-mkapm" depends="init">
    <javac destdir="${builddir}"
	   includes="org/catacombae/hfsexplorer/tools/MkAPM.java"
	   debug="true"
	   debuglevel="${debuglevel}"
	   encoding="utf-8"
	   source="${java.source.level}"
	   target="${java.target.level}">
      <src path="${java.source.dir}"/>
      <classpath refid="java.build.classpath"/>
    </javac>
  </target>

  <target name="jar-mkapm" depends="compile-mkapm">
    <jar destfile="${target.mkapm.outjar}" basedir="${builddir}" manifest="${target.mkapm.jarmanifest}"/>
  </target>

  <target name="build-csframework">
    <ant antfile="build.xml"
         dir="external/catacombaeframework"
         inheritAll="false"/>
    <copy file="external/catacombaeframework/targets/base/csframework.jar"
          todir="${java.runtime.library.dir}"
          overwrite="true"/>
  </target>

  <target name="build-hfsx_dmglib">
    <copy file="${java.runtime.library.dir}/csframework.jar"
          todir="external/dmgextractor/targets/application/lib"
          overwrite="true"/>
    <ant antfile="build.xml"
         dir="external/dmgextractor"
         inheritAll="false">
      <target name="build-hfsxlib"/>
    </ant>
    <copy file="external/dmgextractor/targets/hfsxlib/hfsx_dmglib.jar"
          todir="${java.runtime.library.dir}"
          overwrite="true"/>
  </target>

  <target name="javadoc">
    <javadoc destdir="javadoc.~"
             packagenames="org.catacombae.*"
             sourcepath="${java.source.dir}"
             access="protected"
             author="true"
             version="true"
             use="true"
             encoding="utf-8"
             windowtitle="HFSExplorer API">
      <link href="http://java.sun.com/j2se/1.5.0/docs/api/"/>
      <link href="../../catacombaeframework/javadoc.~/"/>
      <classpath>
        <path refid="javadoc.classpath"/>
      </classpath>
    </javadoc>
  </target>

  <target name="javadoc-internal">
    <javadoc destdir="javadoc-internal.~"
             packagenames="org.catacombae.*"
             sourcepath="${java.source.dir}"
             access="private"
             author="true"
             version="true"
             use="true"
             encoding="utf-8"
             windowtitle="HFSExplorer Internal API">
      <link href="http://java.sun.com/j2se/1.5.0/docs/api/"/>
      <link href="../../catacombaeframework/javadoc.~/"/>
      <classpath>
        <path refid="javadoc.classpath"/>
      </classpath>
    </javadoc>
  </target>
</project>
