<!--
- Author: Sean Russell <ser@germane-software.com>
- Version: 0.1
- Date: *2002-157
- 
- To use this, makefile you'll need ant (http://jakarta.apache.org/ant), java
- (obviously), and junit (http://www.junit.org).  Put the ant executable
- in your path and run 'ant help' (in the same directory that this build.xml
- file is in), and follow the instructions.
-
- Be aware, very aware, that there is no "install" option.  The furthest you
- can currently go with this script is 'dist', which will compile everything
- and build a jarball of the Java library.  'dist' doesn't run the tests.
- After 'dist', to install this you still need to copy libsvn_jni.so to
- a good location (like /usr/local/lib) and run ldconfig yourself.  This
- buildfile may include an 'install' task someday.  Maybe.
-->
<project name="SVNJavaBinding" default="compile" basedir=".">
	<!-- 
	- Set up the compile environment.  Properties we set are:
	- version, date, and class.path, and we define a junit task.
	-->
	<property name='version' value='0.1'/>
	<property name='date' value='*2002-155'/>
	<path id="class.path">
		<pathelement path="."/>
		<pathelement path='tests'/>
		<pathelement path="junit.jar"/>
	</path>
	<property name="class.path" refid="class.path"/>
	<taskdef name="junit"
		classname="org/apache/tools/ant/taskdefs/optional/junit/JUnitTask"/>

	<!-- ########################################################### 
	- Print some help/usage information 
	-->
	<target name='help'>
		<echo>USAGE: ant [task]</echo>
		<echo>The tasks defined are:</echo>
		<echo>compile - Builds all of the java files, tests, and the native</echo>
		<echo>          library.</echo>
		<echo>dist    - Builds a jar file of the java library.</echo>
		<echo>test    - Runs the unit tests.</echo>
		<echo>clean   - Removes the compiled/generated files.</echo>
	</target>


	<!-- ###########################################################
	- Compile the core SVN java library classes 
	-->
	<target name="compile.classes">
		<javac debug="on" destdir="." deprecation="on" srcdir="." 
			classpathref="class.path"
			includes="org/tigris/subversion/*.java"
			excludes=".svn/**"/>
		<javac debug='on' destdir='.' deprecation='on' srcdir='.'
			classpathref='class.path'
			includes='org/tigris/subversion/lib/*.java'
			excludes='.svn/**'/>
	</target>


	<!-- ########################################################### 
	- Compile the test classes
	-->
	<target name='compile.tests' depends='compile.classes'>
		<javac debug="on" destdir="." deprecation="on" srcdir="." 
			classpathref="class.path"
			includes="*.java"
			excludes=".svn/**"/>
		<javac debug='on' destdir='tests' deprecation='on' srcdir='.'
			classpathref="class.path"
			includes='tests/*.java'
			excludes=".svn/**"/>
	</target>


	<!-- ###########################################################
	- Compile the JNI headers 
	-->
	<target name='compile.jnih' depends='compile.classes,compile.tests'>
		<javah classpath='${class.path}' outputFile='svn_jni.h'
			class='org.tigris.subversion.lib.ClientImpl'/>
		<javah classpath='${class.path}'
			outputFile='tests/nativewrapper.h'
			class='NativeWrapper'/>
	</target>


	<!-- ########################################################### 
	- A setup task that checks to see if the native library is up-to-date.
	- Sets a property that causes compile.native to be skipped if true.
	-->
	<property name='commonobjs'
		value="date.c,misc.c,status.c,hashtable.c,string.c,j.c,entry.c,vector.c,schedule.c,revision.c,nodekind.c,statuskind.c"/>
	<target name='native.init'>
		<uptodate property="dont.compile.native" 
			targetfile="libsvn_jni.so" >
			<srcfiles dir= "." includes="${commonobjs},main.c,clientimpl_status.c"/>
		</uptodate>
		<uptodate property='dont.compile.nativetests'
			targetfile='libsvn_jni_nativewrapper.so'>
			<srcfiles dir='.' includes='${commonobjs},tests/main.c,tests/nativewrapper.c'/>
		</uptodate>
	</target>
	

	<!-- ########################################################### 
	- Compile the native .so stuff.  This currently uses the original
	- build.sh file to do the compiling, mainly because I'm lazy.  I
	- haven't yet figured out a clean way to compile the native library
	- via Ant.  I'd like to do it in a cross-platform way (which Ant
	- provides assistance for), because the original scripts only work
	- on Unix-ish platforms.
	-->
	<target name='compile.native' depends='native.init,compile.jnih' 
		unless='dont.compile.native'>
		<exec executable='sh' os='Linux'>
			<arg line='build.sh'/>
		</exec>
	</target>

	<!-- This is a future task.  -->
	<target name='compile.nativetests' depends='compile.native'
		unless='dont.compile.native.tests'/>


	<!-- ########################################################### 
	- Compiles everything. 
	-->
	<target name='compile' depends='compile.jnih,compile.native'/>
	

	<!-- ########################################################### 
	- Runs the unit tests 
	-->
	<target name="test" depends="compile">
		<echo>If this fails, make sure you have junit.jar in this directory,</echo>
		<echo>and that your CLASSPATH is set; EG: 'export CLASSPATH=junit.jar'</echo>
		<junit printsummary='on'>
			<formatter type='plain'/>
			<classpath refid="class.path"/>
			<test name="AllTests"/>
		</junit>
		<echo>Any errors were written to TEST-AllTests.txt</echo>
	</target>


	<!-- ########################################################### 
	- Deletes generated and compiled files. 
	-->
	<target name="clean">
		<delete>
			<fileset dir="." casesensitive="yes" >
				<include name="**/*.class"/>
				<include name='**/*.o'/>
				<include name='**/*.so'/>
				<include name='svn_jni.h'/>
				<include name='svn.jar'/>
				<include name='tests/nativewrapper.h'/>
				<include name='TEST*.txt'/>
			</fileset>
		</delete>
	</target>


	<!-- ########################################################### 
	- Builds a distribution .jar file for the Java library part. 
	-->
	<target name="dist" depends="compile">
		<jar jarfile='svn.jar'
			basedir='.'
			includes='org/tigris/subversion/**.class'
			excludes='**/.svn/**'/>
	</target>
</project>


