<?xml version="1.0" encoding="UTF-8"?>

<!-- Current runtime requirements are:
        - Java 8 (class file 52)
        - Android SDK API level 26 (Version 8.0 Oreo, released August 2017)

     Future versions consider using
        - Java 11 (class file 55)
        - Android SDK API level 32 (Version 12 Snow Cone, released 2022)
          - See <https://developer.android.com/build/jdks>
          - See <https://developer.android.com/studio/write/java11-default-support-table>

     Official production builds are performed _on_ OpenJDK 21
     and a Java JDK 17 or greater is required.

     +++

     Android: Aligned with Android SDK build-tools 36 and NDK 29 as of 2025-06-25

     On 2025-08-31: Android 15 (API level 35) or higher is required for stored apps.
     <https://developer.android.com/google/play/requirements/target-sdk>

     Hence, we need to set the APK's manifest SDK min version to 26 (Android 8, Oreo)
     and target version to 35 (Android 15), as required as of 2025-08-31

         <uses-sdk android:minSdkVersion="26" android:targetSdkVersion="35"/>

     It is strongly recommended to test with the x86_64 and maybe x86 emulator
     using the latest API level.

     On 2025-07-20 we have tested `jogl-demos-fat-android-${arch}.apk`
     using an `x86` and `x86_64` emulator for
     - Android  8, API 26
     - Android 14, API 34
     - Android 15, API 35

     Old:
       - On 2019-12-25 we have tested using Android 10, API 29 on the x86 emulator.
       - Further testing should be performed from Android 5, API 21, to Android 9, API 28,
         as well as on aarch64 and armv7a devices.

     +++

     For crosscompilation the following shall be set:
     - TARGET_PLATFORM_SYSROOT Crosscompiler and system specified 'sysroot' (as in gcc \-\-print-sysroot)
     - TARGET_PLATFORM_USRROOT Additional optional user headers and libraries for target
     - TARGET_PLATFORM_USRLIBS Actual location of target user libraries within TARGET_PLATFORM_USRROOT
     - TARGET_JAVA_LIBS Actual location of the Java libraries within TARGET_PLATFORM_USRROOT
  -->

<project name="jogamp-env" basedir=".">

  <target name="jogamp.env.validation">
    <echo message="ant.version                ${ant.version}"/>
    <echo message="ant.java.version           ${ant.java.version}"/>
    <echo message="java.version               ${java.version}"/>
    <echo message="java.home                  ${java.home}"/>

    <property name="jvmJava.exe" value="${java.home}/bin/java" /> <!-- the java jvm executable for unit tests -->
    <echo message="jvmJava.exe                ${jvmJava.exe}"/>

    <condition property="jvmJava8.exe" value="${env.JAVA8_EXE}">
        <not>
         <equals arg1="${env.JAVA8_EXE}" arg2="$${env.JAVA8_EXE}" casesensitive="true" />
        </not>
    </condition>
    <echo message="jvmJava8.exe               ${jvmJava8.exe}"/> <!-- optional extra Java8 JVM for unit tests -->

    <fail message="Please build using Ant 1.8.0 or higher.">
      <condition>
          <not>
              <antversion atleast="1.8.0"/>
          </not>
      </condition>
    </fail>

    <condition property="minJava21" value="true">
        <or>
            <equals arg1="${ant.java.version}" arg2="21"/>
            <equals arg1="${ant.java.version}" arg2="22"/>
            <equals arg1="${ant.java.version}" arg2="23"/>
            <equals arg1="${ant.java.version}" arg2="24"/>
            <equals arg1="${ant.java.version}" arg2="25"/>
            <equals arg1="${ant.java.version}" arg2="26"/>
            <equals arg1="${ant.java.version}" arg2="27"/>
            <equals arg1="${ant.java.version}" arg2="28"/>
            <equals arg1="${ant.java.version}" arg2="29"/>
            <equals arg1="${ant.java.version}" arg2="30"/>
        </or>
    </condition>
    <echo message="minJava21                  ${minJava21}"/>

    <condition property="minJava17" value="true">
        <or>
            <equals arg1="${ant.java.version}" arg2="17"/>
            <equals arg1="${ant.java.version}" arg2="18"/>
            <equals arg1="${ant.java.version}" arg2="19"/>
            <equals arg1="${ant.java.version}" arg2="20"/>
            <istrue value="${minJava21}"/>
        </or>
    </condition>
    <echo message="minJava17                  ${minJava17}"/>

    <condition property="minJava11" value="true">
        <or>
            <equals arg1="${ant.java.version}" arg2="11"/>
            <equals arg1="${ant.java.version}" arg2="12"/>
            <equals arg1="${ant.java.version}" arg2="13"/>
            <equals arg1="${ant.java.version}" arg2="14"/>
            <equals arg1="${ant.java.version}" arg2="15"/>
            <equals arg1="${ant.java.version}" arg2="16"/>
            <istrue value="${minJava17}"/>
        </or>
    </condition>
    <echo message="minJava11                  ${minJava11}"/>

    <condition property="minJava9" value="true">
        <or>
            <equals arg1="${ant.java.version}" arg2="9"/>
            <istrue value="${minJava11}"/>
        </or>
    </condition>
    <echo message="minJava9                   ${minJava9}"/>

    <condition property="minJava8" value="true">
        <or>
            <equals arg1="${ant.java.version}" arg2="1.8"/>
            <istrue value="${minJava9}"/>
        </or>
    </condition>
    <echo message="minJava8                   ${minJava8}"/>

    <!-- Only for junit runtime tests Java 11 is allowed, for building Java 11 is required. -->
    <fail message="Unsupported Java version: ${ant.java.version}. Make sure that the version of Java is 11 or greater.">
        <condition>
            <not>
                <istrue value="${minJava11}"/>
            </not>
        </condition>
    </fail>

  </target>

  <target name="jogamp.env.init" depends="jogamp.env.validation">
    <property environment="env" />

    <tstamp>
        <format property="version.timestamp" pattern="yyyyMMdd"/>
    </tstamp>

    <condition property="javadoc.xarg1" value="-Xdoclint:none" else="-J-Ddummy=val">
        <istrue value="${minJava8}"/>
    </condition>
    <echo message="javadoc.xarg1              ${javadoc.xarg1}"/>

    <condition property="jogamp.jar.codebase" value="${env.JOGAMP_JAR_CODEBASE}">
        <not>
         <equals arg1="${env.JOGAMP_JAR_CODEBASE}" arg2="$${env.JOGAMP_JAR_CODEBASE}" casesensitive="true" />
        </not>
    </condition>

  	<property name="target.sourcelevel" value="8"/>
  	<property name="target.targetlevel" value="8"/>
  	<property name="target.releaselevel" value="8"/>
  	<property name="target.buildlevel" value="11"/>

    <!-- not required:     java.base/java.lang=ALL-UNNAMED -->
    <!-- required for AWT: java.desktop/sun.awt=ALL-UNNAMED java.desktop/sun.awt.windows=ALL-UNNAMED java.desktop/sun.java2d=ALL-UNNAMED -->
    <condition property="jvmarg.modules"  value="--enable-native-access=ALL-UNNAMED --add-opens java.desktop/sun.awt=ALL-UNNAMED --add-opens java.desktop/sun.awt.windows=ALL-UNNAMED --add-opens java.desktop/sun.java2d=ALL-UNNAMED">
        <isset property="minJava17"/>
    </condition>
    <condition property="jvmarg.modules"  value="--illegal-access=warn">
        <and>
            <isset property="minJava11"/>
            <not>
                <isset property="minJava17"/>
            </not>
        </and>
    </condition>
    <property name="jvmarg.modules"      value=""/> <!-- default is empty -->
    <property name="jvmarg.generic"      value="${jvmarg.modules}"/>
    <echo message="jvmarg.modules        ${jvmarg.modules}"/>
    <echo message="jvmarg.generic        ${jvmarg.generic}"/>

    <property name="jogamp.jar.codebase"      value=""/> <!-- A jogamp build uses value "Codebase: *.jogamp.org" -->
    <echo message="jogamp.jar.codebase        ${jogamp.jar.codebase}"/>

    <property name="jogamp.version.major" value="2"/>
    <property name="jogamp.version.minor" value="6"/>
    <property name="jogamp.version.submi" value="0"/>
    <!-- property name="jogamp.version.devel" value="-rc-${version.timestamp}"/ --> <!-- Devel RC Tag -->
    <property name="jogamp.version.devel" value=""/> <!-- Release tag -->
    <property name="jogamp.version.base"  value="${jogamp.version.major}.${jogamp.version.minor}"/>
    <property name="jogamp.version"       value="${jogamp.version.base}.${jogamp.version.submi}${jogamp.version.devel}" />
    <echo message="jogamp.version             ${jogamp.version}"/>

    <!-- This is the Android version: xxyyzzz, xx=API yy screen-from-to zzz app-version-->
    <property name="jogamp.version.int"   value="2414030"/>
    <echo message="jogamp.version.int         ${jogamp.version.int}"/>

    <!-- only set 'junit.is.disabled' if set in environment as 'true' to disable JUNIT tests -->
    <condition property="junit.is.disabled" value="${env.JUNIT_DISABLED}">
        <istrue value="${env.JUNIT_DISABLED}"/>
    </condition>
    <echo message="junit.is.disabled          ${junit.is.disabled}"/>

    <condition property="junit.run.arg0" value="${env.JUNIT_RUN_ARG0}">
        <not>
         <equals arg1="${env.JUNIT_RUN_ARG0}" arg2="$${env.JUNIT_RUN_ARG0}" casesensitive="true" />
        </not>
    </condition>
    <property name="junit.run.arg0"       value="-Djunit.run.arg0=dummy" />      <!-- default dummy values -->
    <condition property="junit.run.arg1" value="${env.JUNIT_RUN_ARG1}">
        <not>
         <equals arg1="${env.JUNIT_RUN_ARG1}" arg2="$${env.JUNIT_RUN_ARG1}" casesensitive="true" />
        </not>
    </condition>
    <property name="junit.run.arg1"       value="-Djunit.run.arg1=dummy" />      <!-- default dummy values -->

    <!-- only set 'build.archiveon' if set in environment as 'true' to trigger archive creation -->
    <condition property="build.archiveon" value="${env.BUILD_ARCHIVE}">
        <istrue value="${env.BUILD_ARCHIVE}"/>
    </condition>

    <condition property="build.node.name" value="${env.NODE_NAME}" else="local">
        <not>
         <equals arg1="${env.NODE_NAME}" arg2="$${env.NODE_NAME}" casesensitive="true" />
        </not>
    </condition>

    <condition property="android.api.level" value="${env.ANDROID_API_LEVEL}" else="26">
        <not>
         <equals arg1="${env.ANDROID_API_LEVEL}" arg2="$${env.ANDROID_API_LEVEL}" casesensitive="true" />
        </not>
    </condition>

    <echo message="target.sourcelevel         ${target.sourcelevel}"/>
    <echo message="target.targetlevel         ${target.targetlevel}"/>
    <echo message="target.releaselevel        ${target.releaselevel}"/>
    <echo message="target.buildlevel          ${target.buildlevel}"/>

    <property name="javacdebug"       value="true" />
    <property name="javacdebuglevel"  value="source,lines" />
    <!--property name="javacdebuglevel"  value="source,lines,vars" /-->
    <!-- property name="javac.memorymax"  value="128m" /-->  <!-- I ran out of memory with these .. linux x86_64 6u14 -->
    <property name="javac.memorymax"  value="1024m" />

    <echo message="javacdebug                 ${javacdebug}"/>
    <echo message="javacdebuglevel            ${javacdebuglevel}"/>
    <echo message="javac.memorymax            ${javac.memorymax}"/>

    <echo message="build.archiveon            ${build.archiveon}"/>
    <echo message="build.node.name            ${build.node.name}"/>

    <echo message="android.api.level          ${android.api.level}"/>

    <echo message="junit.run.arg0             ${junit.run.arg0}"/>
    <echo message="junit.run.arg1             ${junit.run.arg1}"/>

    <condition property="macosx.sdkroot" value="${env.SDKROOT}">
        <not>
         <equals arg1="${env.SDKROOT}" arg2="$${env.SDKROOT}" casesensitive="true" />
        </not>
    </condition>
    <echo message="macosx.sdkroot             ${macosx.sdkroot}"/>

    <condition property="TARGET_PLATFORM_SYSROOT" value="${env.TARGET_PLATFORM_SYSROOT}">
        <not>
         <equals arg1="${env.TARGET_PLATFORM_SYSROOT}" arg2="$${env.TARGET_PLATFORM_SYSROOT}" casesensitive="true" />
        </not>
    </condition>
    <condition property="TARGET_PLATFORM_USRROOT" value="${env.TARGET_PLATFORM_USRROOT}">
        <not>
         <equals arg1="${env.TARGET_PLATFORM_USRROOT}" arg2="$${env.TARGET_PLATFORM_USRROOT}" casesensitive="true" />
        </not>
    </condition>
    <condition property="TARGET_PLATFORM_USRLIBS" value="${env.TARGET_PLATFORM_USRLIBS}">
        <not>
         <equals arg1="${env.TARGET_PLATFORM_USRLIBS}" arg2="$${env.TARGET_PLATFORM_USRLIBS}" casesensitive="true" />
        </not>
    </condition>
    <condition property="TARGET_JAVA_LIBS" value="${env.TARGET_JAVA_LIBS}">
        <not>
         <equals arg1="${env.TARGET_JAVA_LIBS}" arg2="$${env.TARGET_JAVA_LIBS}" casesensitive="true" />
        </not>
    </condition>
    <echo message='TARGET_PLATFORM_SYSROOT ${TARGET_PLATFORM_SYSROOT}'/>
    <echo message='TARGET_PLATFORM_USRROOT ${TARGET_PLATFORM_USRROOT}'/>
    <echo message='TARGET_PLATFORM_USRLIBS ${TARGET_PLATFORM_USRLIBS}'/>
    <echo message='TARGET_JAVA_LIBS ${TARGET_JAVA_LIBS}'/>
  </target>

</project>
