<?xml version="1.0"?>

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

<!-- Ant file for building native files -->
<project name="Java 3D" default="compile-opt">

  <target name="nativeSetup-debug-solaris" if="isSolarisOnSparc">
	<property name="bldFlag" value="g"/>
	<property name="coreLibDependency" value="lib/sparc/libj3dcore-ogl.so"/>
	<property name="coreUtilsLibDependency" value="lib/sparc/libj3dutils.so"/>
  </target>

  <target name="nativeSetup-debug-linux" if="isLinuxOnX86">
	<property name="bldFlag" value="g"/>
	<property name="coreLibDependency" value="lib/i386/libj3dcore-ogl.so"/>
	<property name="coreUtilsLibDependency" value="lib/i386/libj3dutils.so"/>
  </target>

  <target name="nativeSetup-debug-linux-amd64" if="isLinuxOnAmd64">
	<property name="bldFlag" value="g -fPIC -march=k8 -msse2 -mfpmath=sse"/>
	<property name="coreLibDependency" value="lib/amd64/libj3dcore-ogl.so"/>
	<property name="coreUtilsLibDependency" value="lib/amd64/libj3dutils.so"/>
  </target>

  <target name="nativeSetup-debug-linux-ia64" if="isLinuxOnIA64">
	<property name="bldFlag" value="g"/>
	<property name="coreLibDependency" value="lib/ia64/libj3dcore-ogl.so"/>
	<property name="coreUtilsLibDependency" value="lib/ia64/libj3dutils.so"/>
  </target>

  <target name="nativeSetup-debug-win32" if="isWindowsOnX86">
	<property name="bldFlag" 
	         value="-DWIN32 -DDEBUG -D_WINDOWS"/>
	<property name="coreLibDependency" value="bin/j3dcore-${build.rend}.dll"/>
	<property name="coreUtilsLibDependency" value="bin/j3dutils.dll"/>
  </target>


  <target name="nativeSetup-debug" depends="nativeSetup-debug-solaris, nativeSetup-debug-linux, nativeSetup-debug-linux-amd64, nativeSetup-debug-linux-ia64, nativeSetup-debug-win32">
	<property name="bldType" value="debug"/>
	<property name="javahCoreSrc"     
	 location="${src}/classes/share/javax/media/j3d"/>
  	<property name="javahCoreTarget"  
	 location="${build}/${platform}/${bldType}/native/javah/j3dcore"/>
  	<property name="javahUtilsSrc"
	 location="${core_utils_src}/classes/share/com/sun/j3d/utils/timer"/>
  	<property name="javahUtilsTarget"
	 location="${build}/${platform}/${bldType}/native/javah/j3dutils"/>
  </target>

  <target name="nativeSetup-opt-solaris" if="isSolarisOnSparc">
	<property name="bldFlag" value="O"/>
	<property name="coreLibDependency" value="lib/sparc/libj3dcore-ogl.so"/>
	<property name="coreUtilsLibDependency" value="lib/sparc/libj3dutils.so"/>
  </target>

  <target name="nativeSetup-opt-linux" if="isLinuxOnX86">
	<property name="bldFlag" value="O"/>
	<property name="coreLibDependency" value="lib/i386/libj3dcore-ogl.so"/>
	<property name="coreUtilsLibDependency" value="lib/i386/libj3dutils.so"/>
  </target>

  <target name="nativeSetup-opt-linux-amd64" if="isLinuxOnAmd64">
	<property name="bldFlag" value="O -fPIC -march=k8 -msse2 -mfpmath=sse"/>
	<property name="coreLibDependency" value="lib/amd64/libj3dcore-ogl.so"/>
	<property name="coreUtilsLibDependency" value="lib/amd64/libj3dutils.so"/>
  </target>

  <target name="nativeSetup-opt-linux-ia64" if="isLinuxOnIA64">
	<property name="bldFlag" value="O"/>
	<property name="coreLibDependency" value="lib/ia64/libj3dcore-ogl.so"/>
	<property name="coreUtilsLibDependency" value="lib/ia64/libj3dutils.so"/>
  </target>

  <target name="nativeSetup-opt-win32" if="isWindowsOnX86">
	<property name="bldFlag" 
	         value="-DWIN32 -DNDEBUG -D_WINDOWS"/>
	<property name="coreLibDependency" value="bin/j3dcore-${build.rend}.dll"/>
	<property name="coreUtilsLibDependency" value="bin/j3dutils.dll"/>
  </target>

  <target name="nativeSetup-opt" depends="nativeSetup-opt-solaris, nativeSetup-opt-linux, nativeSetup-opt-linux-amd64, nativeSetup-opt-linux-ia64, nativeSetup-opt-win32">
	<property name="bldType" value="opt"/>
	<property name="javahCoreSrc"     
	 location="${src}/classes/share/javax/media/j3d"/>
  	<property name="javahCoreTarget"
  	 location="${build}/${platform}/${bldType}/native/javah/j3dcore"/>
  	<property name="javahUtilsSrc"
	 location="${core_utils_src}/classes/share/com/sun/j3d/utils/timer"/>
	<property name="javahUtilsTarget"
	 location="${build}/${platform}/${bldType}/native/javah/j3dutils"/>
  </target>

  <target name="dependencyCheck">

     <!-- ==== source/target out-of-date checking for JNI header files ==== -->
       <condition property="javahBuild.notRequired"> 
       	  <and>
	    <uptodate
     	     srcfile="${javahCoreSrc}/Background.java"
    	     targetfile="${javahCoreTarget}/javax_media_j3d_Background.h"/>
	    <uptodate
     	     srcfile="${javahCoreSrc}/Canvas3D.java"
    	     targetfile="${javahCoreTarget}/javax_media_j3d_Canvas3D.h"/>
	    <uptodate
     	     srcfile="${javahCoreSrc}/ColoringAttributes.java"
    	     targetfile="${javahCoreTarget}/javax_media_j3d_ColoringAttributes.h"/>
	    <uptodate
     	     srcfile="${javahCoreSrc}/ColoringAttributesRetained.java"
    	     targetfile="${javahCoreTarget}/javax_media_j3d_ColoringAttributesRetained.h"/>
	    <uptodate
     	     srcfile="${javahCoreSrc}/CompressedGeometryRetained.java"
    	     targetfile="${javahCoreTarget}/javax_media_j3d_CompressedGeometryRetained.h"/>
	    <uptodate
     	     srcfile="${javahCoreSrc}/DepthComponentRetained.java"
    	     targetfile="${javahCoreTarget}/javax_media_j3d_DepthComponentRetained.h"/>
	    <uptodate
     	     srcfile="${javahCoreSrc}/DetailTextureImage.java"
    	     targetfile="${javahCoreTarget}/javax_media_j3d_DetailTextureImage.h"/>
	    <uptodate
     	     srcfile="${javahCoreSrc}/DirectionalLightRetained.java"
    	     targetfile="${javahCoreTarget}/javax_media_j3d_DirectionalLightRetained.h"/>
	    <uptodate
     	     srcfile="${javahCoreSrc}/DisplayListRenderMethod.java"
    	     targetfile="${javahCoreTarget}/javax_media_j3d_DisplayListRenderMethod.h"/>
	    <uptodate
     	     srcfile="${javahCoreSrc}/DrawingSurfaceObjectAWT.java"
    	     targetfile="${javahCoreTarget}/javax_media_j3d_DrawingSurfaceObjectAWT.h"/>
	    <uptodate
     	     srcfile="${javahCoreSrc}/ExponentialFogRetained.java"
    	     targetfile="${javahCoreTarget}/javax_media_j3d_ExponentialFogRetained.h"/>
	    <uptodate
     	     srcfile="${javahCoreSrc}/GeometryArray.java"
    	     targetfile="${javahCoreTarget}/javax_media_j3d_GeometryArray.h"/>
	    <uptodate
     	     srcfile="${javahCoreSrc}/GeometryArrayRetained.java"
    	     targetfile="${javahCoreTarget}/javax_media_j3d_GeometryArrayRetained.h"/>
	    <uptodate
     	     srcfile="${javahCoreSrc}/GeometryRetained.java"
    	     targetfile="${javahCoreTarget}/javax_media_j3d_GeometryRetained.h"/>
	    <uptodate
     	     srcfile="${javahCoreSrc}/GraphicsContext3D.java"
    	     targetfile="${javahCoreTarget}/javax_media_j3d_GraphicsContext3D.h"/>
	    <uptodate
     	     srcfile="${javahCoreSrc}/ImageComponent.java"
    	     targetfile="${javahCoreTarget}/javax_media_j3d_ImageComponent.h"/>
	    <uptodate
     	     srcfile="${javahCoreSrc}/ImageComponent2DRetained.java"
    	     targetfile="${javahCoreTarget}/javax_media_j3d_ImageComponent2DRetained.h"/>
	    <uptodate
     	     srcfile="${javahCoreSrc}/ImageComponentRetained.java"
    	     targetfile="${javahCoreTarget}/javax_media_j3d_ImageComponentRetained.h"/>
	    <uptodate
     	     srcfile="${javahCoreSrc}/IndexedGeometryArrayRetained.java"
    	     targetfile="${javahCoreTarget}/javax_media_j3d_IndexedGeometryArrayRetained.h"/>
	    <uptodate
     	     srcfile="${javahCoreSrc}/LineAttributes.java"
    	     targetfile="${javahCoreTarget}/javax_media_j3d_LineAttributes.h"/>
	    <uptodate
     	     srcfile="${javahCoreSrc}/LineAttributesRetained.java"
    	     targetfile="${javahCoreTarget}/javax_media_j3d_LineAttributesRetained.h"/>
	    <uptodate
     	     srcfile="${javahCoreSrc}/LinearFogRetained.java"
    	     targetfile="${javahCoreTarget}/javax_media_j3d_LinearFogRetained.h"/>
	    <uptodate
     	     srcfile="${javahCoreSrc}/MasterControl.java"
    	     targetfile="${javahCoreTarget}/javax_media_j3d_MasterControl.h"/>
	    <uptodate
     	     srcfile="${javahCoreSrc}/Material.java"
    	     targetfile="${javahCoreTarget}/javax_media_j3d_Material.h"/>
	    <uptodate
     	     srcfile="${javahCoreSrc}/MaterialRetained.java"
    	     targetfile="${javahCoreTarget}/javax_media_j3d_MaterialRetained.h"/>
	    <uptodate
     	     srcfile="${javahCoreSrc}/ModelClipRetained.java"
    	     targetfile="${javahCoreTarget}/javax_media_j3d_ModelClipRetained.h"/>
	    <uptodate
     	     srcfile="${src}/classes/${ostype}/javax/media/j3d/NativeConfigTemplate3D.java"
    	     targetfile="${javahCoreTarget}/javax_media_j3d_NativeConfigTemplate3D.h"/>
	    <uptodate
     	     srcfile="${javahCoreSrc}/NodeRetained.java"
    	     targetfile="${javahCoreTarget}/javax_media_j3d_NodeRetained.h"/>
	    <uptodate
     	     srcfile="${javahCoreSrc}/PointAttributesRetained.java"
    	     targetfile="${javahCoreTarget}/javax_media_j3d_PointAttributesRetained.h"/>
	    <uptodate
     	     srcfile="${javahCoreSrc}/PointLightRetained.java"
    	     targetfile="${javahCoreTarget}/javax_media_j3d_PointLightRetained.h"/>
	    <uptodate
     	     srcfile="${javahCoreSrc}/PolygonAttributes.java"
    	     targetfile="${javahCoreTarget}/javax_media_j3d_PolygonAttributes.h"/>
	    <uptodate
     	     srcfile="${javahCoreSrc}/PolygonAttributesRetained.java"
    	     targetfile="${javahCoreTarget}/javax_media_j3d_PolygonAttributesRetained.h"/>
	    <uptodate
     	     srcfile="${javahCoreSrc}/Raster.java"
    	     targetfile="${javahCoreTarget}/javax_media_j3d_Raster.h"/>
	    <uptodate
     	     srcfile="${javahCoreSrc}/RasterRetained.java"
    	     targetfile="${javahCoreTarget}/javax_media_j3d_RasterRetained.h"/>
	    <uptodate
     	     srcfile="${javahCoreSrc}/RenderMolecule.java"
    	     targetfile="${javahCoreTarget}/javax_media_j3d_RenderMolecule.h"/>
	    <uptodate
     	     srcfile="${javahCoreSrc}/Renderer.java"
    	     targetfile="${javahCoreTarget}/javax_media_j3d_Renderer.h"/>
	    <uptodate
     	     srcfile="${javahCoreSrc}/RenderingAttributes.java"
    	     targetfile="${javahCoreTarget}/javax_media_j3d_RenderingAttributes.h"/>
	    <uptodate
     	     srcfile="${javahCoreSrc}/RenderingAttributesRetained.java"
    	     targetfile="${javahCoreTarget}/javax_media_j3d_RenderingAttributesRetained.h"/>
	    <uptodate
     	     srcfile="${javahCoreSrc}/SpotLightRetained.java"
    	     targetfile="${javahCoreTarget}/javax_media_j3d_SpotLightRetained.h"/>
	    <uptodate
     	     srcfile="${javahCoreSrc}/TexCoordGeneration.java"
    	     targetfile="${javahCoreTarget}/javax_media_j3d_TexCoordGeneration.h"/>
	    <uptodate
     	     srcfile="${javahCoreSrc}/TexCoordGenerationRetained.java"
    	     targetfile="${javahCoreTarget}/javax_media_j3d_TexCoordGenerationRetained.h"/>
	    <uptodate
     	     srcfile="${javahCoreSrc}/Texture.java"
    	     targetfile="${javahCoreTarget}/javax_media_j3d_Texture.h"/>
	    <uptodate
     	     srcfile="${javahCoreSrc}/Texture2D.java"
    	     targetfile="${javahCoreTarget}/javax_media_j3d_Texture2D.h"/>
	    <uptodate
     	     srcfile="${javahCoreSrc}/Texture2DRetained.java"
    	     targetfile="${javahCoreTarget}/javax_media_j3d_Texture2DRetained.h"/>
	    <uptodate
     	     srcfile="${javahCoreSrc}/Texture3DRetained.java"
    	     targetfile="${javahCoreTarget}/javax_media_j3d_Texture3DRetained.h"/>
	    <uptodate
     	     srcfile="${javahCoreSrc}/TextureAttributes.java"
    	     targetfile="${javahCoreTarget}/javax_media_j3d_TextureAttributes.h"/>
	    <uptodate
     	     srcfile="${javahCoreSrc}/TextureAttributesRetained.java"
    	     targetfile="${javahCoreTarget}/javax_media_j3d_TextureAttributesRetained.h"/>
	    <uptodate
     	     srcfile="${javahCoreSrc}/TextureCubeMapRetained.java"
    	     targetfile="${javahCoreTarget}/javax_media_j3d_TextureCubeMapRetained.h"/>
	    <uptodate
     	     srcfile="${javahCoreSrc}/TextureRetained.java"
    	     targetfile="${javahCoreTarget}/javax_media_j3d_TextureRetained.h"/>
	    <uptodate
     	     srcfile="${javahCoreSrc}/TextureUnitStateRetained.java"
    	     targetfile="${javahCoreTarget}/javax_media_j3d_TextureUnitStateRetained.h"/>
	    <uptodate
     	     srcfile="${javahCoreSrc}/TransparencyAttributes.java"
    	     targetfile="${javahCoreTarget}/javax_media_j3d_TransparencyAttributes.h"/>
	    <uptodate
     	     srcfile="${javahCoreSrc}/TransparencyAttributesRetained.java"
    	     targetfile="${javahCoreTarget}/javax_media_j3d_TransparencyAttributesRetained.h"/>
	    <uptodate
     	     srcfile="${javahUtilsSrc}/J3DTimer.java"
    	     targetfile="${javahUtilsTarget}/com_sun_j3d_utils_timer_J3DTimer.h"/>
	  </and>
       </condition>
       <echo message="javahBuild.notRequired = ${javahBuild.notRequired}"/>

     <!-- ==== source/target out-of-date checking for JNI header files ==== -->
     <!-- ==== and obj files                                           ==== -->	
       <condition property="nativeOGLBuild.notRequired"> 
       	  <and>
	    <istrue value="${javahBuild.notRequired}"/>
	    <uptodate>
    	      <srcfiles dir= "${src}/native/${build.rend}" includes="*.c,*.h,*.cpp,*.hpp"/>
    	      <mapper type="merge" from="*.c,*.h,*.cpp,*.hpp" 
		      to="${build}/${platform}/${bldType}/${coreLibDependency}"/>
            </uptodate>
	    <uptodate>
    	      <srcfiles dir= "${core_utils_src}/native/share" includes="*.c,*.h,*.cpp,*.hpp"/>
    	      <mapper type="merge" from="*.c,*.h,*.cpp,*.hpp" 
		      to="${build}/${platform}/${bldType}/${coreUtilsLibDependency}"/>
            </uptodate>
	  </and>
       </condition>
       <echo message="nativeOGLBuild.notRequired = ${nativeOGLBuild.notRequired}"/>
  </target>

  <target name="genJavah" unless="javahBuild.notRequired">

    <!-- Create the build directory structure used for JNI header -->
    <mkdir dir="${javahCoreTarget}"/>
    <mkdir dir="${javahUtilsTarget}"/>

    <!-- Generate JNI headers from ${build}/${platform}/${bldType}/classes -->
    <!-- into ${javahCoreTarget} -->
    <javah destdir="${javahCoreTarget}" force="yes">
	<classpath>
	    <pathelement path="${build}/${platform}/${bldType}/classes"/>
	</classpath>
	
	<class name="javax.media.j3d.Background"/>
	<class name="javax.media.j3d.Canvas3D"/>
	<class name="javax.media.j3d.ColoringAttributes"/>
	<class name="javax.media.j3d.ColoringAttributesRetained"/>
	<class name="javax.media.j3d.CompressedGeometryRetained"/>
	<class name="javax.media.j3d.DepthComponentRetained"/>
	<class name="javax.media.j3d.DetailTextureImage"/>
	<class name="javax.media.j3d.DirectionalLightRetained"/>
	<class name="javax.media.j3d.DisplayListRenderMethod"/>
	<class name="javax.media.j3d.DrawingSurfaceObjectAWT"/>
	<class name="javax.media.j3d.ExponentialFogRetained"/>
	<class name="javax.media.j3d.GeometryArray"/>
	<class name="javax.media.j3d.GeometryArrayRetained"/>
	<class name="javax.media.j3d.GeometryRetained"/>
	<class name="javax.media.j3d.GraphicsContext3D"/>
	<class name="javax.media.j3d.ImageComponent"/>
	<class name="javax.media.j3d.ImageComponent2DRetained"/>
	<class name="javax.media.j3d.ImageComponentRetained"/>
	<class name="javax.media.j3d.IndexedGeometryArrayRetained"/>
	<class name="javax.media.j3d.LineAttributes"/>
	<class name="javax.media.j3d.LineAttributesRetained"/>
	<class name="javax.media.j3d.LinearFogRetained"/>
	<class name="javax.media.j3d.MasterControl"/>
	<class name="javax.media.j3d.Material"/>
	<class name="javax.media.j3d.MaterialRetained"/>
	<class name="javax.media.j3d.ModelClipRetained"/>
	<class name="javax.media.j3d.NativeConfigTemplate3D"/>
	<class name="javax.media.j3d.NodeRetained"/>
	<class name="javax.media.j3d.PointAttributesRetained"/>
	<class name="javax.media.j3d.PointLightRetained"/>
	<class name="javax.media.j3d.PolygonAttributes"/>
	<class name="javax.media.j3d.PolygonAttributesRetained"/>
	<class name="javax.media.j3d.Raster"/>
	<class name="javax.media.j3d.RasterRetained"/>
	<class name="javax.media.j3d.RenderMolecule"/>
	<class name="javax.media.j3d.Renderer"/>
	<class name="javax.media.j3d.RenderingAttributes"/>
	<class name="javax.media.j3d.RenderingAttributesRetained"/>
	<class name="javax.media.j3d.SpotLightRetained"/>
	<class name="javax.media.j3d.TexCoordGeneration"/>
	<class name="javax.media.j3d.TexCoordGenerationRetained"/>
	<class name="javax.media.j3d.Texture"/>
	<class name="javax.media.j3d.Texture2D"/>
	<class name="javax.media.j3d.Texture2DRetained"/>
	<class name="javax.media.j3d.Texture3DRetained"/>
	<class name="javax.media.j3d.TextureAttributes"/>
	<class name="javax.media.j3d.TextureAttributesRetained"/>
	<class name="javax.media.j3d.TextureCubeMapRetained"/>
	<class name="javax.media.j3d.TextureRetained"/>
	<class name="javax.media.j3d.TextureUnitStateRetained"/>
	<class name="javax.media.j3d.TransparencyAttributes"/>
	<class name="javax.media.j3d.TransparencyAttributesRetained"/>

    </javah>

    <!-- Generate JNI headers from ${build}/${platform}/${bldType}/classes -->
    <!-- into ${javahUtilsTarget} -->
    <javah destdir="${javahUtilsTarget}" force="yes">
	<classpath>
	    <pathelement path="${build}/${platform}/${bldType}/classes"/>
	</classpath>
	<class name="com.sun.j3d.utils.timer.J3DTimer"/>
    </javah>

  </target>

  <target name="compile-debug" depends="nativeSetup-debug, dependencyCheck, genJavah" unless="nativeOGLBuild.notRequired">
	<ant antfile="build-${platform}.xml" dir="${build.rend}" target="compile"/>
	<ant antfile="build-${platform}.xml" dir="share" target="compile"/>
  </target>

  <target name="compile-opt" depends="nativeSetup-opt, dependencyCheck, genJavah" 
	  unless="nativeOGLBuild.notRequired">
	   <ant antfile="build-${platform}.xml" dir="${build.rend}" target="compile"/>
	   <ant antfile="build-${platform}.xml" dir="share" target="compile"/>
  </target>

  <target name="dist">
	   <ant antfile="build-${platform}.xml" dir="${build.rend}" target="dist"/>
	   <ant antfile="build-${platform}.xml" dir="share" target="dist"/>
  </target>

</project>