How to build JOGL
How to build JOGL

## Platform and Component Requirements

Please also check GlueGen's HowToBuild and JogAmp's Supported Platforms.

Here is a list of platforms and components, we were able to build JOGL on,
if not stated otherwise.

- Java
  - Build & Runtime: An OpenJDK 17 compliant SDK.
  - Runtime: An OpenJDK 8 compliant JRE.
  You may find an appropriate OpenJDK build @ Adoptium.
  Or you may try one of the following SDK's and/or Runtimes:
  - Azul's Zulu (active, +embedded)
  - Avian (inactive, not tested)
- Ant 1.10.5 or later
- Git 2.0.4 or later
  - Use your Unix distribution's version, if available, or
  - Source Code for GNU/Linux, MacOS, .., or
  - Git on Windows is provided by cygwin
  - Git ≥ 2.37 provided by Xcode ≥ 14
- Optional NVidia Cg 2.2
  - Cg 2.2 Toolkit Download Page
- FreeBSD x86_64, ...
  - FreeBSD 14 or later
    - openjdk21
    - apache-ant
    - git
    - 7-zip
    - clang
    - doxygen
    - bash
    - xorg
    Commandline:
    - FreeBSD 14.3

          pkg install git doxygen bash openjdk21 junit 7-zip apache-ant xorg
          ln -s /usr/local/bin/bash /bin/bash

      Add the following to your /etc/fstab

          fdesc   /dev/fd         fdescfs         rw      0       0
          proc    /proc           procfs          rw      0       0

- GNU Linux x86_64 as well as aarch64, etc
  You may have to install a few developer packages ...
  - Debian 12 or later
    - build-essential
    - openjdk-17-jre
    - openjdk-17-jdk
    - libopenjfx-java
    - apache-ant
    - git
    - gawk
    - p7zip-full
    - gcc
    - cmake
    - libdrm-dev
    - libgbm-dev
    - libgles2-mesa-dev
    - libegl1-mesa-dev
    - libgl1-mesa-dev
    - libglu1-mesa-dev
    - xorg-dev
    - libice-dev
    - libsm-dev
    - libx11-dev
    - libxext-dev
    - libxxf86vm-dev
    - libxinerama-dev
    - libxrandr-dev
    - libxrender-dev
    - libxcursor-dev
    - libxi-dev
    - libudev-dev
    - libstdc++6
    - libstdc++-12-dev
    - Optional: Your card vendor's proprietary driver
    One liner install command
    - Debian 12 Bullseye

          apt-get install build-essential openjdk-17-jre openjdk-17-jdk libopenjfx-java ant git-all p7zip-full gcc cmake libdrm-dev libgbm-dev libgles2-mesa-dev libegl1-mesa-dev libgl1-mesa-dev libglu1-mesa-dev xorg-dev libice-dev libsm-dev libx11-dev libxext-dev libxxf86vm-dev libxinerama-dev libxrandr-dev libxrender-dev libxcursor-dev libxi-dev libudev-dev libc6-dev g++ libstdc++6 libstdc++-12-dev

    Optional: Add multiarch i386 next to amd64
    - Debian 11 Bullseye

          dpkg --add-architecture i386
          apt-get update
          apt-get install gcc-multilib lib32gomp1 lib32itm1 lib32quadmath0 libdrm2:i386 libdrm-dev:i386 libgbm1:i386 libgbm-dev:i386 libudev1:i386 libc6-i386 libc6-dev-i386 g++-multilib lib32stdc++6 openjdk-17-jre:i386 openjdk-17-jdk:i386

          cd /usr/lib/i386-linux-gnu/
          ln -s libXrender.so.1 libXrender.so
          ln -s libXxf86vm.so.1 libXxf86vm.so
          ln -s libXrandr.so.2 libXrandr.so
          ln -s libXcursor.so.1 libXcursor.so
          ln -s libXi.so.6 libXi.so
          cd /lib/i386-linux-gnu/
          ln -s libudev.so.1 libudev.so

  - OpenSuSE 15.0 or later
    - java-17-openjdk
    - apache-ant
    - git
    - gawk
    - p7zip-full
    - gcc
    - cmake
    - libdrm-dev (sic?)
    - libgbm-dev (sic?)
    - x11-devel
    - mesa-devel
  - CentOS 7 / Red Hat Enterprise Linux 7.6 or later
    - java-17-openjdk
    - apache-ant
    - git
    - gawk
    - p7zip-full
    - gcc
    - cmake
    - libdrm-dev (sic?)
    - libgbm-dev (sic?)
    - mesa-libGL-devel
    - xorg-x11-proto-devel
    - libICE-devel
    - libSM-devel
    - libX11-devel
    - libXext-devel
    - libXau-devel
    - libXdmcp-devel
    - libXt-devel
    - libXxf86vm-devel
    - libXinerama-devel
    - libXrandr-devel
    - libXrender-devel
    - libXcursor-devel
    - libudev-devel
    - Optional: Your card vendor's proprietary driver
- Android/Linux Version 7.0 Nougat API Level 24 or later
  - any of the above GNU/Linux x86_64 hosts for crosscompilation
  - android ndk (todo: detail instructions)
  - android sdk (todo: detail instructions)
- OpenSolaris Derivatives SPARC and x86, 32- and 64-bit
  - OpenIndiana using illumus's OpenSolaris continuation (todo: test)
- MacOS and iOS x86_64 and aarch64
  - Build machine: Mac OS 12.6.5 (Monterey)
    - Lowest test machine: Mac OS 10.13.6 (High Sierra)
    - Minimum deployment target: Mac OS 10.7 (Lion)
  - Xcode 14.2 for clang, etc (included in MacOS)
  - MacOS SDK 11.3 from a previous XCode version or from this alternative site
    - export SDKROOT=macosx11.3
    - We use -mmacosx-version-min=10.7 (Lion 10.7) minimum deployment target.
  - git ≥ 2.37 provided by Xcode ≥ 14
  - awk is provided by MacOS
  - CMake 3.25.1, and install the command line tools
    - Install symlinks to /usr/local/bin, run: sudo "/Applications/CMake.app/Contents/bin/cmake-gui" --install
  - 7-Zip 21.07 x86_64 and arm64 version
  - See also MacOS Versions Related to JogAmp
  Prepare fat universal OpenJDK libraries
  - Open a terminal in your home folder, e.g. /Users/jogamp
  - The OpenJDK library folder of each target platform, x86_64 or aarch64, is /Library/Java/JavaVirtualMachines/temurin-17.jdk/Contents/Home/lib
  - Transfer the x86_64 OpenJDK library folder to temurin-17.jdk.amd64.lib
  - Transfer the aarch64 OpenJDK library folder to temurin-17.jdk.arm64.lib
  - Run the script gluegen/make/scripts/make.macosx.jdk_lipo_libs.sh
  - Fat universal OpenJDK libraries are produced into temurin-17.jdk.fat.lib
  Now we have to tell the gluegen build framework to use temurin-17.jdk.fat.lib, by adding an ant macro in $HOME/gluegen.properties

                                      java.lib.dir.platform=/Users/jogamp/temurin-17.jdk.fat.lib

  Replace jogamp with your user name.
- Windows/x86_64 (64-bit)
  - Windows 7 or later
  - git is provided by cygwin
  - gawk is provided by cygwin
  - MinGW64 (files on github)
    - x86_64-12.2.0-release-posix-seh-msvcrt-rt_v10-rev2.7z
      - version: 12.2.0
      - host: x64
      - threading: posix
      - exceptions: seh
      - c-runtime: msvcrt
      - revision: 2
    - x86_64-12.2.0-release-win32-seh-msvcrt-rt_v10-rev2.7z
      - version: 12.2.0
      - host: x64
      - threading: win32
      - exceptions: seh
      - c-runtime: msvcrt
      - revision: 2
  - CMake 3.25.1 64bit version
  - 7-Zip 22.01 64bit version

Additional platforms such as HP/UX are handled by the build system, but are not officially supported.

## Build Steps

Here are the steps that are required in order to build JOGL.

1. Optain the source code using git:
   - Gluegen Dev GIT Repo
   - JOGL Dev GIT Repo
   It is crucial that you checkout the source code under a common root directory:

           /home/dude/projects/jogamp> git clone --recurse-submodules git://jogamp.org/srv/scm/gluegen.git gluegen
           /home/dude/projects/jogamp> git clone --recurse-submodules git://jogamp.org/srv/scm/jogl.git jogl

   Now you should have following directory structure:

           /home/dude/projects/jogamp
           /home/dude/projects/jogamp/gluegen
           /home/dude/projects/jogamp/jogl

   Note-1: The GlueGen source must be fetched using -recurse-submodules, which imports JCPP, now used as the default C preprocessor.

   Note-2: In case you do not get the JOGL sources with -recurse-submodules, you will miss the following features:

   - OculusVR Support
2. Unset your CLASSPATH environment variable:
   The Ant build requires that the JOGL jars not be visible on the classpath. On Unix, type `unsetenv CLASSPATH` into a csh or tcsh shell, or `unset CLASSPATH` into a Bourne shell. On Windows, type `set CLASSPATH=` into a command prompt.
3. Optional Copy and edit gluegen.properties:
   To specify different basic options for components and compilers,
   copy gluegen/make/gluegen.properties into your home directory (pointed to by the Java system property user.home).
4. Optional Copy and edit jogl.properties:
   To specify different basic options for the build,
   copy jogl/make/jogl.properties into your home directory (pointed to by the Java system property user.home).
   Edit the copy to change desired settings.
5. Build the source tree:
   Open a command shell in the "gluegen/make" directory of the source tree and invoke `ant` with the given properties as follows

           cd /home/dude/projects/jogamp/gluegen/make/
           ant -Dtarget.sourcelevel=1.8 -Dtarget.targetlevel=1.8 -Dtarget.rt.jar=/your/openjdk8/lib/rt.jar

   Alternatively you can also use environment variables instead of properties

           export SOURCE_LEVEL=1.8
           export TARGET_LEVEL=1.8
           export TARGET_RT_JAR=/your/openjdk8/lib/rt.jar
           ant

   Optionally you can also set certain build features via properites or environment variables

           Feature                Property                          or Environment Variable
           developer-zip-archive: build.archiveon=true                 BUILD_ARCHIVE=true
           Native Debug Code:     c.compiler.debug=true
           Java Debug Code:       javacdebuglevel="source,lines,vars"
           Cg                     jogl.cg=1

   - An experimental binding to the high-level Cg language by NVidia corporation can be generated by specifying `-Djogl.cg=1` to ant; e.g. `ant -Djogl.cg=1`. The Cg binding has been tested on Windows, Linux, and Mac OS X.
6. Test your build:
   Stay in your command shell in the "jogl/make" directory of the source tree and invoke `ant` with above properties or environment variables and use the target `junit.run`.
7. Build Javadoc:
   Stay in your command shell in the "jogl/make" directory of the source tree and invoke `ant` with above properties or environment variables and use the target `javadoc.all`. This will produce the end-user documentation for JOGL along with some auxiliary utility packages.

Note that there might be a few warnings produced by ANTLR about the C grammar and our modifications to some of the signatures of the productions; the C grammar warnings have been documented by the author of the grammar as having been investigated completely and harmless, and the warnings about our modifications are also harmless.

## Common build problems

1. Your CLASSPATH environment variable appears to be set (some JOGL classes are currently visible to the build.), and $CLASSPATH isn't set. An older version of JOGL was installed into the extension directory of the JDK you're using to build the current JOGL. On Windows and Linux, delete any ANTLR jars from jre/lib/ext, and on Mac OS X, delete them from /Library/Java/Extensions. It is generally not a good idea to drop JOGL directly into the extensions directory, as this can interfere with upgrades via Java Web Start.
2. CharScanner; panic: ClassNotFoundException: com.jogamp.gluegen.cgram.CToken This occurs because ANTLR was dropped into the Extensions directory of the JRE/JDK. On Windows and Linux, delete any ANTLR jars from jre/lib/ext, and on Mac OS X, delete them from /Library/Java/Extensions. Use the antlr.jar property in the build.xml to point to a JRE-external location of this jar file.

- Christopher Kline and Kenneth Russell, June 2003 (revised November 2006)
- Sven Gothel and Michael Bien, May 2010