<?xml version="1.0"?>

<!-- ======================================================= -->
<!-- (c) 2002 tagtraum industries - hs@tagtraum.com          -->
<!-- GCViewer build file for ant >= v1.4                     -->
<!-- $Id: $ -->
<!-- ======================================================= -->

<!-- This could probably look a lot cleaner, but for now -->
<!-- it's ok (rik) -->

<project name="gcviewer" default="all" basedir=".">

	<!-- ===================================================== -->
	<!-- Sets necessary properties                             -->
	<!-- ===================================================== -->
	<target name="init" description="Initializes ant...">
		<property name="manifestdir" value="src/manifests" />
		<property name="srcdir" value="src/java" />
		<property name="destdir" value="classes" />
		<property name="testsrcdir" value="src/unittest" />
		<property name="testdestdir" value="unittest-classes" />
		<property name="gcviewer" value="." />
		<property name="build" value="gcviewer-1.15" />
		<property name="distbase" value="./dist" />
		<property name="dist" value="${distbase}/${build}" />
		<property name="lib" value="lib" />
		<mkdir dir="${destdir}" />
		<mkdir dir="${testdestdir}" />
        <path id="classpath">
            <pathelement location="${lib}/junit.jar"/>
            <pathelement path="${destdir}"/>
            <pathelement path="${testdestdir}"/>
        </path>
	</target>

	<!-- ===================================================== -->
	<!-- Compiles                                              -->
	<!-- ===================================================== -->
	<target name="compile" depends="init" description="Compiles all GCViewer classes and builds gcviewer.jar">
		<javac
			srcdir="${srcdir}"
			destdir="${destdir}"
			includes="com/tagtraum/perf/gcviewer/**"
			optimize="off"
			debug="on"
			deprecation="on"
		>
            	<classpath refid="classpath"/>
		</javac>
		<copy toDir="${destdir}">
			<fileset dir="${srcdir}" includes="com/tagtraum/perf/gcviewer/**/*.gif,com/tagtraum/perf/gcviewer/**/*.properties"/>
		</copy>
		<jar jarfile="gcviewer.jar" manifest="${manifestdir}/gcviewer.mf" basedir="${destdir}"/>

	</target>

	<!-- ===================================================== -->
	<!-- Compiles Test Classes                                 -->
	<!-- ===================================================== -->
	<target name="compile-tests" depends="compile" description="Compiles all test classes and builds gcviewer-test.jar">
		<javac
			srcdir="${testsrcdir}"
			destdir="${testdestdir}"
			includes="com/tagtraum/**"
			optimize="off"
			debug="on"
			deprecation="on"
		>
            	<classpath refid="classpath" />
		</javac>
		<copy toDir="${testdestdir}">
			<fileset dir="${testsrcdir}" includes="com/tagtraum/**/*.gif,com/tagtraum/**/*.properties,com/tagtraum/**/*.txt"/>
		</copy>
		<jar jarfile="gcviewer-test.jar" manifest="${manifestdir}/gcviewer-test.mf" basedir="${testdestdir}"/>
	</target>

	<!-- ===================================================== -->
	<!-- Runs Test Classes                                     -->
	<!-- ===================================================== -->
	<target name="test" depends="compile-tests" description="Runs test classes.">
		<junit printsummary="yes" haltonfailure="yes">
			<classpath refid="classpath"/>
			<test name="com.tagtraum.perf.gcviewer.TestAll" />
		</junit>
	</target>

	<!-- ===================================================== -->
	<!-- builds the distribution file.                         -->
	<!-- DOES NOT COMPILE!!! see target 'all'                  -->
	<!-- ===================================================== -->
	<target name="dist" depends="init" description="Build distribution package, but does not compile!">
		<mkdir dir="${dist}" />
		<!-- copy scripts etc. -->
		<copy toDir="${dist}">
			<fileset dir="${gcviewer}"
				excludes="${testdestdir}/**,${destdir}/**,${distbase}/**,${dist}/**,**/*.psd,**/*.ai"
			/>
		</copy>
		<!-- get rid of a copy of the dist dir -->
		<delete dir="${dist}/dist" />

		<!-- fix for win -->
		<fixcrlf
			srcDir="${dist}"
			includes="**/*.java,**/*.bat,**/LICENSE.txt,**/README.txt,**/CHANGES.txt,**/*.html,**/*.jsp,**/*.css,**/*.txt,**/*.properties,**/*.xml"
			excludes="**/*.gif,**/*.jpg,**/*.pdf,**/*.jar,**/*.png"
			eol="crlf"
			eof="asis"
		/>
		<!-- fix for unix -->
		<fixcrlf
			srcDir="${dist}"
			includes="**/*.sh"
			excludes="**/*.gif,**/*.jpg,**/*.pdf,**/*.jar,**/*.png"
			eol="lf"
			eof="remove"
		/>
		<!-- build archives -->
		<zip zipfile="${dist}.zip" basedir="${distbase}" includes="${build}/**"/>
		<tar tarfile="${dist}.tar" basedir="${distbase}" includes="${build}/**"/>
		<gzip zipfile="${dist}.tar.gz" src="${dist}.tar" />
		<delete file="${dist}.tar" />
	</target>

	<!-- ===================================================== -->
	<!-- Deletes the distribution files and the jar files      -->
	<!-- ===================================================== -->
	<target name="clean" depends="init" description="Deletes the distribution files, jar files">
		<delete dir="${destdir}" />
		<delete dir="${testdestdir}" />
		<delete dir="${dist}" />
		<delete dir="${distbase}" />
		<delete>
			<fileset dir="${gcviewer}" includes="*.jar"/>
		</delete>
	</target>


	<!-- ===================================================== -->
	<!-- compiles, tests, and builds distribution              -->
	<!-- ===================================================== -->
	<target name="all" depends="test,dist" description="Compiles and builds distribution"/>

</project>
