<?xml version="1.0" encoding="iso-8859-1"?>
<!--
Indus, a program analysis and transformation toolkit for Java.
Copyright (c) 2001, 2007  Venkatesh Prasad Ranganath

All rights reserved.  This program and the accompanying materials are made 
available under the terms of the Eclipse Public License v1.0 which accompanies 
the distribution containing this program, and is available at 
http://www.opensource.org/licenses/eclipse-1.0.php.

For questions about the license, copyright, and software, contact 
	Venkatesh Prasad Ranganath at venkateshprasad.ranganath@gmail.com
                                
This software was developed by Venkatesh Prasad Ranganath in SAnToS Laboratory 
at Kansas State University.
-->
<!-- $Revision$ -->

<project name="indus" default="dist-all" basedir=".">
    <tstamp/>
	
	<taskdef resource="net/sf/antcontrib/antlib.xml"/>	
	
	<property file="distbuild.properties" />

    <path id="subprojects.buildfiles">
        <pathelement path="${projects.dir}/Indus"/>
        <pathelement path="${projects.dir}/StaticAnalyses"/>
        <pathelement path="${projects.dir}/JavaSlicer"/>
    </path>
	
    <target name="init">
        <tstamp/>
        <fail unless="version.fileid" message="specify the property version.fileid (x.y) via the command line. x and y should be numbers.  This will be used to create the filename."/>
        <fail unless="version.cvsid" message="specify the property version.cvsid (x_y) via the command line. x and y should be numbers.  This will be used to extract the given version and tag the resource with a new tag when the build finishes."/>
    	<delete dir="${projects.dir}"/>
    	<mkdir dir="${projects.dir}"/>
        <cvs cvsroot="${cvs.root}"
            compression="true" compressionlevel="3"
            package="${cvs.modules}"
            cvsRsh="ssh"
            dest="${projects.dir}" failonerror="true"
            command="co -r v${version.cvsid}"/>
    </target>

	<target name="tag">
        <fail unless="version.cvsid" message="specify the property version.cvsid (x_y) via the command line. x and y should be numbers.  This will be used to extract the given version and tag the resource with a new tag when the build finishes."/>
        <cvs cvsroot="${cvs.root}"
             compression="true" compressionlevel="3"
             package="${cvs.modules}"
             cvsRsh="ssh"
             dest="${projects.dir}" failonerror="true"
             command="rtag v${version.cvsid}"/>
	</target>

  <target name="dist-all" depends="init, cleanAll, buildAllCode, buildAllDoc">
    <antcall target="package"/>
    <delete dir="${projects.dir}"/>
  </target>

	<target name="dist-bin" depends="init, cleanAll, buildAllCode">
		<antcall target="package-bin"/>
    	<delete dir="${projects.dir}"/>
  </target>

  <target name="dist-docs" depends="buildAllDoc">
    <antcall target="package"/>
    <delete dir="${projects.dir}"/>
  </target>
		
	<target name="prepare-docs">
		<!--
		<mkdir dir="${dist.doc.dir}/${module}/docs/ug"/>
		<unzip dest="${dist.doc.dir}/${module}/docs/ug">
			<fileset dir="${projects.dir}/${module}/docs/ug/dist/">
				<include name="*html-single.zip"/>
			</fileset>			
		</unzip>
		-->
		<mkdir dir="${dist.doc.dir}/${module}/docs/javadocs"/>
		<copy todir="${dist.doc.dir}/${module}/docs/javadocs">
			<fileset dir="${projects.dir}/${module}/docs/javadocs"/>
		</copy>
	</target>
	
	<target name="package-bin">
		<copy todir="${dist.dir}" flatten="true">
            <fileset dir="${projects.dir}">
                <include name="*/*.jar"/>
                <exclude name="*/*src*.jar"/>
            </fileset>
        </copy>
		<move todir="${dist.dir}">
            <fileset dir="${dist.dir}">
                <include name="*.jar"/>
            </fileset>
            <mapper type="regexp" from="^([A-Za-z_-]*).jar$$" to="\1-${version.fileid}.jar"/>
        </move>
	</target>
	
    <target name="package-docs">
        <mkdir dir="${dist.doc.dir}"/>
		<foreach list="${cvs.modules}" target="prepare-docs" param="module" delimiter=" " inheritall="true"/>		
        <zip destfile="${docs.zip.filename}">
			<zipfileset dir="${dist.doc.dir}" prefix=""/>
		</zip>
        <delete dir="${dist.doc.dir}"/> 
    </target>
        
	<target name="package">
		<antcall target="package-docs"/>
		<antcall target="package-bin"/>
	  <antcall target="build-examples"/>	
    </target>

    <target name="build-examples">
        <zip destfile="${examples.src.zip.filename}">
            <fileset dir="${projects.dir}">
                <include name="*/src-xml/**/*.java"/>
            	<include name="Indus/src/**/SootBasedDriver.java"/>
            	<include name="*/src/**/*.xsd"/>
            </fileset>
        </zip>
    </target>

    <target name="cleanAll" depends="init">
        <subant target="clean">
        	<property file="distbuild.properties"/>
            <buildpath refid="subprojects.buildfiles"/>
        </subant>
    </target>

    <target name="buildAllCode" depends="init">
        <subant target="build">
	    	<property file="distbuild.properties"/>
            <buildpath refid="subprojects.buildfiles"/>
        </subant>
        <subant target="jar">
           	<property file="distbuild.properties"/>
            <buildpath refid="subprojects.buildfiles"/>
        </subant>
    </target>

    <target name="buildAllDoc" depends="init">
        <subant target="docs">
           	<property file="distbuild.properties"/>            	
            <buildpath refid="subprojects.buildfiles"/>
        </subant>
    </target>

</project>
