<?xml version="1.0"?>
<project name="Sample" basedir="." default="all">
    <target name="init">
        <property name="unit_name" value="sample"/>
        <property file="./build.properties"/>
        
        <property name="BuildDir" value="./build"/>
        <property name="LibDir" value="./lib"/>
        <property name="ClassDir" value="./build/classes"/>
        <property name="JavaDocDir" value="./docs/apidoc"/>
        <property name="JarDir" value="./build/dist"/>
        
        <property name="SourceDir" value="./src"/>
        <property name="TestDir" value="./test"/>

        <!-- Bump the build number before each build. -->        
        <propertyfile file="./build.properties">
            <entry key="build.number" type="int" operation="+" value="1" 
	     pattern="00"/>
        </propertyfile>

        <!-- Create the directories where we put all the build products. -->        
        <mkdir dir="${BuildDir}"/>
        <mkdir dir="${ClassDir}"/>
        <mkdir dir="${JarDir}"/>
        <mkdir dir="${JavaDocDir}"/>

        <echo message="Build ${build.number}"/>
    </target>

    <target name="compile" depends="init">
        <javac srcdir="${SourceDir}" destdir="${ClassDir}" debug="true" 
	 deprecation="true">
            <classpath>
                <fileset dir="${LibDir}"/>
            </classpath>
        </javac>

        <!-- Copy files needed to run the software to destinations in the 
         build directory. I do this because I usually pull all binary files like
         this from inside the Jar files that make up my application rather than
         having them loose. So they need to be copied to the class dir so they
         get included in the Jar file for the application. -->
        <copy todir="${ClassDir}" >
            <fileset dir="${SourceDir}">
                <include name="**/*.gif"/>
                <include name="**/*.jpg"/>
                <include name="**/*.png"/>
                <include name="**/*.wav"/>
                <include name="**/*.dtd"/>
            </fileset>
        </copy>
    </target>

    <target name="jar" depends="init,compile">
        <jar jarfile="${JarDir}/${unit_name}.jar" compress="true" 
	 basedir="${ClassDir}"/>
    </target>

    <target name="all" depends="jar" description="Build everything.">
        <echo message="Application built."/>
    </target>

    <target name="javadoc" depends="init" description="Javadoc for the code.">
        <javadoc packagenames="*" sourcepath="${SourceDir}" 
	 destdir="${JavaDocDir}"/>
    </target>

    <target name="clean" depends="init" description="Clean all build products.">
        <delete dir="${BuildDir}"/>
    </target>
</project>
