<project name="leiningen" default="jar">
    <description>
        Pack all leiningen sources into a JAR.
    </description>

    <property name="src"   location="src"/>
    <property name="build" location="classes"/>
    <property name="dist"  location="dist"/>
    <property name="prefix" location="__PREFIX__"/>

    <property name="clojure.jar"
              location="${prefix}/clojure/lib/clojure.jar"/>
    <property name="clojure-contrib.jar"
              location="${prefix}/clojure/lib/clojure-contrib.jar"/>
    <property name="ant.jar"
              location="${prefix}/apache-ant/lib/ant.jar"/>
    <property name="ant-launcher.jar"
              location="${prefix}/apache-ant/lib/ant-launcher.jar"/>
    <property name="maven.jar"
              location="${prefix}/maven2/lib/maven-2.2.1-uber.jar"/>

    <!-- The JAR file to create. -->
    <property name="jarfile" location="leiningen.jar"/>

    <target name="init">
        <tstamp/>
        <mkdir dir="${build}"/>
        <mkdir dir="${dist}"/>
    </target>

    <target name="clean" description="Remove generated files and directories.">
        <delete file="${jarfile}"/>
        <delete dir="${build}"/>
        <delete dir="${dist}"/>
    </target>

    <target name="compile_clojure" depends="init"
            description="Compile Clojure sources.">
        <java classname="clojure.lang.Compile">
            <classpath>
                <path location="${build}"/>
                <path location="${src}"/>
                <path location="${clojure.jar}"/>
                <path location="${clojure-contrib.jar}"/>
                <path location="${ant.jar}"/>
                <path location="${ant-launcher.jar}"/>
                <path location="${maven.jar}"/>
            </classpath>
            <sysproperty key="clojure.compile.path" value="${build}"/>
            <sysproperty key="java.awt.headless" value="true"/>

            <arg value="leiningen.clean"/>
            <arg value="leiningen.compile"/>
            <arg value="leiningen.core"/>
            <arg value="leiningen.deps"/>
            <arg value="leiningen.help"/>
            <arg value="leiningen.install"/>
            <arg value="leiningen.jar"/>
            <arg value="leiningen.pom"/>
            <arg value="leiningen.test"/>
            <arg value="leiningen.uberjar"/>
        </java>
    </target>

    <target name="jar" description="Create jar file."
            depends="init,compile_clojure">
        <jar jarfile="${jarfile}">
            <fileset dir="${src}" includes="**/*.clj"/>
            <fileset dir="${build}" includes="**/*.class"/>
            <manifest>
                <attribute name="Class-Path" value="."/>
            </manifest>
        </jar>
    </target>
</project>
