<?xml version="1.0"?>

<!--
==============================================================================

 Whois build file

 Copyright (C) 2002 PostgreSQL, Inc.

==============================================================================
-->

<project default="create" basedir=".">

  <!--
    Give user a chance to override without editing this file
    (and without typing -D each time he compiles it)
  -->

  <property name="name" value="erserver"/>
  <property name="Name" value="eRServer"/>
  <property name="version" value="1.20"/>
  <property name="year" value="2002"/>

  <!--
    these are here only for those who use jikes compiler. For other
    developers this part makes no difference.
  -->
  <property name="build.compiler.emacs" value="on"/>
  <property name="build.compiler.warnings" value="true"/>
<!--  <property name="build.compiler.pedantic" value="true"/> -->
  <property name="build.compiler.depend" value="true"/>
  <property name="build.compiler.fulldepend" value="true"/>

  <property name="debug" value="on"/>
  <property name="optimize" value="off"/>
  <property name="deprecation" value="off"/>

  <!--
       ===================================================================
       Set the properties for intermediate directory
       ===================================================================
  -->
  <property name="build.dir" value="build"/>
  <property name="build.lib" value="${build.dir}/lib"/>
  <property name="build.classes" value="${build.dir}/classes"/>


  <!--
       ===================================================================
       Set the properties for source directories
       ===================================================================
  -->
  <property name="src.dir" value="src"/>
  <property name="conf.dir" value="conf"/>
  <property name="sql.dir" value="sql"/>
  <property name="bin.dir" value="bin"/>
  <property name="lib.dir" value="lib"/>
  <property name="dist.dir" value="dist"/>
  <property name="log.dir" value="log"/>
  <property name="install.file" value="install.sh"/>

  <property name="dist.name" value="${Name}-${version}"/>


  <!--
       ===================================================================
                                  Help on usage
       ===================================================================
  -->
  <target name="usage">
    <echo message=""/>
    <echo message="${Name} Build file"/>
    <echo message="-------------------------------------------------------------"/>
    <echo message=""/>
    <echo message=" available targets are:"/>
    <echo message=""/>
    <echo message="   car        --> generates the ${Name} jar files"/>
    <echo message="   compile    --> compiles the source code"/>
    <echo message="   create     --> moves the jar file into the erserver area"/>
    <echo message="   dist       --> generates the ${Name} distribution"/>
    <echo message="   clean-car      --> cleans up the created jar files"/>
    <echo message="   clean --> cleans up all genereated files and directories"/>
    <echo message=""/>
    <echo message="-------------------------------------------------------------"/>
    <echo message=""/>
  </target>

  <target name="help" depends="usage"/>

 <!--
       ===================================================================
       Set up dist properties
       ===================================================================
  -->
  <target name="setup-properties">

    <property name="dist.dir" value="dist"/>
    <property name="dist.bin" value="${dist.dir}/bin"/>
  </target>



  <!--
       ===================================================================
                         Prepares the build directory
       ===================================================================
  -->
  <target name="prepare" depends="setup-properties">
    <tstamp/>
    <filter token="year" value="${year}"/>
    <filter token="version" value="${version}"/>
    <filter token="date" value="${TODAY}"/>
    <property name="date" value="${TODAY}" />
    <mkdir dir="${build.dir}"/>

  </target>

  <!--
       ===================================================================
                           Prepares the library code
       ===================================================================
   -->
  <target name="prepare-lib" depends="prepare">
    <mkdir dir="${dist.dir}"/>
    <mkdir dir="${build.lib}"/>
    <copy file="${lib.dir}/jdbc7.0-1.2.jar" todir="${build.lib}"/>
    <copy file="${lib.dir}/log4j.jar" todir="${build.lib}"/>
    <copy file="${bin.dir}/version" tofile="${build.lib}/version-${version}"/>
  </target>


  <!--
       ===================================================================
                        Compiles the source code
       ===================================================================
  -->
  <target name="compile" depends="prepare,prepare-lib">

    <mkdir dir="${build.classes}"/>

    <javac srcdir="${src.dir}"
           destdir="${build.classes}"
           debug="${debug}"
           optimize="${optimize}"
           deprecation="${deprecation}">
      <classpath>
        <pathelement location="${src.dir}" />
        <fileset dir="${build.lib}">
          <include name="*.jar" />
        </fileset>
      </classpath>
    </javac>
  </target>


    <!--
       ===================================================================
                           Creates all the .jar files  / only testxmlserver
       ===================================================================
  -->
  <target name="jars" depends="compile">

      <jar jarfile="${build.lib}/${name}.jar"
         basedir="${build.classes}" >
      </jar>

  </target>

    <!--
       ===================================================================
                           Copies the .jar file into the main lib dir
       ===================================================================
  -->
  <target name="create" depends="jars">

    <copy file="${build.lib}/${name}.jar" tofile="../jar/${name}.jar"/>

  </target>


    <!--
       ===================================================================
                           Creates the .car file
       ===================================================================
  -->
  <target name="car" depends="jars">

    <jar jarfile="${build.lib}/${name}.car">

      <prefixedfileset dir="${build.lib}/" prefix="lib/">
        <include name="*.jar"/>
        <include name="version*"/>
      </prefixedfileset>


      <prefixedfileset dir="${conf.dir}" prefix="conf/">
        <include name="*.cfg"/>
      </prefixedfileset>

      <prefixedfileset dir="${sql.dir}" prefix="sql/">
        <include name="*.sql"/>
      </prefixedfileset>

      <prefixedfileset dir="${bin.dir}" prefix="bin/">
        <include name="*.sh"/>
        <include name="*.pl"/>
        <exclude name="${install.file}"/>
      </prefixedfileset>

      <prefixedfileset dir="${log.dir}" prefix="log/">
      </prefixedfileset>

      <prefixedfileset dir="${bin.dir}" prefix="bin/">
        <include name="*.me"/>
      </prefixedfileset>

    </jar>

    <copy file="${build.lib}/${name}.car" tofile="${dist.dir}/${dist.name}.car"/>
    <copy file="${bin.dir}/${install.file}" todir="${dist.dir}"/>
    <copy file="${bin.dir}/INSTALL" todir="${dist.dir}"/>
    <copy file="${bin.dir}/README" todir="${dist.dir}"/>
    <chmod dir="${dist.dir}" perm="750" />
    <chmod file="${dist.dir}/${install.file}" perm="u+x"/>
    <tar tarfile="${dist.name}-bin.tar" basedir="${dist.dir}" />
    <gzip zipfile="${dist.name}-bin.tar.gz" src="${dist.name}-bin.tar"/>
    <delete file="${dist.name}-bin.tar"/>

  </target>

     <!--
       ===================================================================
                      Cleans car
       ===================================================================
  -->
  <target name="clean-car" >
    <delete>
      <fileset dir="${build.lib}" includes="**/*.jar" />
    </delete>
    <delete>
      <fileset dir="${build.lib}" includes="**/*.car" />
    </delete>
  </target>

  <!--
       ===================================================================
                 Cleans up build and distribution directories
       ===================================================================
  -->
  <target name="clean" depends="setup-properties">
    <delete dir="${build.dir}" />
    <delete>
      <fileset dir="." includes="**/*~" defaultexcludes="no"/>
    </delete>
    <delete>
      <fileset dir="${dist.dir}" includes="**/*"/>
    </delete>
  </target>


</project>
