<?xml version="1.0" encoding="UTF-8"?>
<!--
   - Ant build for NEWT.  This build has been tested with ANT 1.7.0.  The
   - optional.jar that contains the optional ANT tasks must be in the ANT
   - classpath (typically the ant/lib directory).
   -
   - A clean download of NEWT is required for this build.
   -
   - This build has no dependence on environment variables; the needed
   - ones (e.g. java.home, ANT_HOME) are all set by the Ant wrapper shell
   - script, by the virtual machine, or elsewhere. However, on all platforms,
   - the C compiler and linker should be in the path. All other paths that
   - need to be set are in host.properties.
   -
   - NOTE:  because the GlueGen config files have their own relative paths
   -        which cannot be overridden by GlueGen, GlueGen MUST be run from
   -        the "make" directory. This also means that this build.xml MUST
   -        be run from the "make" directory.
   -
   - Public targets:
   -   all: (default; autodetects OS and chooses C compiler from newt.properties)
   -   clean:        clean all built
   -   javadoc:      create the standard developer Javadoc (recommended)
   -                 (Note: should build all first - may be dependence in the future)
   -   javadoc.spec: create the standard developer Javadoc but exclude com.jogamp.* classes
   -   javadoc.dev:  create the internal developer Javadoc.  This includes the
   -                       Java and C file generators. Note that it is only supported
   -                       to create the Javadoc for the platform on which you are
   -                       currently running.
   -
   - Note: on Windows the "win32.c.compiler" property in newt.properties
   - is required to select the appropriate C compiler. See the example
   - newt.properties in this directory for valid values. On Mac OS X
   - universal binaries may also be built by setting the "macosxfat"
   - property in newt.properties; again see the example file in this
   - directory.
   -
   - Thanks to Rob Grzywinski and Artur Biesiadowski for the bulk of the
   - ANT build, including the GlueGen and StaticGLInfo tasks, the building of
   - the Java generated sources, the first and second phase Java compiles, and
   - the building of the jar file. Thanks to Alex Radeski for the bulk of the
   - port to the ant-contrib CPPTask framework. Thanks to Athomas Goldberg for
   - the original OS detection code.
   -
   - Some environment defs affecting compilation

   - Internal settings, may not be necessary to set them manually,
     since all JAR archives are orthogonal.
       setup.noCDC
       setup.noAWT
       setup.noOpenGL

   - setup.nodesktop is set iff:
        !isWindows && !isOSX && !isX11

   -->
<project name="NEWT" basedir="." default="all">

    <import file="build-common.xml"/>

    <!-- ================================================================== -->
    <!--
       - Base initialization and detection of operating system.
      -->
    <target name="base.init" depends="common.init">

        <condition property="setup.nonatives">
            <and>
                <isfalse value="${isWindows}" />
                <isfalse value="${isOSX}" />
                <isfalse value="${isX11}" />
                <isfalse value="${useKD}" />
                <isfalse value="${useIntelGDL}" />
                <isfalse value="${useBroadcomEGL}" />
            </and>
        </condition>

        <echo message="setup.noOpenGL: ${setup.noOpenGL}" />
        <echo message="isWindows: ${isWindows}" />
        <echo message="isOSX: ${isOSX}" />
        <echo message="isX11: ${isX11}" />
        <echo message="useKD: ${useKD}" />
        <echo message="useIntelGDL: ${useIntelGDL}" />
        <echo message="useBroadcomEGL: ${useBroadcomEGL}" />
        <echo message="setup.nonatives: ${setup.nonatives}" />

        <!-- partitioning -->

        <property name="java.part.core"
                  value="com/jogamp/newt/*, com/jogamp/newt/event/*, com/jogamp/newt/util/*, com/jogamp/newt/impl/*, com/jogamp/newt/impl/event/*"/>

        <property name="java.part.awt"
                  value="com/jogamp/newt/impl/awt/*, com/jogamp/newt/awt/*, com/jogamp/newt/event/awt/*"/>

        <property name="java.part.x11"
                  value="com/jogamp/newt/impl/x11/*"/>

        <property name="java.part.windows"
                  value="com/jogamp/newt/impl/windows/*"/>

        <property name="java.part.macosx"
                  value="com/jogamp/newt/impl/macosx/*"/>

        <property name="java.part.opengl"
                  value="com/jogamp/newt/opengl/*, com/jogamp/newt/impl/opengl/kd/*"/>

        <property name="java.part.broadcomegl"
                  value="com/jogamp/newt/impl/opengl/broadcom/egl/*"/>

        <property name="java.part.intelgdl"
                  value="com/jogamp/newt/impl/intel/gdl/*"/>

        <!-- condition excludes -->

        <condition property="java.excludes.awt"
                   value="${java.part.awt}">
           <isset property="setup.noAWT"/>
        </condition>

        <condition property="java.excludes.opengl"
                   value="${java.part.opengl} ${java.part.broadcomegl}">
           <isset property="setup.noOpenGL"/>
        </condition>

        <property name="java.excludes.cdcfp" value="${java.part.awt}"/>

        <condition property="java.excludes.desktop"
                   value="${java.part.x11} ${java.part.windows}, ${java.part.macosx}, ${java.part.awt}">
           <isset property="setup.nodesktop"/>
        </condition>

        <property name="java.excludes.all" value="${java.excludes.awt}, ${java.excludes.opengl} ${java.excludes.desktop}" />
        <echo message="java.excludes.all: ${java.excludes.all}" />

    </target>

    <!-- ================================================================== -->
    <!--
       - Declare all paths and user defined variables.
      -->
    <target name="declare.common" description="Declare properties" depends="base.init">
        <property name="rootrel.src" value="src/newt" />
        <property name="rootrel.src.java" value="${rootrel.src}/classes" />
        <property name="rootrel.src.c" value="${rootrel.src}/native" />

        <!-- The source directories. -->
        <property name="src.java" value="${project.root}/${rootrel.src.java}" />
        <property name="src.c"    value="${project.root}/${rootrel.src.c}" />

        <!-- The generated source directories. -->
        <property name="src.generated" value="${build.newt}/gensrc" />
        <property name="src.generated.c" value="${src.generated}/native/newt" />

        <!-- The compiler output directories. -->
        <property name="classes" value="${build.newt}/classes" />
        <property name="classes-cdc" value="${build.newt}/classes-cdc" />

        <!-- The javadoc dirs. -->
        <property name="javadoc" value="${project.root}/javadoc_newt_public" />
        <property name="javadoc.spec" value="${project.root}/javadoc_newt_spec" />
        <property name="javadoc.dev" value="${project.root}/javadoc_newt_dev" />
        <property name="javadoc.link" value="http://java.sun.com/j2se/1.4.2/docs/api/" />
        <property name="javadoc.windowtitle" value="NEWT API -- ${newt_base_version} Specification" />
        <property name="javadoc.overview" value="spec-overview.html" />
        <property name="javadoc.spec.packagenames" value="com.jogamp.newt, com.jogamp.newt.event.*, com.jogamp.newt.opengl" />

        <property name="javadoc.packagenames" value="${javadoc.spec.packagenames}" />

        <property name="javadoc.dev.packagenames" value="${javadoc.packagenames},com.jogamp.newt.*" />
    <property name="javadoc.bottom" value="Copyright 2005 Sun Microsystems, Inc. All rights reserved. Use is subject to &lt;a href=&quot;http://jcp.org/en/jsr/detail?id=231&quot;&gt;license terms&lt;/a&gt;." />
    </target>

    <!-- ================================================================== -->
    <!--
       - Initialize all parameters required for the build and create any
       - required directories.
      -->
    <target name="init" depends="declare.common">
        <mkdir dir="${src.generated.c}" />
        <mkdir dir="${src.generated.c}/X11" />
        <mkdir dir="${src.generated.c}/MacOSX" />
        <mkdir dir="${src.generated.c}/Windows" />
        <mkdir dir="${src.generated.c}/KD" />
        <mkdir dir="${src.generated.c}/IntelGDL" />
        <mkdir dir="${src.generated.c}/BroadcomEGL" />
        <mkdir dir="${classes}" />
        <mkdir dir="${classes-cdc}" />
        <mkdir dir="${obj.newt}" />
    </target>

    <!-- ================================================================== -->
    <!--
       - Compile the original and generated source.
      -->
    <target name="java.compile.javase">
        <!-- Perform the second pass Java compile; everything. -->
        <javac destdir="${classes}"
               excludes="${java.excludes.all}"
               source="${target.sourcelevel}"
               fork="yes"
               includeAntRuntime="false"
               memoryMaximumSize="${javac.memorymax}"
               debug="${javacdebug}" debuglevel="${javacdebuglevel}">
            <src path="${src.java}" />
            <classpath refid="nativewindow_gluegen_jogl.classpath"/>
        </javac>
    </target>

    <target name="java.compile.javacdc" unless="setup.noCDC">
        <!-- Perform the first pass Java compile; everything -->
        <javac destdir="${classes-cdc}"
               excludes="${java.excludes.all} ${java.excludes.cdcfp}"
               source="${target.sourcelevel}"
               bootclasspath="${javac.bootclasspath-cdc.jar}"
               fork="yes"
               includeAntRuntime="false"
               memoryMaximumSize="${javac.memorymax}"
               debug="${javacdebug}" debuglevel="${javacdebuglevel}">
            <classpath refid="nativewindow_gluegen_jogl.classpath-cdc"/>
            <src path="${src.java}" />
        </javac>
    </target>

    <target name="java.compile" depends="java.compile.javase,java.compile.javacdc" />

    <!-- ================================================================== -->
    <!--
       - Compile the native C code for JOGL (and optionally the Cg binding).
      -->

    <target name="c.configure.1" depends="gluegen.cpptasks.detect.os,gluegen.cpptasks.setup.compiler">
      <!-- compiler configuration -->
      <!-- Note that we can use the base setups in the gluegen-cpptasks for most of these -->
      <compiler id="compiler.cfg.freebsd.newt" extends="compiler.cfg.freebsd">
        <includepath path="/usr/local/include" />
      </compiler>

      <!-- linker configuration -->

      <linker id="linker.cfg.freebsd.newt.x11" extends="linker.cfg.freebsd">
        <syslibset dir="/usr/local/lib" libs="X11"/>
        <syslibset libs="Xrandr"/>
        <syslibset dir="/usr/local/lib" libs="Xxf86vm" />
      </linker>

      <linker id="linker.cfg.freebsd.amd64.newt.x11" extends="linker.cfg.freebsd.amd64">
        <syslibset dir="/usr/local/lib" libs="X11"/>
        <syslibset libs="Xrandr"/>
        <syslibset dir="/usr/local/lib" libs="Xxf86vm" />
      </linker>

      <linker id="linker.cfg.linux.newt.broadcom_egl" extends="linker.cfg.linux">
        <syslibset libs="EGL"/>
        <syslibset libs="GLES_CM"/>
      </linker>

      <linker id="linker.cfg.linux.newt.x11" extends="linker.cfg.linux">
        <syslibset libs="X11"/>
        <syslibset libs="Xrandr"/>
        <syslibset libs="Xxf86vm" />
      </linker>

      <linker id="linker.cfg.linux.amd64.newt.x11" extends="linker.cfg.linux.amd64">
        <syslibset libs="X11"/>
        <syslibset libs="Xrandr"/>
        <syslibset libs="Xxf86vm" />
      </linker>

      <linker id="linker.cfg.solaris.newt.x11" extends="linker.cfg.solaris">
        <syslibset libs="X11"/>
      </linker>

      <linker id="linker.cfg.solaris.sparcv9.newt.x11" extends="linker.cfg.solaris.sparcv9">
        <syslibset dir="/usr/lib/sparcv9" libs="X11"/>
      </linker>

      <linker id="linker.cfg.solaris.amd64.newt.x11" extends="linker.cfg.solaris.amd64">
        <syslibset dir="/usr/lib/amd64" libs="X11"/>
      </linker>

      <linker id="linker.cfg.win32.mingw.newt" extends="linker.cfg.win32.mingw">
        <linkerarg value="-Wl,--kill-at" />        <!-- remove @ from function names -->
        <syslibset libs="gdi32, kernel32"/>
      </linker>

      <linker id="linker.cfg.win64.mingw.newt" extends="linker.cfg.win64.mingw">
        <linkerarg value="-Wl,--kill-at" />        <!-- remove @ from function names -->
        <syslibset libs="gdi32, kernel32"/>
      </linker>

      <linker id="linker.cfg.win32.msvc.newt" extends="linker.cfg.win32.msvc">
        <syslibset libs="gdi32, user32, kernel32" />
      </linker>

      <linker id="linker.cfg.macosx.newt" extends="linker.cfg.macosx">
        <linkerarg value="-framework" />
        <linkerarg value="Cocoa" />
      </linker>

      <linker id="linker.cfg.hpux.newt" extends="linker.cfg.hpux">
        <syslibset dir="/usr/lib" libs="X11"/>
      </linker>
    </target>

    <target name="c.configure.win32.vc" if="isVCFamily">
      <echo message="Win32.VC" />
      <property name="compiler.cfg.id"                      value="compiler.cfg.win32.msvc" />
      <property name="linker.cfg.id.core"                   value="linker.cfg.win32.msvc" />
      <property name="linker.cfg.id.oswin"                  value="linker.cfg.win32.msvc.newt" />
    </target>

    <target name="c.configure.win32.mingw" if="isMingW32">
      <echo message="Win32.MingW" />
      <property name="compiler.cfg.id"                      value="compiler.cfg.win32.mingw" />
      <property name="linker.cfg.id.core"                   value="linker.cfg.win32.mingw" />
      <property name="linker.cfg.id.oswin"                  value="linker.cfg.win32.mingw.newt" />
    </target>

    <target name="c.configure.win64.mingw" if="isMingW64">
      <echo message="Win64.MingW" />
      <property name="compiler.cfg.id"                      value="compiler.cfg.win64.mingw" />
      <property name="linker.cfg.id.core"                   value="linker.cfg.win64.mingw" />
      <property name="linker.cfg.id.oswin"                  value="linker.cfg.win64.mingw.newt" />
    </target>

    <target name="c.configure.linux.x86" if="isLinuxX86">
      <echo message="Linux.x86" />
      <property name="compiler.cfg.id"                      value="compiler.cfg.linux" />
      <property name="linker.cfg.id.core"                   value="linker.cfg.linux" />
      <condition property="linker.cfg.id.oswin"             value="linker.cfg.linux.newt.x11"
                                                            else="linker.cfg.linux">
          <isset property="isX11" />
      </condition>
      <echo message="linker.cfg.id.oswin ${linker.cfg.id.oswin}" />
    </target>

    <target name="c.configure.linux.amd64" if="isLinuxAMD64">
      <echo message="Linux.AMD64" />
      <property name="compiler.cfg.id"                      value="compiler.cfg.linux.amd64" />
      <property name="linker.cfg.id.core"                   value="linker.cfg.linux.amd64" />
      <condition property="linker.cfg.id.oswin"             value="linker.cfg.linux.amd64.newt.x11"
                                                            else="linker.cfg.linux.amd64">
          <isset property="isX11" />
      </condition>
      <echo message="linker.cfg.id.oswin ${linker.cfg.id.oswin}" />
    </target>

    <target name="c.configure.linux.ia64" if="isLinuxIA64">
      <echo message="Linux.IA64" />
      <property name="compiler.cfg.id"                      value="compiler.cfg.linux" />
      <property name="linker.cfg.id.core"                   value="linker.cfg.linux" />
      <property name="linker.cfg.id.oswin"                  value="linker.cfg.linux.newt.x11" />
    </target>

    <target name="c.configure.linux" depends="c.configure.linux.x86,c.configure.linux.amd64,c.configure.linux.ia64,c.configure.x11" if="isLinux"/>

    <target name="c.configure.solaris32" depends="c.configure.x11" if="isSolaris32Bit">
      <echo message="Solaris" />
      <property name="compiler.cfg.id"                      value="compiler.cfg.solaris" />
      <property name="linker.cfg.id.core"                   value="linker.cfg.solaris" />
      <property name="linker.cfg.id.oswin"                  value="linker.cfg.solaris.newt.x11" />
    </target>


    <target name="c.configure.solaris.sparcv9" depends="c.configure.x11" if="isSolarisSparcv9">
      <echo message="SolarisSparcv9" />
      <property name="compiler.cfg.id"                      value="compiler.cfg.solaris.sparcv9" />
      <property name="linker.cfg.id.core"                   value="linker.cfg.solaris.sparcv9" />
      <property name="linker.cfg.id.oswin"                  value="linker.cfg.solaris.sparcv9.newt.x11" />
    </target>


    <target name="c.configure.solaris.amd64" depends="c.configure.x11" if="isSolarisAMD64">
      <echo message="SolarisAMD64" />
      <property name="compiler.cfg.id"                      value="compiler.cfg.solaris.amd64" />
      <property name="linker.cfg.id.core"                   value="linker.cfg.solaris.amd64" />
      <property name="linker.cfg.id.oswin"                  value="linker.cfg.solaris.amd64.newt.x11" />
    </target>

    <target name="c.configure.freebsd.x86" if="isFreeBSDX86">
      <echo message="FreeBSD.x86" />
      <property name="compiler.cfg.id"                      value="compiler.cfg.freebsd.newt" />
      <property name="linker.cfg.id.core"                   value="linker.cfg.freebsd" />
      <condition property="linker.cfg.id.oswin"             value="linker.cfg.freebsd.newt.x11"
                                                            else="linker.cfg.freebsd">
          <isset property="isX11" />
      </condition>
      <echo message="linker.cfg.id.oswin ${linker.cfg.id.oswin}" />
    </target>

    <target name="c.configure.freebsd.amd64" if="isFreeBSDAMD64">
      <echo message="FreeBSD.AMD64" />
      <property name="compiler.cfg.id"                      value="compiler.cfg.freebsd.newt" />
      <property name="linker.cfg.id.core"                   value="linker.cfg.freebsd.amd64" />
      <condition property="linker.cfg.id.oswin"             value="linker.cfg.freebsd.amd64.newt.x11"
                                                            else="linker.cfg.freebsd.amd64">
          <isset property="isX11" />
      </condition>
      <echo message="linker.cfg.id.oswin ${linker.cfg.id.oswin}" />
    </target>

    <target name="c.configure.freebsd" depends="c.configure.freebsd.x86,c.configure.freebsd.amd64,c.configure.x11" if="isFreeBSD"/>

    <target name="c.configure.hpux" depends="c.configure.x11" if="isHPUX">
      <echo message="HP-UX" />
      <property name="compiler.cfg.id"                      value="compiler.cfg.hpux" />
      <property name="linker.cfg.id.core"                   value="linker.cfg.hpux" />
      <property name="linker.cfg.id.oswin"                  value="linker.cfg.hpux.newt.x11" />
    </target>

    <target name="c.configure.win32" depends="c.configure.win32.vc,c.configure.win32.mingw,c.configure.win64.mingw" if="isWindows" />

    <target name="c.configure.x11" if="isX11" />

    <target name="c.configure.macosx" if="isOSX">
      <property name="compiler.cfg.id"                      value="compiler.cfg.macosx" />
      <property name="linker.cfg.id.core"                   value="linker.cfg.macosx" />
      <property name="linker.cfg.id.oswin"                  value="linker.cfg.macosx.newt" />
    </target>

    <target name="c.configure.2" depends="c.configure.win32,c.configure.linux,c.configure.solaris32,c.configure.solaris.sparcv9,c.configure.solaris.amd64,c.configure.macosx,c.configure.freebsd,c.configure.hpux" />

    <target name="c.configure" depends="c.configure.1,c.configure.2" />

    <target name="rename.mingw.dll" if="isMingW">
        <move file="${src}" tofile="${dest}" />
    </target>

    <target name="rename.dylib" if="isOSX">
        <move file="${src}" tofile="${dest}" />
        <copy file="${dest}" tofile="${dest-cdc}" />
    </target>

    <macrodef name="c.build">
      <attribute name="c.compiler.src.files" />
      <attribute name="compiler.cfg.id" />
      <attribute name="linker.cfg.id" />
      <attribute name="output.lib.name" />
      <attribute name="c.compiler.use-jawt" default="false"/>
      <sequential>
        <echo message="Output lib name = @{output.lib.name}" />

        <!-- NOTE: the value of the debug and optimise attributes will not be overridden if already set externally -->
        <property name="c.compiler.debug"     value="false" />
        <!-- Optimise flags one of { none, size, speed, minimal, full, aggressive, extreme, unsafe } -->
        <property name="c.compiler.optimise"  value="none" />

        <condition property="c.compiler.use-debug"><istrue value="${c.compiler.debug}"/></condition>

        <patternset id="c.src.files.newt">
          <include name="${rootrel.src.c}/NewtCommon.c" />
          <include name="${rootrel.src.c}/WindowsWindow.c" if="isWindows"/>
          <include name="${rootrel.src.c}/*.m" if="isOSX"/>
          <include name="${rootrel.src.c}/X11Window.c" if="isX11"/>
          <include name="${rootrel.src.c}/KDWindow.c"  if="useKD"/>
          <include name="${rootrel.src.c}/IntelGDL.c"  if="useIntelGDL"/>
          <include name="${rootrel.src.c}/BroadcomEGL.c"  if="useBroadcomEGL"/>
        </patternset>

        <echo message="Compiling @{output.lib.name}" />

        <cc outtype="shared"
            objdir="${obj.newt}"
            outfile="${obj.newt}/@{output.lib.name}"
            optimize="${c.compiler.optimise}"
            debug="${c.compiler.debug}"
            multithreaded="true"
            exceptions="false"
            rtti="false">

          <fileset dir="${project.root}"><patternset refid="@{c.compiler.src.files}"/></fileset>

          <compiler extends="@{compiler.cfg.id}" >
            <sysincludepath path="${java.includes.dir}"/>
            <sysincludepath path="${java.includes.dir.platform}"/>
            <includepath path="stub_includes/khr"/>
            <includepath path="stub_includes/egl"/>
            <!-- This is for the generated headers for handwritten C code -->
            <includepath path="${src.generated.c}" />
            <includepath path="${src.generated.c}/X11" if="isX11"/>
            <includepath path="${src.generated.c}/MacOSX" if="isOSX"/>
            <includepath path="${src.generated.c}/Windows" if="isWindows"/>
            <includepath path="${src.generated.c}/KD" if="useKD" />
            <includepath path="${src.generated.c}/IntelGDL" if="useIntelGDL" />
            <includepath path="stub_includes/embedded/IntelGDL" if="useIntelGDL" />
            <includepath path="${src.generated.c}/BroadcomEGL" if="useBroadcomEGL" />

            <!-- This must come last to not override real include paths -->
            <!-- includepath path="stub_includes/macosx" if="isOSX" / -->
          </compiler>

          <linker extends="@{linker.cfg.id}">
            <syslibset dir="${java.lib.platform}" libs="jawt" if="@{output.lib.name}.useLibJAWT"/>
            <syslibset dir="${java.lib.platform}/server" libs="jvm" if="@{output.lib.name}.useLibJVM"/>
          </linker>
        </cc>

        <!-- FIXME: this is a hack; the cpptask should have an option to change the
             suffix or at least understand the override from dylib to jnilib -->
        <antcall target="rename.dylib" inheritRefs="true">
            <param name="src"  value="${obj.newt}/lib@{output.lib.name}.dylib" />
            <param name="dest" value="${obj.newt}/lib@{output.lib.name}.jnilib" />
            <param name="dest-cdc" value="${obj.newt}/lib@{output.lib.name}.so" />
        </antcall>

        <!-- FIXME: this is a hack; the cpptask should have an option to change the
             suffix or at least understand the override from dylib to jnilib -->
        <antcall target="rename.mingw.dll" inheritRefs="true">
            <param name="src"  value="${obj.newt}/lib@{output.lib.name}.so" />
            <param name="dest" value="${obj.newt}/@{output.lib.name}.dll" />
        </antcall>
      </sequential>
    </macrodef>

    <target name="c.build.newt.prepare.KD" if="useKD">
      <javah destdir="${src.generated.c}/KD" classpath="${classes}" class="com.jogamp.newt.impl.opengl.kd.KDWindow" />
    </target>

    <target name="c.build.newt.prepare.IntelGDL" if="useIntelGDL">
      <javah destdir="${src.generated.c}/IntelGDL" classpath="${classes}" class="com.jogamp.newt.impl.intel.gdl.Display" />
      <javah destdir="${src.generated.c}/IntelGDL" classpath="${classes}" class="com.jogamp.newt.impl.intel.gdl.Screen" />
      <javah destdir="${src.generated.c}/IntelGDL" classpath="${classes}" class="com.jogamp.newt.impl.intel.gdl.Window" />
    </target>

    <target name="c.build.newt.prepare.BroadcomEGL" if="useBroadcomEGL">
      <javah destdir="${src.generated.c}/BroadcomEGL" classpath="${classes}" class="com.jogamp.newt.impl.opengl.broadcom.egl.Window" />
    </target>

    <target name="c.build.newt.prepare.desktop" unless="setup.nodesktop">
      <javah destdir="${src.generated.c}/Windows" classpath="${classes}" class="com.jogamp.newt.impl.windows.WindowsWindow" />
      <javah destdir="${src.generated.c}/Windows" classpath="${classes}" class="com.jogamp.newt.impl.windows.WindowsScreen" />
      <javah destdir="${src.generated.c}/Windows" classpath="${classes}" class="com.jogamp.newt.impl.windows.WindowsDisplay" />
      <javah destdir="${src.generated.c}/MacOSX" classpath="${classes}" class="com.jogamp.newt.impl.macosx.MacWindow" />
      <javah destdir="${src.generated.c}/MacOSX" classpath="${classes}" class="com.jogamp.newt.impl.macosx.MacScreen" />
      <javah destdir="${src.generated.c}/MacOSX" classpath="${classes}" class="com.jogamp.newt.impl.macosx.MacDisplay" />
      <javah destdir="${src.generated.c}/X11" classpath="${classes}" class="com.jogamp.newt.impl.x11.X11Window" />
      <javah destdir="${src.generated.c}/X11" classpath="${classes}" class="com.jogamp.newt.impl.x11.X11Screen" />
      <javah destdir="${src.generated.c}/X11" classpath="${classes}" class="com.jogamp.newt.impl.x11.X11Display" />
    </target>

    <target name="c.build.newt.prepare" depends="c.build.newt.prepare.KD,c.build.newt.prepare.IntelGDL,c.build.newt.prepare.BroadcomEGL,c.build.newt.prepare.desktop" />

    <target name="c.build.newt.windowlib" unless="setup.nonatives">
      <c.build c.compiler.src.files="c.src.files.newt"
               output.lib.name="newt"
               compiler.cfg.id="${compiler.cfg.id}"
               linker.cfg.id="${linker.cfg.id.oswin}"/>
    </target>

    <target name="c.manifest" if="isVC8Family">
      <!-- exec mt, the Microsoft Manifest Tool, to include DLL manifests in order to resolve the location of msvcr80.dll -->
      <msvc.manifest objdir="${obj.newt}" dllname="newt" />
    </target>

    <target name="c.build.newt.natives" depends="c.build.newt.windowlib" unless="setup.nonatives">
    </target>

    <target name="c.build.newt" depends="c.configure,c.build.newt.prepare,c.build.newt.natives">
      <antcall target="gluegen.cpptasks.striplibs" inheritRefs="true">
          <param name="libdir" value="${obj.newt}"/>
      </antcall>

      <antcall target="c.manifest" inheritRefs="true" />
    </target>

    <!-- ================================================================== -->
    <!--
       - Build the newt.jar files.
      -->
    <target name="build-jars" depends="gluegen.cpptasks.detect.os,build-jars-javase,build-jars-cdc" />

    <target name="setup-manifestfile">
        <property name="manifestfile" value="newtversion"/>
        <copy file="${manifestfile}"
          tofile="tempversion"
          overwrite="true">
          <filterset>
              <filter token="VERSION" value="${newt.version}"/>
              <filter token="SCM_BRANCH" value="${jogl.build.branch}"/>
              <filter token="SCM_COMMIT" value="${jogl.build.commit}"/>
              <filter token="BASEVERSION" value="${newt_base_version}"/>
          </filterset>
        </copy>
    </target>

    <target name="setup-manifestfile-cdc">
        <property name="manifestfile" value="newtversion-cdc"/>
        <copy file="${manifestfile}"
          tofile="tempversion-cdc"
          overwrite="true">
          <filterset>
              <filter token="VERSION" value="${newt.version}"/>
              <filter token="SCM_BRANCH" value="${jogl.build.branch}"/>
              <filter token="SCM_COMMIT" value="${jogl.build.commit}"/>
              <filter token="BASEVERSION" value="${newt_base_version}"/>
          </filterset>
        </copy>
    </target>

    <target name="build-jars-awt" depends="setup-manifestfile" unless="setup.noAWT">
        <jar manifest="tempversion" destfile="${newt.awt.jar}" filesonly="true">
            <fileset dir="${classes}"
                     includes="${java.part.awt}"/>
        </jar>
    </target>

    <target name="build-jars-opengl" depends="setup-manifestfile" unless="setup.noOpenGL">
        <jar manifest="tempversion" destfile="${newt.ogl.jar}" filesonly="true">
            <fileset dir="${classes}"
                     includes="${java.part.opengl}"/>
        </jar>
        <jar manifest="tempversion" destfile="${newt.broadcomegl.jar}" filesonly="true">
            <fileset dir="${classes}"
                     includes="${java.part.broadcomegl}"/>
        </jar>
    </target>

    <target name="build-jars-driver" depends="setup-manifestfile">
        <jar manifest="tempversion" destfile="${newt.intelgdl.jar}" filesonly="true">
            <fileset dir="${classes}"
                     includes="${java.part.intelgdl}"/>
        </jar>
    </target>

    <target name="build-jars-opengl-cdc" depends="setup-manifestfile-cdc" unless="setup.noOpenGL">
        <jar manifest="tempversion-cdc" destfile="${newt.ogl.cdc.jar}" filesonly="true">
            <fileset dir="${classes-cdc}"
                     includes="${java.part.opengl}"/>
        </jar>
        <jar manifest="tempversion-cdc" destfile="${newt.broadcomegl.cdc.jar}" filesonly="true">
            <fileset dir="${classes-cdc}"
                     includes="${java.part.broadcomegl}"/>
        </jar>
    </target>

    <target name="build-jars-driver-cdc" depends="setup-manifestfile-cdc">
        <jar manifest="tempversion-cdc" destfile="${newt.intelgdl.cdc.jar}" filesonly="true">
            <fileset dir="${classes}"
                     includes="${java.part.intelgdl}"/>
        </jar>
    </target>

    <target name="build-jars-desktop" depends="setup-manifestfile" unless="setup.nodesktop">
        <jar manifest="tempversion" destfile="${newt.os.x11.jar}" filesonly="true">
            <fileset dir="${classes}"
                     includes="${java.part.x11}"/>
        </jar>
        <jar manifest="tempversion" destfile="${newt.os.win.jar}" filesonly="true">
            <fileset dir="${classes}"
                     includes="${java.part.windows}"/>
        </jar>
        <jar manifest="tempversion" destfile="${newt.os.osx.jar}" filesonly="true">
            <fileset dir="${classes}"
                     includes="${java.part.macosx}"/>
        </jar>
    </target>

    <target name="build-jars-desktop-cdc" depends="setup-manifestfile-cdc" unless="setup.nodesktop">
        <jar manifest="tempversion-cdc" destfile="${newt.os.x11.cdc.jar}" filesonly="true">
            <fileset dir="${classes-cdc}"
                     includes="${java.part.x11}"/>
        </jar>
        <jar manifest="tempversion-cdc" destfile="${newt.os.win.cdc.jar}" filesonly="true">
            <fileset dir="${classes-cdc}"
                     includes="${java.part.windows}"/>
        </jar>
        <jar manifest="tempversion-cdc" destfile="${newt.os.osx.cdc.jar}" filesonly="true">
            <fileset dir="${classes-cdc}"
                     includes="${java.part.macosx}"/>
        </jar>
    </target>

    <target name="build-jars-all-awt" depends="setup-manifestfile" unless="setup.noAWT">
        <jar manifest="tempversion" destfile="${newt.all.jar}" filesonly="true">
            <fileset dir="${classes}"
                     includes="com/jogamp/newt/**" />
        </jar>
        <jar manifest="tempversion" destfile="${newt.event.jar}" filesonly="true">
            <fileset dir="${classes}"
                     includes="com/jogamp/newt/Display* com/jogamp/newt/Screen* com/jogamp/newt/Window* com/jogamp/newt/ScreenMode* com/jogamp/newt/event/** com/jogamp/newt/impl/Debug*" />
        </jar>
    </target>

    <target name="build-jars-all-noawt" depends="setup-manifestfile">
        <jar manifest="tempversion" destfile="${newt.all-noawt.jar}" filesonly="true">
            <fileset dir="${classes}"
                     includes="com/jogamp/newt/**"
                     excludes="${java.part.awt}" />
        </jar>
    </target>

    <target name="build-jars-all-cdc" depends="setup-manifestfile-cdc">
        <jar manifest="tempversion-cdc" destfile="${newt.all.cdc.jar}" filesonly="true">
            <fileset dir="${classes-cdc}"
                     includes="com/jogamp/newt/**"
                     excludes="${java.excludes.cdcfp}" />
        </jar>
    </target>

    <target name="build-jars-javase" depends="setup-manifestfile,build-jars-awt,build-jars-opengl,build-jars-all-noawt,build-jars-all-awt,build-jars-desktop,build-jars-driver">
        <jar manifest="tempversion" destfile="${newt.core.jar}" filesonly="true">
            <fileset dir="${classes}"
                     includes="${java.part.core}"/>
        </jar>
        <jar manifest="tempversion" destfile="${build.newt}/newt-natives-${os.and.arch}.jar" filesonly="true">
            <fileset dir="${obj.newt}">
              <include name="*.${native.library.suffix}" />
            </fileset>
        </jar>
        <delete file="tempversion"/>
    </target>

    <target name="build-jars-cdc" depends="setup-manifestfile-cdc,build-jars-opengl-cdc,build-jars-all-cdc,build-jars-desktop-cdc,build-jars-driver-cdc" unless="setup.noCDC">
        <jar manifest="tempversion-cdc" destfile="${newt.core.cdc.jar}" filesonly="true">
            <fileset dir="${classes-cdc}"
                     includes="${java.part.core}"/>
        </jar>
        <jar manifest="tempversion-cdc" destfile="${build.newt}/newt-natives-${os.and.arch}-cdc.jar" filesonly="true">
            <fileset dir="${obj.newt}">
              <include name="*.${native.library.suffix-cdc}" />
            </fileset>
        </jar>
        <delete file="tempversion-cdc"/>
    </target>

    <!-- ================================================================== -->
    <!--
       - Build the Javadocs for the sources.
       - NOTE:  these are not entirely correct as the javadocs targets depend
       -        on the platform specific build targets.  To circumvent any
       -        errors, ensure that the source is built first.
      -->
    <target name="javadoc" depends="init">
        <!-- Build the general Javadoc -->
        <javadoc packagenames="${javadoc.packagenames}"
                 excludepackagenames="${java.excludes.javadoc.packagenames}"
                 sourcepath="${src.java};${src.generated.java}"
                 destdir="${javadoc}" windowtitle="${javadoc.windowtitle}"
                 overview="${javadoc.overview}"
                 source="1.4"
                 linkoffline="${javadoc.link} 142-packages"
         bottom="${javadoc.bottom}" >
         <classpath refid="nativewindow_gluegen_jogl.classpath"/>
        </javadoc>
    </target>

    <target name="javadoc.spec" depends="init">
        <!-- Build the general Javadoc -->
        <javadoc packagenames="${javadoc.spec.packagenames}"
                 excludepackagenames="${java.excludes.javadoc.packagenames}"
                 sourcepath="${src.java};${src.generated.java}"
                 destdir="${javadoc.spec}" windowtitle="${javadoc.windowtitle}"
                 overview="${javadoc.overview}"
                 source="1.4"
                 linkoffline="${javadoc.link} 142-packages"
                 bottom="${javadoc.bottom}" >
         <classpath refid="nativewindow_gluegen_jogl.classpath"/>
        </javadoc>
    </target>

    <target name="javadoc.dev" depends="init">
        <!-- Build the internal developer Javadoc -->
        <javadoc packagenames="${javadoc.dev.packagenames}"
                 excludepackagenames="${java.excludes.javadoc.packagenames}"
                 sourcepath="${src.java};${src.generated.java}"
                 destdir="${javadoc.dev}" windowtitle="${javadoc.windowtitle}"
                 overview="${javadoc.overview}"
                 source="1.4"
                 linkoffline="${javadoc.link} 142-packages"
         bottom="${javadoc.bottom}" >
         <classpath refid="nativewindow_gluegen_jogl.classpath"/>
        </javadoc>
    </target>

    <target name="all.doc" description="Build NEWT docs" depends="init,javadoc,javadoc.spec,javadoc.dev" />

    <!-- ================================================================== -->
    <!--
       - Clean up all that is built.
      -->
    <target name="clean" description="Remove all build products" depends="declare.common">
        <delete includeEmptyDirs="true" quiet="true">
            <fileset dir="${build.newt}" />
            <fileset dir="${javadoc}" />
            <fileset dir="${javadoc.spec}" />
            <fileset dir="${javadoc.dev}" />
        </delete>
    </target>

    <!-- ================================================================== -->
    <!--
       - Build everything.
      -->
    <target name="all" description="Build NEWT JAR file(s) and native libraries." depends="init,java.compile,c.build.newt,build-jars,generate.version.txt" />

    <target name="generate.version.txt" depends="init">
        <!-- Create a version.txt file indicating which version we just built -->
        <echo message="${newt.version}" file="${build.newt}/version.txt" />
    </target>

</project>