<?xml version="1.0"?>

<!--
/*
 * $RCSfile$
 *
 * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
 *
 * Use is subject to license terms.
 *
 * $Revision$
 * $Date$
 * $State$
 */
 -->

<!-- Ant file for building java classes and jar files -->
<project name="Java 3D" default="jar-debug">

  <path id="vecmath.debug.classpath">
    <pathelement location="${vecmath_home}/build/debug/lib/ext/vecmath.jar"/>
  </path>

  <path id="vecmath.opt.classpath">
    <pathelement location="${vecmath_home}/build/opt/lib/ext/vecmath.jar"/>
  </path>

  <target name="compile-debug">

    <!-- Create the debug build directory structure used for compile -->
    <mkdir dir="${build}/${platform}/debug/classes"/>

    <!-- Create the directories used for compiling generated files -->
    <mkdir dir="${build-debug-gen}/tools"/>
    <mkdir dir="${build-debug-gen}/classes/javax/media/j3d"/>

    <!-- Copy VersionInfo.java file and change tags for this build -->
    <copy file="${build-tools}/VersionInfo.java"
          todir="${build-debug-gen}/classes/javax/media/j3d"
          overwrite="true">
        <filterset>
            <filter token="BUILD_TYPE" value="${build.type}"/>
            <filter token="BUILDTIME" value="${buildtime}"/>
            <filter token="BUILDTIME_VERBOSE" value="${buildtime_verbose}"/>
            <filter token="IS_DEBUG" value="true"/>
            <filter token="IS_DEV_PHASE" value="true"/>
            <filter token="IS_PRODUCTION" value="${is_production}"/>
            <filter token="USE_VERBOSE_BUILDTIME" value="${use_verbose_buildtime}"/>
            <filter token="VERSION_BASE" value="${version_base}"/>
            <filter token="VERSION_BUILD" value="${version_build}"/>
            <filter token="VERSION_SUFFIX" value="${version_suffix}"/>
        </filterset>
    </copy>

    <!-- Compile the java code from ${src} into ${build}/${platform}/debug/classes -->
    <javac srcdir="${src}/classes/share:${src}/classes/${wstype}:${jogl.pipeline.srcdir}:${core_utils_src}/classes/share:${build-debug-gen}/classes"
           destdir="${build}/${platform}/debug/classes"
	   source="1.5"
	   target="1.5"
	   debug="true"
           deprecation="off"
           excludes="${javac.excludes}">
	   <classpath refid="vecmath.debug.classpath"/>
    </javac>

    <!-- Copy the I18N property files while retaining package location -->
    <copy todir="${build}/${platform}/debug/classes">
        <fileset dir="${src}/classes/share" includes="**/*.properties"/>
        <fileset dir="${core_utils_src}/classes/share" includes="**/*.properties"/>
    </copy>
  </target>

  <target name="compile-opt">

    <!-- Create the opt build directory structure used for compile -->
    <mkdir dir="${build}/${platform}/opt/classes"/>

    <!-- Create the directories used for compiling generated files -->
    <mkdir dir="${build-opt-gen}/tools"/>
    <mkdir dir="${build-opt-gen}/classes/javax/media/j3d"/>

    <!-- Copy VersionInfo.java file and change tags for this build -->
    <copy file="${build-tools}/VersionInfo.java"
          todir="${build-opt-gen}/classes/javax/media/j3d"
          overwrite="true">
        <filterset>
            <filter token="BUILD_TYPE" value="${build.type}"/>
            <filter token="BUILDTIME" value="${buildtime}"/>
            <filter token="BUILDTIME_VERBOSE" value="${buildtime_verbose}"/>
            <filter token="IS_DEBUG" value="false"/>
            <filter token="IS_DEV_PHASE" value="${is_dev_phase}"/>
            <filter token="IS_PRODUCTION" value="${is_production}"/>
            <filter token="USE_VERBOSE_BUILDTIME" value="${use_verbose_buildtime}"/>
            <filter token="VERSION_BASE" value="${version_base}"/>
            <filter token="VERSION_BUILD" value="${version_build}"/>
            <filter token="VERSION_SUFFIX" value="${version_suffix}"/>
        </filterset>
    </copy>

    <!-- Compile the java code from ${src} into ${build}/${platform}/opt/classes -->
   <javac srcdir="${src}/classes/share:${src}/classes/${wstype}:${jogl.pipeline.srcdir}:${core_utils_src}/classes/share:${build-opt-gen}/classes"            destdir="${build}/${platform}/opt/classes"
           source="1.5"
           target="1.5"
           debug="true"
           debuglevel="lines,source"
           deprecation="off"
           excludes="${javac.excludes}">
           <classpath refid="vecmath.opt.classpath"/>
    </javac>
                                                                                                     
    <!-- Copy the I18N property files while retaining package location -->
    <copy todir="${build}/${platform}/opt/classes">
        <fileset dir="${src}/classes/share" includes="**/*.properties"/>
        <fileset dir="${core_utils_src}/classes/share" includes="**/*.properties"/>
    </copy>
  </target>


  <target name="jar-debug" depends="jar-debug-impl,copy-default-debug"/>

  <target name="jar-debug-impl">
    <!-- Create the j3dcore and j3dutils jars directory -->
    <mkdir dir="${build}/${platform}/debug/lib/ext"/>

    <copy todir="${build-debug-gen}"
          overwrite="true">
        <fileset dir="${src}/classes" includes="J3dVersion"/>
        <fileset dir="${core_utils_src}/classes" includes="ToolsVersion"/>
        <filterset>
            <filter token="VERSION_BASE" value="${version_base}"/>
        </filterset>
    </copy>

    <!-- Copy the copyright file and all license files for j3dcore.jar -->
    <copy todir="${build}/${platform}/debug/classes/javax">
      <fileset dir="${src}/.." includes="COPYRIGHT.txt"/>
      <fileset dir="${src}/.." includes="*LICENSE*.txt"/>
    </copy>

    <!-- Copy the copyright file and all license files for j3dutils.jar -->
    <copy todir="${build}/${platform}/debug/classes/com">
      <fileset dir="${core_utils_home}" includes="COPYRIGHT.txt"/>
      <fileset dir="${core_utils_home}" includes="*LICENSE*.txt"/>
    </copy>

    <!-- Put everything in ${build}/${platform}/debug/classes/javax into the j3dcore.jar file -->
    <jar jarfile="${build}/${platform}/debug/lib/ext/j3dcore.jar"
         manifest="${build-debug-gen}/J3dVersion" update="no"
	 compress="false">
	<fileset dir="${build}/${platform}/debug/classes" includes="javax/**/*"/>
    </jar>

    <!-- Put everything in ${build}/${platform}/debug/classes/com into the j3dutils.jar file -->
    <jar jarfile="${build}/${platform}/debug/lib/ext/j3dutils.jar"
         manifest="${build-debug-gen}/ToolsVersion" update="no"
 	 compress="false">
	<fileset dir="${build}/${platform}/debug/classes" includes="com/**/*"/>
    </jar>
  </target>

  <target name="copy-default-debug" unless="build.concurrent">
    <!-- Copy platform-specific jar and native files to "default" directory -->
    <delete dir="${build}/default/debug" quiet="true"/>
    <mkdir dir="${build}/default/debug/native"/>
    <copy todir="${build}/default/debug" overwrite="true">
      <fileset dir="${build}/${platform}/debug" includes="lib/ext/**/*.jar"/>
    </copy>
    <copy todir="${build}/default/debug/native" overwrite="true" includeemptydirs="false" flatten="true">
      <fileset dir="${build}/${platform}/debug" includes="lib/** bin/**" excludes="**/*.jar"/>
    </copy>
  </target>

  <target name="jar-opt" depends="jar-opt-impl,copy-default-opt"/>

  <target name="jar-opt-impl">
    <!-- Create the j3dcore and j3dutils jars directory -->
    <mkdir dir="${build}/${platform}/opt/lib/ext"/>

    <copy todir="${build-opt-gen}"
          overwrite="true">
        <fileset dir="${src}/classes" includes="J3dVersion"/>
        <fileset dir="${core_utils_src}/classes" includes="ToolsVersion"/>
        <filterset>
            <filter token="VERSION_BASE" value="${version_base}"/>
        </filterset>
    </copy>
                                                                                                     
    <!-- Copy the copyright file and all license files for j3dcore.jar -->
    <copy todir="${build}/${platform}/opt/classes/javax">
      <fileset dir="${src}/.." includes="COPYRIGHT.txt"/>
      <fileset dir="${src}/.." includes="*LICENSE*.txt"/>
    </copy>

    <!-- Copy the copyright file and all license files for j3dutils.jar -->
    <copy todir="${build}/${platform}/opt/classes/com">
      <fileset dir="${core_utils_home}" includes="COPYRIGHT.txt"/>
      <fileset dir="${core_utils_home}" includes="*LICENSE*.txt"/>
    </copy>

    <!-- Put everything in ${build}/${platform}/opt/classes/javax into the j3dcore.jar file -->
    <jar jarfile="${build}/${platform}/opt/lib/ext/j3dcore.jar"
         manifest="${build-opt-gen}/J3dVersion" update="no"
	 compress="false">
	<fileset dir="${build}/${platform}/opt/classes" includes="javax/**/*"/>
    </jar>

    <!-- Put everything in ${build}/${platform}/opt/classes/com into the j3dutils.jar file -->
    <jar jarfile="${build}/${platform}/opt/lib/ext/j3dutils.jar"
         manifest="${build-opt-gen}/ToolsVersion" update="no"
         compress="false">
        <fileset dir="${build}/${platform}/opt/classes" includes="com/**/*"/>
    </jar>
  </target>

  <target name="copy-default-opt" unless="build.concurrent">
    <!-- Copy platform-specific jar and native files to "default" directory -->
    <delete dir="${build}/default/opt" quiet="true"/>
    <mkdir dir="${build}/default/opt/native"/>
    <copy todir="${build}/default/opt" overwrite="true">
      <fileset dir="${build}/${platform}/opt" includes="lib/ext/**/*.jar"/>
    </copy>
    <copy todir="${build}/default/opt/native" overwrite="true" includeemptydirs="false" flatten="true">
      <fileset dir="${build}/${platform}/opt" includes="lib/** bin/**" excludes="**/*.jar"/>
    </copy>
  </target>

  <target name="setup-docs">
    <property name="javadoc.bottom"
       value="&lt;font size=&quot;-1&quot;&gt;Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved. Use is subject to &lt;a href=&quot;{@docRoot}/LICENSE-SPEC.html&quot;&gt;license terms&lt;/a&gt;."/>
  </target>

  <target name="docs-jcp" depends="setup-docs">
    <!-- Create the build directory structure used by docs -->
    <mkdir dir="${build}/${platform}/javadocs/docs-jcp"/>

    <!-- Compile the javadoc from ${src} into ${build}/javadocs -->
    <javadoc packagenames="javax.media.j3d.*,
                           javax.vecmath.*"
             maxmemory="128m"
             destdir="${build}/${platform}/javadocs/docs-jcp"
	     bottom="${javadoc.bottom}"
             windowtitle="Java 3D ${version}">
	     <sourcepath>
		<pathelement location="${src}/classes/share"/>
		<pathelement location="${src}/classes/${wstype}"/>
		<pathelement location="${core_utils_src}/classes/share"/>
		<pathelement location="${vecmath_src}"/>
             </sourcepath>
    </javadoc>

    <!-- Copy the copyright and license files -->
    <copy todir="${build}/${platform}/javadocs/docs-jcp">
      <fileset dir="${src}/.." includes="COPYRIGHT.txt"/>
      <fileset dir="${src}/.." includes="LICENSE-SPEC.html"/>
    </copy>
  </target>

  <target name="docs-private" depends="setup-docs">
    <!-- Create the build directory structure used by docs -->
    <mkdir dir="${build}/${platform}/javadocs/docs-private"/>

    <!--
      ** TODO: there is an implicit dependency on "compile-opt",
      ** since the J3dBuildInfo source file is only built as part of
      ** that target. We don't want to make this an explicit
      ** dependency because we don't want the time stamp regenerated.
      **
      ** Ideally, we should make a "time-stamp-opt" target that only
      ** creates J3DBuildInfo.java if it doesn't exist, and a
      ** "force-time-stamp-opt" target that unconditionally creates
      ** it. The "docs-*" targets would depend on "time-stamp-opt"
      ** while the "compile-opt" target would depend on
      ** "force-time-stamp-opt"
      -->

    <!-- Compile the javadoc from ${src} into ${build}/javadocs -->
    <javadoc packagenames="javax.media.j3d.*,
                           com.sun.j3d.*,
                           javax.vecmath.*"
             maxmemory="128m"
	     private="true"
             destdir="${build}/${platform}/javadocs/docs-private"
	     bottom="${javadoc.bottom}"
             windowtitle="Java 3D ${version}">
	     <sourcepath>
		<pathelement location="${src}/classes/share"/>
		<pathelement location="${src}/classes/${wstype}"/>
		<pathelement location="${build}/${platform}/opt/gen/classes"/>
		<pathelement location="${core_utils_src}/classes/share"/>
		<pathelement location="${vecmath_src}"/>
             </sourcepath>
    </javadoc>

    <!-- Copy the copyright and license files -->
    <copy todir="${build}/${platform}/javadocs/docs-private">
      <fileset dir="${src}/.." includes="COPYRIGHT.txt"/>
      <fileset dir="${src}/.." includes="LICENSE-SPEC.html"/>
    </copy>
  </target>

  <target name="docs-public" depends="setup-docs">
    <!-- Create the build directory structure used by docs -->
    <mkdir dir="${build}/${platform}/javadocs/docs-public"/>

    <!-- Compile the javadoc from ${src} into ${build}/javadocs -->
    <javadoc packagenames="javax.media.j3d.*,
			   com.sun.j3d.audioengines.*,
                           com.sun.j3d.exp.*,
			   com.sun.j3d.loaders.*,
			   com.sun.j3d.utils.*,
                           javax.vecmath.*"
             excludepackagenames="com.sun.j3d.utils.scenegraph.io.retained,
			   com.sun.j3d.exp.swing.impl,
			   com.sun.j3d.utils.scenegraph.io.state.*"
             maxmemory="128m"
             destdir="${build}/${platform}/javadocs/docs-public"
	     bottom="${javadoc.bottom}"
             windowtitle="Java 3D ${version}">
	     <sourcepath>
		<pathelement location="${src}/classes/share"/>
		<pathelement location="${src}/classes/${wstype}"/>
		<pathelement location="${core_utils_src}/classes/share"/>
		<pathelement location="${vecmath_src}"/>
             </sourcepath>
    </javadoc>

    <!-- Copy the copyright and license files -->
    <copy todir="${build}/${platform}/javadocs/docs-public">
      <fileset dir="${src}/.." includes="COPYRIGHT.txt"/>
      <fileset dir="${src}/.." includes="LICENSE-SPEC.html"/>
    </copy>
  </target>

  <target name="docs" depends="docs-jcp,docs-public,docs-private"/>

  <target name="dist">
    <!-- Create the distribution directory -->
    <mkdir dir="${dist}/${platform}/lib/ext"/>

    <!-- Copy the jar files -->
    <copy todir="${dist}/${platform}/lib/ext">
      <fileset dir="${build}/${platform}/opt/lib/ext" includes="*.jar"/>
      <fileset dir="${vecmath_home}/build/opt/lib/ext" includes="vecmath.jar"/>
    </copy>

    <!-- Create the docs distribution directory -->
    <mkdir dir="${dist}/${platform}/javadocs"/>

    <!-- Put everything in ${build}/javadocs into the zip docname file -->
    <zip zipfile="${dist}/${platform}/javadocs/${docname}.zip" 
	 basedir="${build}/${platform}/javadocs/docs-public"/>
  </target>

  <target name="install-debug">
    <copy todir="${java.home}/lib/ext">
        <fileset dir="${build}/${platform}/debug/lib/ext" includes="*.jar"/>
        <fileset dir="${vecmath_home}/build/debug/lib/ext" includes="vecmath.jar"/>
    </copy>
    <copy todir="${java.home}/${install.bin}">
       <fileset dir="${build}/${platform}/debug/${install.bin}" includes="*"/>
    </copy>
  </target>
 
  <target name="install-opt">
    <copy todir="${java.home}/lib/ext">
        <fileset dir="${build}/${platform}/opt/lib/ext" includes="*.jar"/>
        <fileset dir="${vecmath_home}/build/opt/lib/ext" includes="vecmath.jar"/>
    </copy>
    <copy todir="${java.home}/${install.bin}">
       <fileset dir="${build}/${platform}/opt/${install.bin}" includes="*"/>
    </copy>
  </target>
 
  <target name="uninstall">
    <delete>
        <fileset dir="${java.home}/lib/ext" includes="j3dcore.jar, j3dutils.jar, vecmath.jar"/>
    </delete>
    <delete>
       <fileset dir="${java.home}/${install.bin}" includes="libj3dcore*.so"/>
       <fileset dir="${java.home}/${install.bin}" includes="j3dcore*.dll"/>
    </delete>
  </target>
 
</project>