<?xml version="1.0" encoding="UTF-8" ?>
<!--
	Copyright (c) 2004 on behalf of the EU EGEE Project: 
	The European Organization for Nuclear Research (CERN), 
	Istituto Nazionale di Fisica Nucleare (INFN), Italy
	Datamat Spa, Italy
	Centre National de la Recherche Scientifique (CNRS), France
	CS Systeme d'Information (CSSI), France
	Royal Institute of Technology, Center for Parallel Computers (KTH-PDC), Sweden
	Universiteit van Amsterdam (UvA), Netherlands
	University of Helsinki (UH.HIP), Finland
	University of Bergen (UiB), Norway
	Council for the Central Laboratory of the Research Councils (CCLRC), United Kingdom

	Build file for the Gridsite Core Subsystem
	
	Authors: Alberto Di Meglio <alberto.di.meglio@cern.ch>		
	Version info: $Id$
	Release: $Name$

	Revision history:
	$Log$
	Revision 1.12  2005/05/23 13:54:53  dimeglio
	Added load of build.number file

	Revision 1.11  2005/02/16 14:14:39  dimeglio
	Added patch to use globus compilation flags also in the RPMS
	
	Revision 1.10  2004/12/17 09:11:43  dimeglio
	Added local tag targets (because of special naming rules here)
	
	Revision 1.9  2004/12/17 09:02:49  dimeglio
	Removed redefinition of global.prefix
	
	Revision 1.8  2004/12/17 00:32:50  dimeglio
	Fixed global.prefix
	
	Revision 1.7  2004/12/03 14:49:59  dimeglio
	Added OPENSSL_FLAGS and _LIBS options
	
	Revision 1.6  2004/11/13 10:55:44  glbuild
	Added artifacts RPMS directory
	
	Revision 1.5  2004/10/29 22:55:07  dimeglio
	Use envset target
	
	Revision 1.4  2004/10/28 23:00:14  dimeglio
	Removed post-subsystem entry
	
	Revision 1.3  2004/10/27 11:19:17  dimeglio
	Fixed i386 instead of 1386
	
	Revision 1.2  2004/10/27 11:18:38  dimeglio
	Use os.platform instead of hard-coded rhel30
	
	Revision 1.1  2004/10/26 17:54:24  dimeglio
	First version of this file
	
-->

<project name="gridsite-core" default="dist">

	<description>
		Ant build file to build the Gridsite Core Component
	</description>
	
	<!-- =========================================
	     Import properties (order is important) 
	     ========================================= -->
	
	<!-- Import baseline & user properties -->
	<import file="../org.glite/project/baseline.properties.xml" />

	<!-- Import subsystem build properties, 
	                      subsystem properties & 
	                      subsystem common properties -->
	<import file="./project/properties.xml" />

	<!-- Import global build properties and global properties -->
	<import file="${global.properties.file}" />
				
	<!-- =========================================
		 Load dependencies properties files (order is important) 
	     ========================================= -->
	<property file="${user.dependencies.file}"/>
	<property file="${subsystem.dependencies.file}"/>
	<property file="${global.dependencies.file}"/>	
	
	<!-- =========================================
		 Load configure options
		========================================= -->
        <import file="${global.configure.options.file}"/>
		<import file="${component.configure.options.file}"/>
		
	<!-- =========================================
		 Import global task definitions
	     ========================================= -->
	<import file="${global.taskdefs.file}" />
	
	<!-- =========================================
	     Import global compiler definitions
  	     ========================================= -->
	<import file="${global.compilerdefs.file}" />
		
	<!-- =========================================
		 Import targets 
	     ========================================= -->
	<import file="${global.targets-common.file}" />
	
	<!-- =========================================
		 Load version file 
	     ========================================= -->
	<property file="${module.version.file}"/>
	<property file="${module.build.file}"/>
	
	<!-- ===============================================
		  Public common targets
	     =============================================== -->
	
	<target name="localinit" depends="envcheck">
		<mkdir dir="${stage.dir}" />
		<mkdir dir="${dist.dir}" />
	</target>

	<target name="init" depends="localinit">
		<echo>${global.prefix}</echo>
	</target>

	<target name="checkstyle" depends="init">
	</target>

	<target name="compile" depends="checkstyle">
		<if>
			<isset property="libonly"/>
			<then>
				<property name="buildtarget" value="build-lib"/>
			</then>
			<else>
				<property name="buildtarget" value="build"/>
			</else>
		</if>
		<if>
			<isset property="build.make.arguments"/> 	 
			<then>
				<!-- Call make default compile target -->	
				<make target="${buildtarget}" dir="${module.src.dir}" failonerror="${failonerror}" args="${build.make.arguments}"/>
			</then> 	 
			<else> 	 
				<!-- Call make default compile target -->	
				<make target="${buildtarget}" dir="${module.src.dir}" failonerror="${failonerror}"/>
			</else> 	 
		</if> 	 
	</target>

	<target name="compiletest" depends="compile">
	</target>

	<target name="unittest" depends="compiletest">
	</target>

	<target name="unitcoverage" depends="unittest">
	</target>

	<target name="doc" depends="unitcoverage">
	</target>

    <target name="stage" depends="doc">
		<if>
			<isset property="libonly"/>
			<then>
				<property name="installtarget" value="install-lib"/>
			</then>
			<else>
				<property name="installtarget" value="install"/>
			</else>
		</if>
		<if>
			<isset property="build.make.arguments"/> 	 
			<then>
				<!-- Call make default compile target -->	
				<make target="${installtarget}" dir="${module.src.dir}" failonerror="${failonerror}" args="${build.make.arguments}"/>
			</then> 	 
			<else> 	 
				<!-- Call make default compile target -->	
				<make target="${installtarget}" dir="${module.src.dir}" failonerror="${failonerror}"/>
			</else> 	 
		</if> 	 
    </target>

	<target name="dist" depends="stage">
		<make target="rpm" dir="${module.src.dir}" failonerror="${failonerror}" args="${build.make.arguments}"/>
		<exec dir="${module.dir}/RPMTMP/BUILDROOT/usr" executable="tar">
			<arg line="-czf ${module.dir}/gridsite-${module.version}_bin.tar.gz ." />
		</exec>
		<copy file="gridsite-${module.version}_bin.tar.gz" todir="${dist.dir}"/>
		<copy file="gridsite-${module.version}.src.tar.gz" tofile="${dist.dir}/gridsite-${module.version}_src.tar.gz"/>
		<copy todir="${dist.dir}/${os.platform}/i386/RPMS">
			<fileset dir="${module.dir}/RPMTMP/RPMS/i386">
				<include name="*.rpm"/>
			</fileset>
		</copy>
		<delete dir="${module.dir}/RPMS"/>
		<mkdir dir="${module.dir}/RPMS"/>
                <copy todir="${module.dir}/RPMS">
                        <fileset dir="${module.dir}/RPMTMP/RPMS/i386">
                                <include name="*.rpm"/>
                        </fileset>
                </copy>
		<delete>
			<fileset dir="${module.dir}">
				<include name="*.tar.gz"/>
			</fileset>
		</delete>
		<delete dir="RPMTMP"/>
	</target>

	<target name="install" depends="localinit">
		<make target="install" dir="${module.src.dir}" failonerror="${failonerror}"/>
	</target>

	<target name="all" depends="dist">
	</target>

	<target name="clean" depends="envcheck">
		<property name="offline.repository" value="true" />
		<make target="clean" dir="${module.src.dir}" failonerror="false"/>
		<delete dir="${module.dir}/src/doxygen"/>
		<delete>
			<fileset dir="${module.dir}/src">
				<include name="*.o"/>
				<include name="*.so"/>
				<include name="*.so.*"/>
				<include name="*.a"/>
				<include name="rm -rf urlencode"/>
			</fileset>
		</delete>
		<delete dir="${module.dir}/RPMS"/>
	</target>

	<target name="cleanAll" depends="clean"/>

	<!-- ===============================================
		 Private targets
	     =============================================== -->
	
	<!-- ========================================================
              tag: Tag module     
	     ======================================================== -->
	<target name="tag" description="Apply tag.">

		<property name="tag.type" value="B"/>
		<!-- Set module CVS Label -->
		<exec executable="tr" inputstring="${module.version}" outputproperty="cvs.module.version">
			<arg line=". _"/>
		</exec>
		<property name="cvs.label" value="gridsite-core_${tag.type}_${cvs.module.version}_${module.build}" />
		<echo>New tag is ${cvs.label}</echo>
		
		<!-- Apply tag -->
		<property name="failonerror" value="true"/>
		<property name="tag.switch" value="-FR"/>
		<exec dir="${workspace.abs.dir}" executable="cvs" failonerror="${failonerror}">
			<arg line="tag ${tag.switch} ${cvs.label} ${module.name}" />
		</exec>

	</target>

	<target name="component_release_tag">

		<!-- Set module CVS Label -->
		<exec executable="tr" inputstring="${module.version}" outputproperty="cvs.module.version">
			<arg line=". _"/>
		</exec>
		<property name="cvs.label" value="gridsite-core_R_${cvs.module.version}" />
		<echo>New tag is ${cvs.label}</echo>
		
		<!-- Apply tag -->
		<exec dir="${workspace.abs.dir}" executable="cvs" failonerror="true">
			<arg line="tag -R ${cvs.label} ${module.name}" />
		</exec>

	</target>

	<!-- ===============================================
		 Modules proxy targets
	     =============================================== -->

	<!-- component targets definitions tag = do not remove = -->

	<!-- Main proxy -->
	<target name="buildmodules" depends="envset"/>

</project>

