<?xml version="1.0"?>
<!--
	Builds API documentation and PEAR compliant packages.
	
	Phing 2.2.0 (http://phing.info) or newer recommended.
	
	@version $Id$
	@author Jukka Hassinen <jukka.hassinen@brainalliance.com> 
-->	
<project name="Doctrine" basedir="." default="main">
	
	<property name="base.name" value="Doctrine"/>
	<property name="project.base.dir" value="../.."/>
	<property name="build.base.dir" value="${project.base.dir}/build"/>	
	<property name="build.dest.dir" value="${build.base.dir}/tobuild"/>
	
	<fileset dir="${project.base.dir}/lib" id="classes">			
		<include name="**/**"/>
		<exclude name="**/.svn**"/>
	</fileset>

	<fileset dir="${project.base.dir}/manual" id="docs">
		<include name="**/**"/>
        <exclude name="**/.svn**"/>
	</fileset>

	<fileset dir="${project.base.dir}/tests" id="test">
		<include name="**/**"/>
		<exclude name="**/.svn**"/>
		<exclude name="**/.svn*/*.txt"/>
		<exclude name=".svn/**"/>
		<exclude name=".svn**"/>
	</fileset>

	<target name="main">
		<phingcall target="build"/>
		<phingcall target="generate-docs"/> 
<!--		<phingcall target="pear-package"/> -->
<!--		<phingcall target="compress"/> -->
	</target>
		
	<target name="build">
		<echo>-----------------------------</echo>
		<echo>| Creating directory layout |</echo>
		<echo>-----------------------------</echo>
		
		<delete dir="${build.base.dir}"/>
		
		<copy todir="${build.dest.dir}/lib">			
			<fileset refid="classes"/>						
		</copy>

		<copy todir="${build.dest.dir}/docs">			
			<fileset refid="docs"/>						
		</copy>

		<copy todir="${build.dest.dir}/test">			
			<fileset refid="test"/>						
		</copy>
		
		
		<svnlastrevision svnpath="svn" workingcopy="${project.base.dir}" propertyname="svn.lastrevision"/>
		<property name="version" value="0.0.${svn.lastrevision}"/>

		<fileset dir="${build.dest.dir}" id="php-files">			
			<include name="**/**.php"/>
			<exclude name="**/.svn**"/>
		</fileset>

		<reflexive>
	  		<fileset refid="php-files" />
			<filterchain>
				<replaceregexp>
			      <regexp pattern="@version \$(.*)\$" replace="@version \$$1\$ Package ver: ${version}"/>
			    </replaceregexp>
			</filterchain>
			<filterchain>
  				<tabtospaces tablength="4" />
			</filterchain>
		</reflexive>
		
	</target>

	<target name="generate-docs">
		<!-- 
			Generates the API documentation using Doxygen and PHPDoc 
			Doxygen is required in the path.
		-->
		<mkdir dir="${build.dest.dir}/docs/API/doxygen" />		
		<exec command="doxygen" dir="."/>
		<!-- <exec command="make pdf" dir="${build.src.dir}/docs/latex"/> -->		
		
		<mkdir dir="${build.dest.dir}/docs/API/phpdoc" />
		<phpdoc title="Doctrine Documentation" destdir="${build.dest.dir}/docs/API/phpdoc/html" 
                        sourcepath="${project.base.dir}/lib" output="HTML:Smarty:PHP"/>
	</target>
	
	<target name="pear-package">
	
		<echo>-----------------------------</echo>
		<echo>| Creating PEAR package.xml |</echo>
		<echo>-----------------------------</echo>
		<echo></echo>
		
		<svnlastrevision svnpath="svn" workingcopy="${project.base.dir}" propertyname="svn.lastrevision"/>
		<property name="version" value="0.0.${svn.lastrevision}"/>
		
		<pearpkg name="${base.name}" dir="${build.dest.dir}" destFile="${build.dest.dir}/package.xml">
			
			<fileset refid="classes"/>			
			<fileset refid="docs"/>			
			<fileset refid="test"/>
		
			<option name="notes">*</option>
			<option name="description">ORM</option>			
			<option name="summary">ORM</option>
			<option name="version" value="${version}"/>
			<option name="state" value="stable"/>
			<option name="license" value="LGPL"/>
			
			<mapping name="maintainers">
				<element>
					<element key="handle" value="jhassine"/>
					<element key="name" value="Jukka Hassinen"/>
					<element key="email" value="Jukka.Hassinen@BrainAlliance.com"/>
					<element key="role" value="lead"/>
				</element>
			</mapping>
			
			<mapping name="deps">
				<element>
					<element key="type" value="php"/>
					<element key="version" value="5.1.0"/>
					<element key="rel" value="ge"/>
				</element>						
			</mapping>
		</pearpkg>
	</target>
	
	<target name="compress">
		<echo>-----------------------------</echo>
		<echo>| Creating tar.gz package   |</echo>
		<echo>-----------------------------</echo>	
		
		<svnlastrevision svnpath="svn" workingcopy="." propertyname="svn.lastrevision"/>
		<property name="version" value="0.0.${svn.lastrevision}"/>
		
		<property name="gztarfile" value="${build.base.dir}/${base.name}-${version}-pear.tar.gz"/>
		<property name="bz2tarfile" value="${build.base.dir}/${base.name}-${version}-pear.tar.bz2"/>
		<property name="zipfile" value="${build.base.dir}/${base.name}-${version}-pear.zip"/>
			
		<delete	file="${gztarfile}"/>
		<delete	file="${bz2tarfile}"/>
		<delete	file="${zipfile}"/>                
		<tar destFile="${gztarfile}" basedir="${build.dest.dir}" compression="gzip"/>
		<tar destFile="${bz2tarfile}" basedir="${build.dest.dir}" compression="bzip2"/>
		<zip destfile="${zipfile}" basedir="${build.dest.dir}"/>
	</target>
	
</project>