<?xml version="1.0"?>
<project name="tema" default="dist" basedir=".">
    
    <property name="version"  value="0.3"/>
    
    <property name="src"      value="src"/>
    <property name="build"    value="build"/>
    <property name="dist"     value="dist"/>
    <property name="res"      value="res"/>
    <property name="doc"      value="doc"/>
    <property name="lib"      value="${dist}/lib"/>
    <property name="jar_file" value="tema.jar"/>
    
    <property name="ant_jar" value="/usr/share/java/ant.jar"/>
    
    <path id="project.libs">
        <fileset dir="${lib}">
            <include name="**/*.jar"/>
        </fileset>
    </path>
    
    <target name="init">
        <tstamp/>
        <mkdir dir="${build}"/>
    </target>
    
    <target name="compile" depends="init">
        <javac srcdir="${src}" destdir="${build}"
               deprecation="on" optimize="on" debug="on">
            <compilerarg value="-Xlint:unchecked"/>
            <classpath refid="project.libs"/>
        </javac>
        
        <copy todir="${build}">
            <fileset dir="${res}"/>
        </copy>
    </target>
    
    <target name="dist" depends="compile">
        <jar jarfile="${dist}/${jar_file}" manifest="${src}/Manifest.mf">
            <fileset dir="${build}" includes="**/*.class"/>
            <fileset dir="${build}" includes="**/*.template"/>
        </jar>
    </target>
      
    <target name="run" depends="compile">
        <java classname="kryshen.tema.Tema" fork="true">
            <classpath>
                <pathelement location="${build}"/>
                <path refid="project.libs"/>
            </classpath>
        </java>
    </target>
    
    <target name="run.demo" depends="compile">
        <java classname="kryshen.tema.Tema" fork="true">
            <classpath>
                <pathelement location="${build}"/>
                <path refid="project.libs"/>
            </classpath>
            <arg value="-demo"/>
        </java>        
    </target>
    
    <target name="doc.manual" depends="dist">
        <taskdef name="tema"
                 classname="kryshen.tema.ant.TemaTask"
                 classpath="${dist}/tema.jar"/>
                 
        <tema infile="${doc}/manual/manual.tema"
              outfile="${doc}/manual/manual.html"
              basedir="${doc}/manual"/>
    </target>

    <target name="doc.api" depends="init">
        <javadoc destdir="${doc}/api" sourcepath="${src}"
                 packagenames="kryshen.tema.*">
            <classpath> 
                <path refid="project.libs"/>
                <pathelement location="${ant_jar}"/>
            </classpath>
        </javadoc>
    </target>
    
    <target name="package.tar" depends="dist,doc.manual,doc.api">
        <tar destfile="${dist}/${ant.project.name}-${version}.tar.gz"
             compression="gzip">
            <tarfileset dir="${basedir}"
                        prefix="${ant.project.name}-${version}">
                <exclude name="${build}/**"/>
                <exclude name="misc/**"/>
                <exclude name="test/**"/>
                <exclude name="nbproject/**"/>
                <exclude name="${dist}/${ant.project.name}-*.tar.gz"/>
                <exclude name="${dist}/tema"/>
            </tarfileset>
            <tarfileset dir="${basedir}"
                        prefix="${ant.project.name}-${version}"
                        mode="755">
                <include name="${dist}/tema"/>
            </tarfileset>
        </tar>
    </target>
    
    <target name="clean" depends="init">
        <delete>
            <fileset dir="${build}" includes="**/*.class"/>
        </delete>
        <delete file="${dist}/${jar_file}"/>
        <delete dir="${doc}/api"/>
    </target>
    
</project>