<?xml version="1.0" encoding="UTF-8"?>

<!-- 
  build.xml
  
  Copyright (c) 2007  Vreixo Formoso
 
  This library is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.
  See COPYING file for details.
-->

<project name="java-libburn" default="all" basedir=".">

	<!-- === App properties ============================ -->
	<property file="build.properties" />

	<!-- === Compiler properties ====================== -->
	<property name="build.compiler" value="modern" />

	<property name="javac.debug" value="on" />
	<property name="javac.optimize" value="off" />
	<property name="javac.deprecation" value="on" />
	<property name="javac.nowarn" value="on" />
	
	<property name="cc.debug" value="on" />

	<!-- === directories ====================== -->
	<property name="src" value="src" />
	<property name="src.java" value="${src}/java" />
	<property name="src.test" value="${src}/test" />
	<property name="src.jni" value="${src}/jni" />
	<property name="build" value="build" />
	<property name="build.object" value="${build}/.object" />
	<property name="build.headers" value="${build}/.headers" />
	<property name="build.classes" value="${build}/.classes" />
	<property name="build.test" value="${build}/.test" />
	<property name="doc" value="doc" />
	<property name="doc.api" value="${doc}/api" />
	<property name="libs" value="libs" />
	
	<property name="dist.tar" value="${package}-${version}" />
	<property name="dist.jar" value="${package}-${version}.jar" />

	<!-- === CC tasks ====================== -->
	<property name="cc.jar" value="${libs}/cpptasks.jar"/>	
	<taskdef resource="cpptasks.tasks"
	  	 	 classpath="${cc.jar}"
	  		 loaderRef="cctasks"/>
	<typedef resource="cpptasks.types"
 	 	 	 classpath="${cc.jar}"
	 		 loaderRef="cctasks"/>
	
	<!-- == JavaDoc URLs ========================================= -->

	<!-- JavaDoc bottom -->
	<property name="javadoc.bottomline" value="${package} ${version}" />

	<!-- == target "init" ================================================= -->
	<target name="init">
		<echo>
		----------------------------------------------------
		Building ${package}...
		----------------------------------------------------
		</echo>
	</target>

	<!-- == target "all" ================================================== -->
	<target name="all" depends="init, jars, jni" />

	<!-- == target "compile" ============================================== -->
	<target name="compile" depends="init">
		<mkdir dir="${build.classes}" />
		<javac srcdir="${src.java}" destdir="${build.classes}"
			debug="${javac.debug}"
			optimize="${javac.optimize}" deprecation="${javac.deprecation}"
			nowarn="${javac.nowarn}" />
	</target>

	<!-- == target "compile.test" ========================================== -->
	<target name="compile.test" depends="init">
		<mkdir dir="${build.test}" />
		<javac srcdir="${src.test}" destdir="${build.test}"
			classpath="${build.classes}" debug="${javac.debug}"
			optimize="${javac.optimize}" deprecation="${javac.deprecation}"
			nowarn="${javac.nowarn}" />
	</target>

	<!-- == target "headers" ============================================== -->
	<target name="headers" depends="compile">
		<mkdir dir="${build.headers}" />
		<javah destdir="${build.headers}"
	    	force="yes" classpath="${build.classes}">
	      	
			<class name="org.pykix.libburnia.libisofs.IsoVolume"/>
			<class name="org.pykix.libburnia.libisofs.IsoTreeNode"/>
			<class name="org.pykix.libburnia.libisofs.IsoExclude"/>
			<class name="org.pykix.libburnia.libisofs.IsoVolSet"/>
			<class name="org.pykix.libburnia.libburn.Burn"/>
			<class name="org.pykix.libburnia.libburn.Disc"/>
			<class name="org.pykix.libburnia.libburn.Drive"/>
			<class name="org.pykix.libburnia.libburn.DriveInfo"/>
			<class name="org.pykix.libburnia.libburn.Message"/>
			<class name="org.pykix.libburnia.libburn.Progress"/>
			<class name="org.pykix.libburnia.libburn.ReadOpts"/>
			<class name="org.pykix.libburnia.libburn.ScsiAdr"/>
			<class name="org.pykix.libburnia.libburn.Session"/>
			<class name="org.pykix.libburnia.libburn.Source"/>
			<class name="org.pykix.libburnia.libburn.Track"/>
			<class name="org.pykix.libburnia.libburn.WriteOpts"/>
		</javah>
	</target>
	
	<!-- == target "jni" ================================================== -->
	<target name="jni" depends="headers" >
		<mkdir dir="${build.object}"/>
		<cc debug="${cc.debug}"
			link="shared" libtool="yes"
			outfile="${build}/${package}-${version}"
			objdir="${build.object}"
			multithreaded="true"
			exceptions="true" >
			
			<defineset define="DEBUG"/>
			<compiler name="gcc" />
			<compilerarg value="-Wno-pointer-to-int-cast"/>
			<compilerarg value="-Wno-int-to-pointer-cast"/>
			
			<!-- A 64 bits off_t is needed for DVD -->
			<compilerarg value="-D_FILE_OFFSET_BITS=64"/>
			<compilerarg value="-D_LARGEFILE_SOURCE=1"/>
			
			<fileset dir="${src.jni}"/>
			<includepath location="${build.headers}" />
			
			<sysincludepath location="${env.JAVA_HOME}/include" />
			<sysincludepath location="${cflags.isofs}" />
			<sysincludepath location="${cflags.burn}" />
			
			<libset libs="isofs"/>
			<libset libs="burn"/>
			<linker name="gcc" />
		</cc>
	</target>


	<!-- == target "jars" ================================================= -->
	<target name="jars" depends="compile">
		<mkdir dir="${build}" />
		<jar destfile="${build}/${dist.jar}">
			<manifest>
				<attribute name="version" value="${version}" />
			</manifest>
			<fileset dir="${build.classes}" />
		</jar>
	</target>

	<!-- == target "rebuild" ============================================== -->
	
	<target name="rebuild" depends="init, clean, all" />

	<!-- == target "distclean" ============================================ -->

	<target name="distclean" depends="init">
		<delete dir="${build}" />
		<delete dir="${doc.api}" />
		<delete file="build.properties" />
		<delete >
			<fileset dir="." includes="config.*" />
		</delete>
	</target>

	<!-- ================ "maintainer-clean" target ======================= -->
	
	<target name="maintainer-clean" depends="distclean" >
		<echo>NOT IMPLEMENTED YET</echo>
	</target>

	<!-- == target "clean" ================================================ -->

	<target name="clean" depends="init">
		<delete dir="${build.classes}" />
		<delete dir="${build.object}" />
		<delete dir="${build.test}" />
		<delete >
			<fileset dir="." includes="hs_err_*" />
		</delete>
	</target>

	<!-- == target "javadoc" ============================================== -->
	
	<target name="doc" depends="compile">
		<delete dir="${doc.api}" />
		<mkdir dir="${doc.api}" />
		<javadoc packagenames="org.*" sourcepath="${src.java}"
			classpath="${build.classes}" destdir="${doc.api}" access="public"
			windowtitle="${package}" doctitle="${package}"
			header="${package}" bottom="${javadoc.bottomline}">
			<!--
				<link href="${j2se.javadocurl}"/>
			-->
		</javadoc>
	</target>

	<!-- ================= "run" target =================================== -->
	
	<target name="run" depends="all, compile.test">
		<!--
		<java classname="org.pykix.libburnia.test.IsoFsMain" fork="true" >
			<arg value="-R"/>
			<arg value="-L"/>
			<arg value="3"/>
			<arg value="/home/metalpain/Projects/LibBurn"/>
			<arg value="/home/metalpain/proba.iso"/>
			<classpath location="${build.test}" />
			<classpath location="${build.classes}"/>
			<jvmarg value="-Djava.library.path=${build}" />
		</java>
		-->
		<java classname="org.pykix.libburnia.test.Test" fork="true" >
			<classpath location="${build.test}" />
			<classpath location="${build.classes}"/>
			<jvmarg value="-Djava.library.path=${build}" />
		</java>
	</target>

	<!-- ================= "install" target =============================== -->
	
	<target name="install" depends="all">
		<echo>NOT IMPLEMENTED YET</echo>
		<!--  
			It seems that these are default locations for java objects, at
			least on Ubuntu:
			
			jars to /usr/share/java
			jni libs to /usr/lib/jni
		-->
	</target>
	
	<!-- ========================= "dist" target ========================== -->
	
	<target name="dist" depends="init, dist-tarZ" />
	
	<target name="dist-tarZ" >
		
		<mkdir dir="${build}"/>
		
		<patternset id="tar.commonfiles" includes="java-libburn/**"
			excludes="**/build/**, **/bin/**, **/*.back, **/*~,     
			          **/*.sh, **/doc/api/**, **/autom4te.cache/**, 
					  **/build.properties/**, **/.bzr**" />
		<!--
		 .tar.gz distribution (with execution permissions for .sh files) 
		-->
		<delete file="${build}/${dist.tar}.tar.gz"/>
		<tar tarfile="${build}/${dist.tar}.tar.gz" longfile="gnu" 
			 compression="gzip">
			<tarfileset dir="..">
				<patternset refid="tar.commonfiles"/>
			</tarfileset>
			<tarfileset dir=".." mode="755" includes="java-libburn/**/*.sh"/>
		</tar>
	</target>
	
	<!-- ======================== "backup" target ========================= -->
		
	<target name="backup" >
		
		<mkdir dir="${build}"/>
		
		<patternset id="tar.commonfiles" includes="java-libburn/**"
			excludes="**/build/**, **/bin/**, **/*.back, **/*~,     
			          **/*.sh, **/doc/api/**, **/autom4te.cache/**, 
					  **/build.properties/**" />
		
		<delete file="${build}/${dist.tar}.back.tar.gz"/>
		<tar tarfile="${build}/${dist.tar}.back.tar.gz" longfile="gnu" 
			 compression="gzip">
			<tarfileset dir="..">
				<patternset refid="tar.commonfiles"/>
			</tarfileset>
			<tarfileset dir=".." mode="755" includes="java-libburn/**/*.sh"/>
		</tar>
	</target>

</project>