<!DOCTYPE project [

<!ENTITY base ".." >
<!ENTITY tomcat_build "&base;/build/tomcat" >
<!ENTITY tomcat_build "&base;/dist/tomcat" >
<!ENTITY ant_home "&base;/build/tomcat" >
<!ENTITY app_name "tomcat" >
<!ENTITY app_version "3.1beta" >

]>

<project name="Tomcat" default="main" basedir=".">

  <!-- ==================== Copy static files ==================== -->
  <!-- IF YOU CHANGE, sync dist.prepare !!! -->

  <target name="prepare">
    <mkdir dir="src/doc"/> <!-- Temp change until dir is not empty -->
    <mkdir dir="&tomcat_build;"/>
    <mkdir dir="&tomcat_build;/classes"/>
    <mkdir dir="&tomcat_build;/conf"/>
    <mkdir dir="&tomcat_build;/src"/>
    <mkdir dir="&tomcat_build;/lib"/>
    <mkdir dir="&tomcat_build;/logs"/>
    <mkdir dir="&tomcat_build;/bin"/>
    <mkdir dir="&tomcat_build;/doc"/>
    <mkdir dir="&tomcat_build;/webapps"/>

    <copydir src="src/shell" dest="&tomcat_build;/bin" />
    <copydir src="src/etc" dest="&tomcat_build;/conf"/>
    <copydir src="src/doc" dest="&tomcat_build;/doc"/>
    <copydir src="src/share/javax" dest="&tomcat_build;/src/javax"/>
    <mkdir dir="&tomcat_build;/lib/test"/>
    <mkdir dir="&tomcat_build;/lib/test/Golden"/>
    <copydir src="src/tests/share/tests/jsp/Golden" dest="&tomcat_build;/lib/test/Golden"/>

    <!-- include ant, it is used for testing and will be used for
         configuration and few other tasks -->
    <copydir src="&ant_home;/bin" dest="&tomcat_build;/bin"/>
    <copyfile src="&ant_home;/lib/xml.jar" dest="&tomcat_build;/lib/xml.jar"/>
    <copyfile src="&ant_home;/lib/ant.jar" dest="&tomcat_build;/lib/ant.jar"/>

    <copyfile src="LICENSE" dest="&tomcat_build;/LICENSE"/>

    <fixcrlf srcdir="&tomcat_build;" includes="*.sh" cr="remove"/>
    <fixcrlf srcdir="&tomcat_build;" includes="*.bat" cr="add"/>

    <chmod perm="+x" src="&tomcat_build;/bin/ant"/>
    <chmod perm="+x" src="&tomcat_build;/bin/antRun"/>
    <chmod perm="+x" src="&tomcat_build;/bin/tomcat.sh"/>
    <chmod perm="+x" src="&tomcat_build;/bin/jspc.sh"/>
    <chmod perm="+x" src="&tomcat_build;/bin/startup.sh"/>
    <chmod perm="+x" src="&tomcat_build;/bin/shutdown.sh"/>
  </target>

  <!-- ==================== Build tomcat ==================== -->
  <target name="tomcat" depends="prepare">
    <javac srcdir="src/share" destdir="&tomcat_build;/classes"
           classpath="&tomcat_build;/lib/xml.jar" debug="on"/>
    <javac srcdir="src/j2ee" destdir="&tomcat_build;/classes"
           classpath="&tomcat_build;/lib/xml.jar" debug="on"/>
    <rmic base="&tomcat_build;/classes"
          classname="org.apache.tomcat.shell.AdminImpl"/>
  </target>

  <!-- ==================== Build all web applications ==================== -->
  <target name="webapps" depends="prepare">
    <!-- Examples -->
    <mkdir dir="&tomcat_build;/webapps/examples"/>
    <copydir src="src/examples" dest="&tomcat_build;/webapps/examples"/>
    <javac srcdir="src/examples/WEB-INF/classes"
           destdir="&tomcat_build;/webapps/examples/WEB-INF/classes"
           classpath="&tomcat_build;/classes"/>
    <javac srcdir="src/examples/jsp/plugin/applet"
           destdir="&tomcat_build;/webapps/examples/jsp/plugin/applet"/>

    <!-- Root context -->
    <mkdir dir="&tomcat_build;/webapps/ROOT"/>
    <copydir src="src/webpages" dest="&tomcat_build;/webapps/ROOT"/>
    <javac srcdir="src/webpages/WEB-INF/classes"
           destdir="&tomcat_build;/webapps/ROOT/WEB-INF/classes"
           classpath="&tomcat_build;/classes"/>

    <!-- admin context -->
    <mkdir dir="&tomcat_build;/webapps/admin"/>
    <copydir src="src/admin" dest="&tomcat_build;/webapps/admin"/>
    <javac srcdir="src/admin/WEB-INF/classes"
           destdir="&tomcat_build;/webapps/admin/WEB-INF/classes"
           classpath="&tomcat_build;/classes"/>

    <!-- Test application -->
    <mkdir dir="&tomcat_build;/webapps/test"/>
    <copydir src="src/tests/webpages" dest="&tomcat_build;/webapps/test"/>
    <javac srcdir="src/tests/webpages/WEB-INF/classes"
           destdir="&tomcat_build;/webapps/test/WEB-INF/classes"
           classpath="&tomcat_build;/classes"/>
  </target>


  <!-- ==================== Copy the files to distribution format ==================== -->
  <target name="dist" depends="main,webapps">

    <mkdir dir="&tomcat_home;"/>
    <copydir src="&tomcat_build;" dest="&tomcat_home;"/>

    <!-- create tomcat jar files -->
    <jar jarfile="&tomcat_home;/lib/webserver.jar"
         basedir="&tomcat_home;/classes"
         includes="org/apache/tomcat/**"/> 
    <jar jarfile="&tomcat_home;/lib/servlet.jar"
         basedir="&tomcat_home;/classes"
         includes="javax/servlet/**"/>
    <jar jarfile="&tomcat_home;/lib/jasper.jar"
         basedir="&tomcat_home;/classes"
         includes="org/apache/jasper/**"/>

    <!-- Add Tomcat internal javadoc -->
    <mkdir dir="&tomcat_home;/webapps/ROOT/javadoc" />
    <javadoc packagenames="org.apache.tomcat.core"
             sourcepath="src/share"
             destdir="&tomcat_home;/webapps/ROOT/javadoc"
             author="true"
             version="true"
             use="true"
             windowtitle="Tomcat internal API"
             doctitle="Tomcat internal"
             bottom="Copyright &#169; 2000 Apache Software Foundation. All Rights Reserved."
    />

    <deltree dir="&tomcat_home;/classes"/>


    <!-- create webapp WARS -->
    <jar   jarfile="&tomcat_home;/webapps/examples.war"
           basedir="&tomcat_home;/webapps/examples"
           includes="**" /> 
    <deltree dir="&tomcat_home;/webapps/examples"/>

    <jar   jarfile="&tomcat_home;/webapps/admin.war"
           basedir="&tomcat_home;/webapps/admin"
           includes="**" /> 
    <deltree dir="&tomcat_home;/webapps/admin"/>

    <jar   jarfile="&tomcat_home;/webapps/ROOT.war"
           basedir="&tomcat_home;/webapps/ROOT"
           includes="**" />
    <deltree dir="&tomcat_home;/webapps/ROOT"/>

    <jar   jarfile="&tomcat_home;/webapps/test.war"
           basedir="&tomcat_home;/webapps/test"
           includes="**" /> 
    <deltree dir="&tomcat_home;/webapps/test"/>

    <!-- Change permissions for unix -->
    <chmod perm="+x" src="&tomcat_home;/bin/tomcat.sh"/>
    <chmod perm="+x" src="&tomcat_home;/bin/jspc.sh"/>
    <chmod perm="+x" src="&tomcat_home;/bin/startup.sh"/>
    <chmod perm="+x" src="&tomcat_home;/bin/shutdown.sh"/>
    <chmod perm="+x" src="&tomcat_home;/bin/test-tomcat.sh"/>
  </target>
 
  <!-- =================================================================== -->
  <!-- Packages the distribution with ZIP                                  -->
  <!-- =================================================================== -->
  <target name="dist-zip" depends="dist">
    <zip zipfile="&app_name;-&app_version;.zip" basedir="&tomcat_home;" includes="**"/>
  </target>

  

  <!-- ==================== Admin ==================== -->
  <target name="clean">
    <deltree dir="&tomcat_build;"/>
    <deltree dir="&tomcat_home;"/>
  </target>
  
  <target name="all" depends="clean,dist"/>
  <target name="main" depends="tomcat,webapps"/>
  
</project>
