<?xml version="1.0" encoding="UTF-8"?>
<project name="BeagleSequenceSimulator" default="help" basedir=".">

   <property name="build.sysclasspath" value="last" />
   <property name="Main-Class" value="dr.app.bss.BeagleSequenceSimulatorApp" />
   <property name="JDK_VERSION" value="1.6" />
   <property name="src" location="src"/>
   <property name="build" location="build" />
   <property name="dist" location="dist" />
   <property name="lib" location="lib" />


   <target name="help">
      <echo message="Common build targets:" />
      <echo message="jar - Builds buss.jar" />
      <echo message="build - Same as clean+jar" />
      <echo message="compile - Compiles buss classes" />
      <echo message="clean - Remove all *.class and buss.jar" />
   </target>


    <path id="classpath">
        <fileset dir="${lib}" includes="**/*.jar"/>
    </path>


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


   <target name="jar" depends="compile">
      <mkdir dir="${dist}" />

      <jar jarfile="${dist}/buss.jar">

         <manifest>
            <attribute name="Built-By" value="${user.name}" />
            <attribute name="Main-Class" value="${Main-Class}" />
         </manifest>

         <fileset dir="${build}">
            <include name="dr/app/bss/**/*.class" />
            <include name="dr/inference/model/**/*.class" />
            <include name="dr/inference/loggers/**/*.class" />
            <include name="dr/inference/distribution/**/*.class" />
            <include name="dr/evomodel/branchratemodel/**/*.class" />
             <include name="dr/evomodel/substmodel/**/*.class" />
            <include name="dr/app/beagle/evomodel/substmodel/**/*.class" />
            <include name="dr/app/beagle/evomodel/branchmodel/**/*.class" />
            <include name="dr/inference/parallel/**/*.class**" />
            <include name="dr/app/beagle/evomodel/sitemodel/**/*.class" />
            <include name="dr/app/beauti/options/**/*.class" />
            <include name="dr/app/beauti/tipdatepanel/**/*.class" />
            <include name="dr/app/gui/table/**/*.class" />
            <include name="dr/app/gui/components/**/*.class" />
            <include name="dr/app/beauti/util/**/*.class" />
            <include name="dr/evomodel/tree/**/*.class" />
            <include name="dr/app/beagle/tools/**/*.class" />
            <include name="dr/app/beagle/evomodel/treelikelihood/**/*.class" />
            <include name="dr/app/beagle/evomodel/treelikelihood/**/*.class" />
            <include name="dr/app/util/**/*.class" />
            <include name="dr/evolution/alignment/**/*.class" />
            <include name="dr/evolution/coalescent/**/*.class" />
            <include name="dr/evolution/colouring/**/*.class" />
            <include name="dr/evolution/datatype/**/*.class" />
            <include name="dr/evolution/distance/**/*.class" />
            <include name="dr/evolution/io/**/*.class" />
            <include name="dr/evolution/parsimony/**/*.class" />
            <include name="dr/evolution/sequence/**/*.class" />
            <include name="dr/evolution/tree/**/*.class" />
            <include name="dr/evolution/util/**/*.class" />
            <include name="dr/evoxml/**/*.class" />
            <include name="dr/gui/table/**/*.class" />
            <include name="dr/inference/trace/**/*.class" />
            <include name="dr/math/**/*.class" />
            <include name="dr/matrix/**/*.class" />
            <include name="dr/stats/**/*.class" />
            <include name="dr/util/**/*.class" />
            <include name="dr/xml/**/*.class" />
			<include name="dr/evomodelxml/branchratemodel/**/*.class" />
			<include name="dr/evomodelxml/coalescent/**/*.class" />
			<include name="dr/evomodelxml/sitemodel/**/*.class" />
			<include name="dr/evomodelxml/tree/**/*.class" />
			<include name="dr/app/beagle/tools/parsers/**/*.class" />
			<include name="dr/evolution/io/Importer/**/*.class" />

         </fileset>

         <zipgroupfileset dir="${lib}" includes="jam.jar" />
         <zipgroupfileset dir="${lib}" includes="beagle.jar" />
         <zipgroupfileset dir="${lib}" includes="commons-math-2.2.jar" />

		<fileset dir="${src}">
			<include name="dr/**/*.png"/>
		</fileset>

      </jar>
   </target>


   <target name="compile">
      <mkdir dir="${build}" />

      <javac source="${JDK_VERSION}" target="${JDK_VERSION}" srcdir="${src}" destdir="${build}" classpathref="classpath">

         <include name="dr/app/bss/**" />
         <include name="dr/inference/model/**" />
         <include name="dr/inference/loggers/**" />
          <include name="dr/inference/distribution/**" />
         <include name="dr/evomodel/branchratemodel/**" />
         <include name="dr/evomodel/substmodel/**" />
         <include name="dr/app/beagle/evomodel/substmodel/**" />
         <include name="dr/app/beagle/evomodel/branchmodel/**" />
         <include name="dr/inference/parallel/**" />
         <include name="dr/app/beagle/evomodel/sitemodel/**" />
         <include name="dr/app/beauti/options/**" />
         <include name="dr/app/beauti/tipdatepanel/**" />
         <include name="dr/app/gui/table/**" />
         <include name="dr/app/gui/components/**" />
         <include name="dr/app/beauti/util/**" />
         <include name="dr/evomodel/tree/**" />
         <include name="dr/app/beagle/tools/**" />
         <include name="dr/app/beagle/evomodel/treelikelihood/**" />
         <include name="dr/app/util/**" />
         <include name="dr/evolution/alignment/**" />
         <include name="dr/evolution/colouring/**" />
         <include name="dr/evolution/datatype/**" />
         <include name="dr/evolution/distance/**" />
         <include name="dr/evolution/io/**" />
         <include name="dr/evolution/parsimony/**" />
         <include name="dr/evolution/sequence/**" />
         <include name="dr/evolution/tree/**" />
         <include name="dr/evolution/util/**" />
         <include name="dr/evoxml/**" />
         <include name="dr/gui/table/**" />
         <include name="dr/inference/trace/**" />
         <include name="dr/math/**" />
         <include name="dr/matrix/**" />
         <include name="dr/stats/**" />
         <include name="dr/util/**" />
         <include name="dr/xml/**" />
		 <include name="dr/evomodelxml/branchratemodel/**" />
		 <include name="dr/evomodelxml/coalescent/**" />
		 <include name="dr/evomodelxml/sitemodel/**" />
		 <include name="dr/evomodelxml/tree/**" />
		 <include name="dr/app/beagle/tools/parsers/**" />
		 <include name="dr/evolution/io/Importer/**" />

      </javac>
      <echo message="Successfully compiled." />
   </target>

    <property name="version" value="1.0" />
    <property name="release_dir" value="release_pibuss" />
    <property name="name" value="piBUSS" />

    <property name="common_dir" value="${release_dir}/common" />

    <property name="Mac_dir" value="${release_dir}/Mac" />
    <property name="Linux_dir" value="${release_dir}/Linux" />
    <property name="Windows_dir" value="${release_dir}/Windows" />

    <property name="Mac_package_dir" value="${Mac_dir}/${name} v${version}" />
    <property name="Linux_package_dir" value="${Linux_dir}/${name}_v${version}" />
    <property name="Windows_package_dir" value="${Windows_dir}/${name} v${version}" />

    <!-- Need to either install Launch4j under {BEAST workspace}/${release}
                 or install it in the default directory and change the location of launch4j.dir -->
    <target name="windows" depends="build" description="release Windows version of πBUSS">

        <delete dir="${Windows_package_dir}" />
        <!-- Create the release directory -->
        <mkdir dir="${Windows_package_dir}" />

        <property name="launch4j.dir" location="${Windows_dir}/launch4j" />
        <taskdef name="launch4j" classname="net.sf.launch4j.ant.Launch4jTask"
                 classpath="${launch4j.dir}/launch4j.jar :${launch4j.dir}/lib/xstream.jar" />

        <copy file="${dist}/buss.jar" todir="${Windows_package_dir}/lib"/>
        <copy todir="${Windows_package_dir}/lib">
            <fileset dir="${Windows_dir}/lib"/>
        </copy>
        <copy file="${common_dir}/README.txt" todir="${Windows_package_dir}"/>

        <launch4j configFile="${Windows_dir}/pibuss_launch4j.xml"
                  jar="${dist}/buss.jar"
                  outfile="${Windows_package_dir}/${name} v${version}.exe"
                  fileVersion="${version}.0.0"
                  txtFileVersion="${version}"
                  productVersion="${version}.0.0"
                  txtProductVersion="${version}"/>

        <zip destfile="${release_dir}/${name} v${version}.zip">
            <zipfileset dir="${Windows_package_dir}" prefix="${name} v${version}"/>
        </zip>

        <echo message="Windows version release is finished." />
    </target>

    <target name="linux" depends="build" description="release Linux/Unix version of πBUSS">
        <delete dir="${Linux_package_dir}" />
        <!-- Create the release directory -->
        <mkdir dir="${Linux_package_dir}" />

        <copy todir="${Linux_package_dir}/bin">
            <fileset dir="${Linux_dir}/scripts"/>
        </copy>

        <chmod dir="${Linux_package_dir}/bin" perm="755" includes="**/**"/>

        <copy file="${Linux_dir}/icons/pibuss.png" todir="${Linux_package_dir}/images"/>
        <copy file="${dist}/buss.jar" todir="${Linux_package_dir}/lib"/>
        <copy todir="${Linux_package_dir}/lib">
            <fileset dir="${Linux_dir}/lib"/>
        </copy>
        <copy file="${common_dir}/README.txt" todir="${Linux_package_dir}"/>

        <tar destfile="${release_dir}/${name}_v${version}.tgz" compression="gzip">
            <tarfileset dir="${Linux_package_dir}" prefix="${name}_v${version}"/>
        </tar>

        <echo message="Linux/Unix version release is finished." />
    </target>

    <target name="mac" depends="build" description="release Mac version of πBUSS">
        <delete dir="${Mac_package_dir}" />
        <!-- Create the release directory -->
        <mkdir dir="${Mac_package_dir}" />

        <copy file="${common_dir}/README.txt" todir="${Mac_package_dir}"/>

        <taskdef name="jarbundler" classname="net.sourceforge.jarbundler.JarBundler"/>

        <!-- create a jar bundle for the mac -->
        <jarbundler dir="${Mac_package_dir}"
                    name="${name} v${version}"
                    mainclass="dr.app.bss.BeagleSequenceSimulatorApp"
                    icon="${Mac_dir}/icons/πBUSS.icns"
                    jvmversion="1.6+"
                    arguments=""
                    version="${version}"
                    infostring="${name} v${version}, Copyright 2013, Filip Bielejec, Andrew Rambaut, Philippe Lemey and Marc Suchard"
                    bundleid="pibuss" >
            <javaproperty name="apple.laf.useScreenMenuBar" value="true"/>
            <jarfileset dir="${dist}">
                <include name="**/buss.jar"/>
            </jarfileset>
            <jarfileset dir="${Mac_dir}/lib">
                <include name="**/*.jar"/>
            </jarfileset>
        </jarbundler>

        <echo message="Building disk image." />

        <!-- create disk image -->
        <exec executable="/usr/bin/hdiutil">
            <arg value="create"/>
            <arg value="-ov"/>
            <arg value="-srcfolder"/>
            <arg value="${Mac_package_dir}"/>
            <arg value="-volname"/>
            <arg value="${name} v${version}"/>
            <arg value="-imagekey"/>
            <arg value="zlib-level=6"/>
            <arg value="${release_dir}/${name} v${version}.dmg"/>
        </exec>

        <echo message="Mac version release is finished." />
    </target>


    <target name="clean">
      <delete dir="${build}" />
      <delete dir="${dist}" />
   </target>


</project>
