<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." default="everything" name="deploy">
    <property environment="env"/>

    <!-- 
	CONFIGURATION PARAMETERS
	Modify here the parameters according to your own system
    -->
	<!-- PAMELA Software(s) root directory -->
    	<property name="pamSoftware"
		  value="/home/pamelaprod/yoda"/>
	<!-- CERN's ROOT base directory -->
	<property name="root"
		  value="/opt/root"/>
	<!-- LOG4CXX base directory -->
	<property name="log4cxx" 
		  value="/opt/log4cxx"/>
	<!-- ant-contrib base directory -->
	<property name="ant-contrib.lib"
		  value="/opt/ant-contrib/lib"/>
	
	<property name="scripts.src"
		value="${basedir}"/>

	<property name="destdir"
		value="${basedir}/.."/>
	

	<!-- 
	     CONFIGURATION PARAMETERS (optional)
	     If your system have custom installation, uncomment and modify
	     the parameters according to your own system
        -->
	<!-- fortToC library directory -->
	<!--<property name="g2c"
		  value="xxx/libf2c/.libs"/>-->
	






    <!-- 
	     PARAMETRIZED PARAMETERS 
	     From here to the end there is NO NEED to modify anything
    -->
    <tstamp>
	    <format property="compilationFolder" pattern="hmsS" unit="millisecond"/>
    </tstamp>
    
    <!-- Linux -->
    <property name="local" value="/usr/local"/>
    <property name="local.include" value="${local}/include"/>
    <property name="local.lib" value="${local}/lib"/>
    
    <!-- CERN's ROOT -->
    <property name="root.include" value="${root}/include"/>
    <property name="root.lib" value="${root}/lib"/>
    
    <!-- log4cxx -->    
    <property name="log4cxx.include" value="${log4cxx}/include"/>
    <property name="log4cxx.lib" value="${log4cxx}/lib"/>
    
    <!-- ant-contrib library -->
    <path id="classpath">
        <pathelement location="${ant-contrib.lib}/cpptasks.jar"/>
    </path>
    
    <!--
	  Load definition of C/C++ Tasks and Types
	  To allow the compilation and linking of C/C++ code  
    -->	
    <taskdef classpathref="classpath" loaderref="classpath.loaderRef" resource="cpptasks.tasks"/>
    <typedef classpathref="classpath" loaderref="classpath.loaderRef" resource="cpptasks.types"/>
     
    <!--
	  Load definition of Additional Tasks and Types
    --> 
    <taskdef resource="net/sf/antcontrib/antcontrib.properties">
        <classpath>
		<pathelement location="${ant-contrib.lib}/ant-contrib.jar"/>
        </classpath>
    </taskdef>

    <target name="init">
	<!-- Compiler parameters -->
	<property name="compilationFolder.lib" 	   	value="${compilationFolder}/lib"/>
	<property name="compilationFolder.include"  	value="${compilationFolder}/include"/>
	
	<!-- scripts parameters -->
	<property name="scripts.compilationFolder" value="${env.HOME}/tmp/${compilationFolder}"/>
	<property name="scripts.obj"      	   value="${scripts.compilationFolder}/obj"/>
	<property name="scripts.lib"      	   value="${scripts.compilationFolder}/lib"/>
	<property name="scripts.bin"      	   value="${scripts.compilationFolder}/bin"/>
	
	<!-- Deploy parameters -->
	<property name="deploy"   	value="${destdir}"/>
	<property name="deploy.lib" 	value="${destdir}/lib"/>
	<property name="deploy.include" value="${destdir}/include"/>
	<property name="deploy.bin"	value="${deploy}/bin"/>

	<mkdir dir="${compilationFolder}"/>
    </target>

    <compiler id="scripts-gcc" name="gcc">
	    <includepath location="${local.include}"/>
	    <includepath location="${log4cxx.include}"/>
	    <includepath location="${root.include}"/>
	    <compilerarg value="-O"/>
	    <compilerarg value="-g"/>
    </compiler>
    
    <linker id="scripts-link">
	    <libset dir="${root.lib}"    libs="Cint, Core, Tree, Graf, Hist, Matrix, Gpad"/>
	    <libset dir="${log4cxx.lib}" libs="log4cxx"/>
	    <libset libs="stdc++"/>
    </linker>
    
    
    <!-- 
	 Clean the compilation folder
    -->
    <target description="Clean all build products." name="clean">
	    <delete dir="${scripts.compilationFolder}"/>
	    <delete dir="${compilationFolder}"/>
    </target>
    
    <target description="Create executable" name="compileQL">
	    <mkdir dir="${scripts.bin}"/>
	    <mkdir dir="${scripts.obj}"/>
	    <cc objdir="${scripts.obj}" outfile="${scripts.bin}/TriggerScanBasic" outtype="executable">
		    <compiler extends="scripts-gcc">
			    <fileset dir="${scripts.src}" includes="TriggerScanBasic.cpp">
			    </fileset>
			    <includepath location="${scripts.src}"/>
			    <includepath location="${pamSoftware}/include"/>
			    <includepath location="${pamSoftware}/include/yoda"/>
		    </compiler>
		    <linker extends="scripts-link">
			    <libset dir="${pamSoftware}/lib" libs="yoda"/>
		    </linker>
	    </cc>
	    
    </target>
    
    <target depends="compileQL" description="Create executable" name="Basic">
	    
    </target>


    <target description="Create executable" name="compileQLExp">
	    <mkdir dir="${scripts.bin}"/>
	    <mkdir dir="${scripts.obj}"/>
	    <cc objdir="${scripts.obj}" outfile="${scripts.bin}/TriggerScanExpert" outtype="executable">
		    <compiler extends="scripts-gcc">
			    <fileset dir="${scripts.src}" includes="TriggerScanExpert.cpp">
			    </fileset>
			    <includepath location="${scripts.src}"/>
			    <includepath location="${pamSoftware}/include"/>
			    <includepath location="${pamSoftware}/include/yoda"/>
		    </compiler>
		    <linker extends="scripts-link">
			    <libset dir="${pamSoftware}/lib" libs="yoda"/>
		    </linker>
	    </cc>
	    	    
    </target>


    <target depends="compileQLExp" description="Create executable" name="Exp">
	    
    </target>

    <target depends="init" description="Deploy the scripts" name="deploy">
	<mkdir dir="${deploy}"/>
	<mkdir dir="${deploy.lib}"/>
	<mkdir dir="${deploy.bin}"/>
	    <!--<copy todir="${deploy.lib}">
		    <fileset dir="${profiler.lib}" includes="*.so"/>
	    </copy>-->
	    <copy todir="${deploy.bin}">
		    <fileset dir="${scripts.bin}" includes="*" excludes="*.*"/>
	    </copy>
	    <chmod dir="${deploy.bin}" perm="775" includes="**/*"/>
    </target>
    
    <target depends="init,Basic,Exp,deploy,clean" description="Make everything" name="everything">
     </target>
</project>
