Subject: [bug#41360] [PATCH v4 01/12] gnu: java-openjfx-graphics: Implement a complete compilation.

From: Alexey Abramov <[email-masked]>
Date: Sun, 7 Jun 2020 17:55:07 +0200

* gnu/packages/java.scm (java-openjfx-graphics): Add stages to build
  libdecora_sse, prism_common, glassgtk2, iio, prism_sw, prism_es2,
  font_freetype, glassgtk3, font, font_pango and glass libraries.

All the steps were taken by inspecting ./gradlew build --info result.

Signed-off-by: Alexey Abramov <[email-masked]>
---
 gnu/packages/java.scm | 642 +++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 634 insertions(+), 8 deletions(-)

diff --git a/gnu/packages/java.scm b/gnu/packages/java.scm
index 43f0f37b91..fb5d754a60 100644
--- a/gnu/packages/java.scm
+++ b/gnu/packages/java.scm
@@ -56,6 +56,7 @@
   #:use-module (gnu packages gettext)
   #:use-module (gnu packages gcc)
   #:use-module (gnu packages gl)
+  #:use-module (gnu packages glib)
   #:use-module (gnu packages ghostscript) ;lcms
   #:use-module (gnu packages gnome)
   #:use-module (gnu packages groovy)
@@ -2567,16 +2568,641 @@ distribution.")))
     (arguments
      `(#:jar-name "java-openjfx-graphics.jar"
        #:source-dir "modules/graphics/src/main/java"
-       #:tests? #f; require X
-       #:test-dir "modules/graphics/src/test"))
+       #:tests? #f               ; requires X
+       #:test-dir "modules/graphics/src/test"
+       #:test-include (list "**/*Test.*")
+       #:modules ((guix build ant-build-system)
+                  (guix build utils)
+                  (srfi srfi-1)
+                  (srfi srfi-26)
+                  (ice-9 regex)
+                  (ice-9 match))
+       #:phases
+       (let* ((jdk (assoc-ref %build-inputs "jdk"))
+              (javac/h-flags
+               '(;; When javac is compiling code it doesn't link
+                 ;; against rt.jar by default. Instead it uses special
+                 ;; symbol file lib/ct.sym with class stubs.
+                 ;; Surprisingly this file contains many but not *all*
+                 ;; of internal classes.
+                 "-XDignore.symbol.file"
+                 ;; It’s an internal option for JDK 1.7+ that prevents
+                 ;; the compiler from sharing a table that will never
+                 ;; be reused. When shared, it can’t be garbage
+                 ;; collected, continues to accumulate data, and
+                 ;; therefore wastes memory.
+                 "-XDuseUnsharedTable=true"))
+              (common-flags
+               '("-fno-strict-aliasing" "-fPIC" "-fno-omit-frame-pointer" ;; optimization flags
+                 "-fstack-protector"
+                 "-W" "-Wall" "-Wno-unused" "-Wno-parentheses"))
+              (cc-flags
+               `(,@common-flags "-c" "-ffunction-sections" "-fdata-sections"
+                                "-I" ,(string-append jdk "/include")
+                                "-I" ,(string-append jdk "/include/linux")))
+              (link-flags
+               `("-static-libgcc" "-static-libstdc++" "-shared" ,@common-flags
+                 "-z" "relro"
+                 "-Wl,--gc-sections"))
+              (java-aux-class?
+               (lambda (class)
+                 (string-match "\\$[0-9]+\\.class" class)))
+              (java-list-classes
+               (lambda (path)
+                 ;; For each .java file we need to figure out what
+                 ;; class the .java file belongs in and convert it to a
+                 ;; class name.
+                 (filter-map
+                  (lambda (class)
+                    (let* ((rx (make-regexp (string-append path file-name-separator-string "?")))
+                           (class (string-drop-right class (string-length ".class")))
+                           (class (match:suffix (regexp-exec rx class))))
+                      (if (java-aux-class? class)
+                          #f
+                          (string-join (string-split class #\/) "."))))
+                  (find-files path "\\.class$")))))
+         (modify-phases %standard-phases
+
+           (replace 'build
+             (lambda _
+               ;; Do not mix different classes. There will be more stuff in build/classes
+               (invoke "ant" "compile" "-Dclasses.dir=modules/graphics/build/classes/java/main")
+               #t))
+
+           ;; XX: Description can be found in build.gradle:1429. Currently
+           ;; there is no sdk creation step.
+           ;;
+           ;; The Decora and Prism JSL files have to be generated in a very specific set of steps.
+           ;;      1) Compile the *Compile.java classes. These live in src/main/jsl-* and will be
+           ;;         output to $buildDir/classes/jsl-compilers/* (where * == decora or prism).
+           ;;      2) Generate source files from the JSL files contained in src/main/jsl-*. These
+           ;;         will be output to $buildDir/generated-src/jsl-*
+           ;;      3) Compile the JSL Java sources in $buildDir/generated-src/jsl-* and put the output
+           ;;         into classes/jsl-*
+           ;;      4) Compile the native JSL sources in $buildDir/generated-src/jsl-* and put the obj
+           ;;         files into native/jsl-* and the resulting library into libs/jsl-*.dll|so|dylib
+           ;;      5) Modify the jar step to include classes/jsl-*
+           ;; The native library must be copied over during SDK creation time in the "sdk" task. In
+           ;; addition to these steps, the clean task is created. Note that I didn't bother to create
+           ;; a new task for each of the decora files, preferring instead just to create a rule?? Also
+           ;; need "clean" tasks for each compile task.
+           (add-after 'build 'compile-prism-compilers
+             (lambda _
+               (let ((prism-compilers-classes "modules/graphics/build/classes/jsl-compilers/prism")
+                     (prism-src "modules/graphics/src/main/jsl-prism/"))
+                 (mkdir-p prism-compilers-classes)
+
+                 (apply invoke "javac" "-d" prism-compilers-classes
+                        (append javac/h-flags (find-files prism-src "\\.java"))))
+
+               #t))
+
+           (add-after 'compile-prism-compilers 'generate-prism-shaders
+             (lambda _
+               (let ((prism-compilers-classes "modules/graphics/build/classes/jsl-compilers/prism")
+                     (prism-src "modules/graphics/src/main/jsl-prism/")
+                     (prism-gen-src "modules/graphics/build/generated-src/jsl-prism"))
+                 (mkdir-p prism-gen-src)
+                 (for-each (lambda (file)
+                             (apply invoke "java"
+                                    "-cp" (string-join (list
+                                                        ;; For CompileJSL
+                                                        prism-compilers-classes
+                                                        ;; jsl files are there
+                                                        prism-src
+                                                        (getenv "CLASSPATH"))
+                                                       ":")
+                                    "CompileJSL"
+                                    "-i" prism-src
+                                    "-o" prism-gen-src
+                                    "-t"
+                                    "-pkg" "com/sun/prism"
+                                    "-d3d"
+                                    "-es2"
+                                    "-name" (list file)))
+                           (find-files prism-src "\\.jsl$")))
+               #t))
+
+           (add-after 'generate-prism-shaders 'compile-prism-shaders
+             (lambda _
+               (let* ((classes "modules/graphics/build/classes/java/main")
+                      (prism-classes "modules/graphics/build/classes/jsl-prism")
+                      (prism-gen-src "modules/graphics/build/generated-src/jsl-prism")
+                      (prism-gen-shaders-src (string-append prism-gen-src "/com/sun/prism/shader")))
+                 (mkdir-p prism-classes)
+                 (apply invoke "javac"
+                        "-d" prism-classes
+                        "-cp" (string-append classes ":" (getenv "CLASSPATH"))
+                        (append javac/h-flags (find-files prism-gen-shaders-src))))
+               #t))
+
+           (add-after 'compile-prism-shaders 'compile-decora-compilers
+             (lambda _
+               (let ((classes "modules/graphics/build/classes/java/main")
+                     (decora-compilers-classes "modules/graphics/build/classes/jsl-compilers/decora")
+                     (decora-src "modules/graphics/src/main/jsl-decora/"))
+                 (mkdir-p decora-compilers-classes)
+                 (apply invoke "javac"
+                        "-d" decora-compilers-classes
+                        "-cp" (string-append classes ":" (getenv "CLASSPATH"))
+                        (append javac/h-flags (find-files decora-src "\\.java"))))
+               #t))
+
+           (add-after 'compile-decora-compilers 'generate-decora-shaders
+             (lambda _
+               (let ((classes "modules/graphics/build/classes/java/main")
+                     (decora-classes "modules/graphics/build/classes/jsl-decora/")
+                     (decora-compilers-classes "modules/graphics/build/classes/jsl-compilers/decora")
+                     (decora-gen-src "modules/graphics/build/generated-src/jsl-decora")
+                     (decora-src "modules/graphics/src/main/jsl-decora/")
+                     (decora-components '([(file-name . "ColorAdjust")
+                                           (generator . "CompileJSL")
+                                           (outputs . "-all")]
+                                          [(file-name . "Brightpass")
+                                           (generator . "CompileJSL")
+                                           (outputs . "-all")]
+                                          [(file-name . "SepiaTone")
+                                           (generator . "CompileJSL")
+                                           (outputs . "-all")]
+                                          [(file-name . "PerspectiveTransform")
+                                           (generator . "CompileJSL")
+                                           (outputs . "-all")]
+                                          [(file-name . "DisplacementMap")
+                                           (generator . "CompileJSL")
+                                           (outputs . "-all")]
+                                          [(file-name . "InvertMask")
+                                           (generator . "CompileJSL")
+                                           (outputs . "-all")]
+                                          [(file-name . "Blend")
+                                           (generator . "CompileBlend")
+                                           (outputs . "-all")]
+                                          [(file-name . "PhongLighting")
+                                           (generator . "CompilePhong")
+                                           (outputs . "-all")]
+                                          [(file-name . "LinearConvolve")
+                                           (generator . "CompileLinearConvolve")
+                                           (outputs . "-hw")]
+                                          [(file-name . "LinearConvolveShadow")
+                                           (generator . "CompileLinearConvolve")
+                                           (outputs . "-hw")])))
+                 (mkdir-p decora-gen-src)
+                 (for-each (match-lambda
+                             ((('file-name . file-name)
+                               ('generator . generator)
+                               ('outputs . outputs))
+                              (apply invoke "java"
+                                     "-cp" (string-join (cons* classes
+                                                               decora-src
+                                                               ;; CompileJSL
+                                                               decora-compilers-classes
+                                                               decora-classes
+                                                               ;; We need resources from the build
+                                                               "buildSrc/src/main/resources"
+                                                               (list (getenv "CLASSPATH")))
+                                                        ":")
+                                     generator
+                                     "-i" decora-src
+                                     "-o" decora-gen-src
+                                     "-t"
+                                     "-pkg" "com/sun/scenario/effect"
+                                     outputs
+                                     (list file-name))))
+                           decora-components)
+                 #t)))
+
+           (add-after 'generate-decora-shaders 'compile-decora-shaders
+             (lambda _
+               (let ((classes "modules/graphics/build/classes/java/main")
+                     (decora-classes "modules/graphics/build/classes/jsl-decora/")
+                     (decora-gen-src "modules/graphics/build/generated-src/jsl-decora"))
+                 (mkdir-p decora-classes)
+                 (apply invoke "javac"
+                        "-d" decora-classes
+                        "-cp" classes
+                        (append javac/h-flags (find-files decora-gen-src "\\.java$"))))
+               #t))
+
+           (add-after 'compile-decora-shaders 'compile-decora-native-lib
+             (lambda* (#:key inputs #:allow-other-keys)
+               (let* ((classes "modules/graphics/build/classes/java/main")
+                      (decora-gen-headers "modules/graphics/build/generated-src/headers/jsl-decora")
+                      (decora-gen-src "modules/graphics/build/generated-src/jsl-decora")
+                      (decora-native-lib "modules/graphics/build/libs/jsl-decora/linux/libdecora_sse.so")
+                      (decora-native-obj "modules/graphics/build/native/jsl-decora/linux")
+                      (decora-native-src "modules/graphics/src/main/native-decora")
+                      (decora-src "modules/graphics/src/main/jsl-decora/")
+                      (decora-classes "modules/graphics/build/classes/jsl-decora/")
+                      (decora-cc-flags `(,@cc-flags "-ffast-math")))
+                 (mkdir-p decora-gen-headers)
+                 (apply invoke "javah"
+                        "-d" decora-gen-headers
+                        "-cp" (string-join (list classes decora-classes) ":")
+                        (append javac/h-flags
+                                (filter (cut string-prefix? "com.sun.scenario.effect.impl.sw.sse" <>)
+                                        (append (java-list-classes classes)
+                                                (java-list-classes decora-classes)))))
+                 (mkdir-p decora-native-obj)
+                 (for-each (lambda (cc)
+                             (apply invoke "gcc"
+                                    "-I" decora-gen-headers
+                                    "-I" decora-gen-src
+                                    "-I" decora-native-src
+                                    "-o" (string-append decora-native-obj  "/" (basename cc ".cc") ".obj")
+                                    (append decora-cc-flags (list cc))))
+                           (append (find-files decora-gen-src "\\.cc$")
+                                   (find-files decora-native-src "\\.cc$")))
+                 (mkdir-p (dirname decora-native-lib))
+                 (apply invoke "g++" "-o" decora-native-lib
+                        (append link-flags (find-files decora-native-obj "\\.obj$"))))
+               #t))
+
+           (add-after 'compile-decora-native-lib 'compile-linux-font-native-lib
+             (lambda* (#:key inputs #:allow-other-keys)
+               (let* ((classes "modules/graphics/build/classes/java/main")
+                      (font-gen-headers "modules/graphics/build/generated-src/headers/font/linux")
+                      (font-native-lib "modules/graphics/build/libs/font/linux/libjavafx_font.so")
+                      (font-native-obj "modules/graphics/build/native/font/linux")
+                      (font-native-src "modules/graphics/src/main/native-font")
+                      ;;
+                      (font-cc-flags `("-DJFXFONT_PLUS" ,@cc-flags)))
+                 (mkdir-p font-gen-headers)
+                 (apply invoke "javah"
+                        "-d" font-gen-headers
+                        "-cp" classes
+                        (append javac/h-flags
+                                (filter (lambda (class)
+                                          (or (string-prefix? "com.sun.javafx.font" class)
+                                              (string-prefix? "com.sun.javafx.text" class)))
+                                        (java-list-classes classes))))
+                 (mkdir-p font-native-obj)
+                 (for-each (lambda (cc)
+                             (apply invoke "gcc"
+                                    "-I" font-gen-headers
+                                    "-I" font-native-src
+                                    "-o" (string-append font-native-obj "/"
+                                                        (basename cc ".c") ".obj")
+                                    (append font-cc-flags (list cc))))
+                           (find-files font-native-src "\\.c$"))
+                 (mkdir-p (dirname font-native-lib))
+                 (apply invoke "g++"
+                        "-o" font-native-lib
+                        (append link-flags
+                                (find-files font-native-obj "\\.obj$"))))
+               #t))
+
+           (add-after 'compile-linux-font-native-lib 'compile-linux-font-freetype
+             (lambda* (#:key inputs #:allow-other-keys)
+               (let* ((classes "modules/graphics/build/classes/java/main")
+                      ;;
+                      (font-freetype-gen-headers "modules/graphics/build/generated-src/headers/fontFreetype/linux")
+                      (font-freetype-native-lib "modules/graphics/build/libs/fontFreetype/linux/libjavafx_font_freetype.so")
+                      (font-freetype-native-obj "modules/graphics/build/native/fontFreetype/linux")
+                      (font-freetype-native-src "modules/graphics/src/main/native-font/freetype.c")
+                      (font-freetype-cc-flags `("-DJFXFONT_PLUS" "-D_ENABLE_PANGO"
+                                                "$(pkg-config --cflags freetype2)" ,@cc-flags))
+                      (font-freetype-link-flags `("$(pkg-config --libs freetype2)" ,@link-flags)))
+                 (mkdir-p font-freetype-gen-headers)
+                 (apply invoke "javah"
+                        "-d" font-freetype-gen-headers
+                        "-cp" classes
+                        (append javac/h-flags
+                                (filter (cut string-prefix? "com.sun.javafx.font.freetype.OSFreetype" <>)
+                                        (java-list-classes classes))))
+                 (mkdir-p font-freetype-native-obj)
+                 (invoke "bash" "-c"
+                         (string-join `("gcc"
+                                        ,@font-freetype-cc-flags
+                                        "-I" ,font-freetype-gen-headers
+                                        "-I" ,(dirname font-freetype-native-src)
+                                        "-o" ,(string-append font-freetype-native-obj "/"
+                                                             (basename font-freetype-native-src ".c") ".obj")
+                                        ,font-freetype-native-src)))
+                 (mkdir-p (dirname font-freetype-native-lib))
+                 (invoke "bash" "-c"
+                         (string-join `("g++"
+                                        "-o" ,font-freetype-native-lib
+                                        ,@font-freetype-link-flags
+                                        ,@(find-files font-freetype-native-obj "\\.obj$"))))
+                 #t)))
+
+           (add-after 'compile-linux-font-freetype 'compile-linux-font-pango-lib
+             (lambda* (#:key inputs #:allow-other-keys)
+               (let* ((classes "modules/graphics/build/classes/java/main")
+                      (font-pango-gen-headers "modules/graphics/build/generated-src/headers/fontPango/linux")
+                      (font-pango-native-lib "modules/graphics/build/libs/fontPango/linux/libjavafx_font_pango.so")
+                      (font-pango-native-obj "modules/graphics/build/native/fontPango/linux")
+                      (font-pango-native-src "modules/graphics/src/main/native-font/pango.c")
+                      (font-pango-cc-flags `("-DJFXFONT_PLUS" "-D_ENABLE_PANGO"
+                                             "$(pkg-config --cflags pangoft2)" ,@cc-flags))
+                      (font-pango-link-flags `("$(pkg-config --libs pangoft2)" ,@link-flags)))
+                 (mkdir-p font-pango-gen-headers)
+                 (apply invoke "javah"
+                        "-d" font-pango-gen-headers
+                        "-cp" classes
+                        (append javac/h-flags
+                                (filter (cut string-prefix? "com.sun.javafx.font.freetype.OSPango" <>)
+                                        (java-list-classes classes))))
+                 (mkdir-p font-pango-native-obj)
+                 (invoke "bash" "-c"
+                         (string-join `("gcc"
+                                        ,@font-pango-cc-flags
+                                        "-I" ,font-pango-gen-headers
+                                        "-I" ,(dirname font-pango-native-src)
+                                        "-o" ,(string-append font-pango-native-obj "/"
+                                                             (basename font-pango-native-src ".c") ".obj")
+                                        ,font-pango-native-src)))
+                 (mkdir-p (dirname font-pango-native-lib))
+                 (invoke "bash" "-c"
+                         (string-join `("g++"
+                                        ,@font-pango-link-flags
+                                        "-o" ,font-pango-native-lib
+                                        ,@(find-files font-pango-native-obj "\\.obj$")))))
+               #t))
+
+           (add-after 'compile-linux-font-pango-lib 'compile-linux-glass-lib
+             (lambda* (#:key inputs #:allow-other-keys)
+               (let* ((classes "modules/graphics/build/classes/java/main")
+                      ;; glass
+                      (glass-gen-headers "modules/graphics/build/generated-src/headers/glass/linux")
+                      (glass-native-lib "modules/graphics/build/libs/glass/linux/libglass.so")
+                      (glass-native-obj "modules/graphics/build/native/glass/linux/glass")
+                      (glass-native-src "modules/graphics/src/main/native-glass/gtk/launcher.c")
+                      (glass-cc-flags
+                       `(,@cc-flags
+                         "$(pkg-config --cflags glib-2.0 gdk-2.0 gtk+-2.0 gthread-2.0 xtst)"
+                         "-Werror"))
+                      (glass-link-flags
+                       `(,@link-flags "$(pkg-config --libs x11)" "-ldl"))
+                      ;; glass-gtk2
+                      (gtk (assoc-ref inputs "gtk"))
+                      (glass-gtk2-native-obj "modules/graphics/build/native/glass/linux/glassgtk2")
+                      (glass-gtk2-native-src (dirname glass-native-src))
+                      (glass-gtk2-native-lib "modules/graphics/build/libs/glass/linux/libglassgtk2.so")
+                      (glass-gtk2-cc-flags
+                       `(,@cc-flags
+                         "$(pkg-config --cflags gtk+-2.0 gthread-2.0 xtst)"
+                         ;; XX: GTimeVal has been deprecated in GLIB since
+                         ;; version 2.62. GTimeVal s not year-2038-safe. Gtk
+                         ;; 2.24 uses GTimeVal so our build is also failing.
+                         "-Wno-deprecated-declarations"
+                         "-Werror"))
+                      (glass-gtk2-link-flags
+                       `(,@link-flags
+                         "$(pkg-config --libs gtk+-2.0 gthread-2.0 xtst)"))
+                      ;; glass-gtk3
+                      (gtk3 (assoc-ref inputs "gtk3"))
+                      (glass-gtk3-native-obj "modules/graphics/build/native/glass/linux/glassgtk3")
+                      (glass-gtk3-native-src (dirname glass-native-src))
+                      (glass-gtk3-native-lib "modules/graphics/build/libs/glass/linux/libglassgtk3.so")
+                      (glass-gtk3-cc-flags
+                       `(,@cc-flags
+                         "$(pkg-config --cflags gtk+-3.0 gthread-2.0 xtst)"
+                         "-Wno-deprecated-declarations" "-Werror"))
+                      (glass-gtk3-link-flags
+                       `(,@link-flags "$(pkg-config --libs gtk+-3.0 gthread-2.0 xtst)")))
+                 ;; glass
+                 (mkdir-p glass-gen-headers)
+                 (apply invoke "javah"
+                        "-d" glass-gen-headers
+                        "-cp" (string-append classes ":" (getenv "CLASSPATH"))
+                        (append javac/h-flags
+                                (filter (lambda (class)
+                                          (or (string-prefix? "com.sun.glass.events" class)
+                                              (string-prefix? "com.sun.glass.ui.gtk" class)
+                                              (string-prefix? "com.sun.glass.ui" class)))
+                                        (java-list-classes classes))))
+                 (mkdir-p glass-native-obj)
+                 (invoke "bash" "-c"
+                         (string-join `("gcc"
+                                        ,@glass-cc-flags
+                                        "-I" ,glass-gen-headers
+                                        "-I" ,(dirname glass-native-src)
+                                        "-o" ,(string-append glass-native-obj "/"
+                                                             (basename glass-native-src ".c") ".obj")
+                                        ,glass-native-src)))
+                 (mkdir-p (dirname glass-native-lib))
+                 (invoke "bash" "-c"
+                         (string-join `("g++"
+                                        ,@glass-link-flags
+                                        "-o" ,glass-native-lib
+                                        ,@(find-files glass-native-obj "\\.obj$"))))
+                 ;; gtk2
+                 (mkdir-p glass-gtk2-native-obj)
+                 (for-each (lambda (cpp)
+                             (invoke "bash" "-c"
+                                     (string-join `("gcc"
+                                                    ,@glass-gtk2-cc-flags
+                                                    "-I" ,glass-gen-headers
+                                                    "-o" ,(string-append glass-gtk2-native-obj "/"
+                                                                         (basename cpp ".cpp") ".obj")
+                                                    ,cpp))))
+                           (find-files glass-gtk2-native-src "\\.cpp$"))
+                 (mkdir-p (dirname glass-gtk2-native-lib))
+                 (invoke "bash" "-c"
+                         (string-join `("g++"
+                                        ,@glass-gtk2-link-flags
+                                        "-o" ,glass-gtk2-native-lib
+                                        ,@(find-files glass-gtk2-native-obj "\\.obj$"))))
+                 ;; gtk3
+                 (mkdir-p glass-gtk3-native-obj)
+                 (for-each (lambda (cpp)
+                             (invoke "bash" "-c"
+                                     (string-join `("gcc"
+                                                    ,@glass-gtk3-cc-flags
+                                                    "-I" ,glass-gen-headers
+                                                    "-o" ,(string-append glass-gtk3-native-obj "/"
+                                                                         (basename cpp ".cpp") ".obj")
+                                                    ,cpp))))
+                           (find-files glass-gtk3-native-src "\\.cpp$"))
+                 (mkdir-p (dirname glass-gtk3-native-lib))
+                 (invoke "bash" "-c"
+                         (string-join `("g++"
+                                        ,@glass-gtk3-link-flags
+                                        "-o" ,glass-gtk3-native-lib
+                                        ,@(find-files glass-gtk3-native-obj "\\.obj$")))))
+               #t))
+
+           (add-after 'compile-linux-glass-lib  'compile-linux-iio
+             (lambda* (#:key inputs #:allow-other-keys)
+               (let* ((classes "modules/graphics/build/classes/java/main")
+                      (iio-gen-headers "modules/graphics/build/generated-src/headers/iio/linux")
+                      (iio-native-lib "modules/graphics/build/libs/iio/linux/libjavafx_iio.so")
+                      (iio-native-obj "modules/graphics/build/native/iio/linux")
+                      (iio-native-src "modules/graphics/src/main/native-iio")
+                      (iio-cc-flags cc-flags)
+                      (iio-link-flags link-flags))
+                 (mkdir-p iio-gen-headers)
+                 (apply invoke "javah"
+                        "-d" iio-gen-headers
+                        "-cp" (string-append classes ":" (getenv "CLASSPATH"))
+                        (append javac/h-flags
+                                (filter (cut string-prefix? "com.sun.javafx.iio" <>)
+                                        (java-list-classes classes))))
+                 (mkdir-p iio-native-obj)
+                 (for-each (lambda (c)
+                             (invoke "bash" "-c"
+                                     (string-join `("gcc"
+                                                    ,@iio-cc-flags
+                                                    "-I" ,iio-gen-headers
+                                                    "-o" ,(string-append iio-native-obj "/"
+                                                                         (basename c ".c") ".obj")
+                                                    ,c))))
+                           (find-files iio-native-src "\\.c$"))
+                 (mkdir-p (dirname iio-native-lib))
+                 (invoke "bash" "-c"
+                         (string-join `("g++"
+                                        ,@iio-link-flags
+                                        "-o" ,iio-native-lib
+                                        ,@(find-files iio-native-obj "\\.obj$"))))
+                 #t)))
+
+           (add-after 'compile-linux-iio 'compile-linux-prism
+             (lambda* (#:key inputs #:allow-other-keys)
+               (let* ((classes "modules/graphics/build/classes/java/main")
+                      (prism-gen-headers "modules/graphics/build/generated-src/headers/prism/linux")
+                      (prism-native-lib "modules/graphics/build/libs/prism/linux/libprism_common.so")
+                      (prism-native-obj "modules/graphics/build/native/prism/linux")
+                      (prism-native-src "modules/graphics/src/main/native-prism")
+                      (prism-cc-flags `(,@cc-flags "-DINLINE=inline"))
+                      (prism-link-flags link-flags))
+                 (mkdir-p prism-gen-headers)
+                 (apply invoke "javah"
+                        "-d" prism-gen-headers
+                        "-cp" (string-append classes ":" (getenv "CLASSPATH"))
+                        (append javac/h-flags
+                                (filter (lambda (class)
+                                          (or (string-prefix? "com.sun.prism.impl" class)
+                                              (string-prefix? "com.sun.prism.PresentableState" class)))
+                                        (java-list-classes classes))))
+                 (mkdir-p prism-native-obj)
+                 (for-each (lambda (c)
+                             (invoke "bash" "-c"
+                                     (string-join `("gcc"
+                                                    ,@prism-cc-flags
+                                                    "-I" ,prism-gen-headers
+                                                    "-I" ,prism-native-src
+                                                    "-o" ,(string-append prism-native-obj "/"
+                                                                         (basename c ".c") ".obj")
+                                                    ,c))))
+                           (find-files prism-native-obj "\\.c$"))
+                 (mkdir-p (dirname prism-native-lib))
+                 (invoke "bash" "-c"
+                         (string-join `("g++"
+                                        ,@prism-link-flags
+                                        "-o" ,prism-native-lib
+                                        ,@(find-files prism-native-obj "\\.obj$"))))
+                 #t)))
+
+           (add-after 'compile-linux-prism 'compile-linux-prism-es2
+             (lambda* (#:key inputs #:allow-other-keys)
+               (let* ((classes "modules/graphics/build/classes/java/main")
+                      (prism-es2-gen-headers "modules/graphics/build/generated-src/headers/prismES2/linux")
+                      (prism-es2-native-lib "modules/graphics/build/libs/prism/linux/libprism_es2.so")
+                      (prism-es2-native-obj "modules/graphics/build/native/prismES2/linux")
+                      (prism-es2-native-src "modules/graphics/src/main/native-prism-es2")
+                      (prism-es2-cc-flags `("-DLINUX" ,@cc-flags))
+                      (prism-es2-link-flags
+                       `(,@link-flags "$(pkg-config --libs x11 xxf86vm gl)"))
+                      ;; We need all *.c files in the root and only those
+                      ;; which are in a specific directories.
+                      (filter-src
+                       (lambda (abs _)
+                         (or (regexp-exec (make-regexp (string-append prism-es2-native-src "[^/]*\\.c$"))
+                                          abs)
+                             (regexp-exec (make-regexp (string-append prism-es2-native-src "(x11/|GL/)"))
+                                          abs)))))
+                 (mkdir-p prism-es2-gen-headers)
+                 (apply invoke "javah"
+                        "-d" prism-es2-gen-headers
+                        "-cp" (string-append classes ":" (getenv "CLASSPATH"))
+                        (append javac/h-flags
+                                (filter (cut string-prefix? "com.sun.prism.es2" <>)
+                                        (java-list-classes classes))))
+                 (mkdir-p prism-es2-native-obj)
+                 (for-each (lambda (c)
+                             (apply invoke "gcc"
+                                    "-I" glass-native-src
+                                    "-I" prism-es2-gen-headers
+                                    "-I" prism-es2-native-src
+                                    "-I" (string-append prism-es2-native-src "/GL")
+                                    "-I" (string-append prism-es2-native-src "/x11")
+                                    "-o" (string-append prism-es2-native-obj "/" (basename c ".c") ".obj")
+                                    (append prism-es2-cc-flags (list c))))
+                           (find-files prism-es2-native-src filter-src))
+                 (mkdir-p (dirname prism-es2-native-lib))
+                 (invoke "bash" "-c"
+                         (string-join `("g++"
+                                        ,@prism-es2-link-flags
+                                        "-o" ,prism-es2-native-lib
+                                        ,@(find-files prism-es2-native-obj "\\.obj$"))))
+                 #t)))
+
+           (add-after 'compile-linux-prism-es2 'compile-linux-prism-sw
+             (lambda* (#:key inputs #:allow-other-keys)
+               (let* ((classes "modules/graphics/build/classes/java/main")
+                      (prism-sw-gen-headers "modules/graphics/build/generated-src/headers/prismSW/linux")
+                      (prism-sw-native-lib "modules/graphics/build/libs/prism/linux/libprism_sw.so")
+                      (prism-sw-native-obj "modules/graphics/build/native/prismSW/linux")
+                      (prism-sw-native-src "modules/graphics/src/main/native-prism-sw")
+                      ;;
+                      (prism-sw-cc-flags `(,@cc-flags "-DINLINE=inline"))
+                      (prism-sw-link-flags link-flags))
+                 (mkdir-p prism-sw-gen-headers)
+                 (apply invoke "javah"
+                        "-d" prism-sw-gen-headers
+                        "-cp" (string-append classes ":" (getenv "CLASSPATH"))
+                        (append javac/h-flags
+                                (filter (cut string-prefix? "com.sun.pisces" <>)
+                                        (java-list-classes classes))))
+                 (mkdir-p prism-sw-native-obj)
+                 (for-each (lambda (c)
+                             (invoke "bash" "-c"
+                                     (string-join `("gcc"
+                                                    ,@prism-sw-cc-flags
+                                                    "-I" ,prism-sw-gen-headers
+                                                    "-I" ,prism-sw-native-src
+                                                    "-o" ,(string-append prism-sw-native-obj "/"
+                                                                         (basename c ".c") ".obj")
+                                                    ,c))))
+                           (find-files prism-sw-native-src "\\.c$"))
+                 (mkdir-p (dirname prism-sw-native-lib))
+                 (apply invoke "g++" "-o" prism-sw-native-lib
+                        (append prism-sw-link-flags (find-files prism-sw-native-obj "\\.obj$")))
+                 #t)))
+
+           (add-after 'compile-linux-prism-sw 'install-native
+             (lambda* (#:key outputs #:allow-other-keys)
+               (let ((lib (string-append (assoc-ref outputs "out") "/lib")))
+                 (for-each (lambda (file)
+                             (install-file file lib))
+                           (find-files "." "\\.so$"))
+                 #t)))
+
+           (add-after 'install-native 'build-jar
+             (lambda _
+               (let* ((module (string-append "modules/graphics"))
+                      (resources (string-append module "/src/main/resources"))
+                      (classes (string-append module "/build/classes/java/main")))
+                 (copy-recursively resources classes)
+
+                 (invoke "ant" "jar" (string-append "-Dclasses.dir=" classes)))
+               #t))))))
+    (native-inputs
+     `(("freetype" ,freetype)
+       ("fontconfig" ,fontconfig)
+       ("gcc" ,gcc)
+       ("glib" ,glib)
+       ("zlib" ,zlib)
+       ("gtk" ,gtk+-2)
+       ("gtk3" ,gtk+)
+       ("jpeg" ,libjpeg-turbo)
+       ("libxtst" ,libxtst)
+       ("pango" ,pango)
+       ("libpng" ,libpng)
+       ("pkg-config" ,pkg-config)))
     (propagated-inputs
      `(("java-openjfx-base" ,java-openjfx-base)
-       ("java-swt" ,java-swt)))
-    (description "OpenJFX is a client application platform for desktop,
-mobile and embedded systems built on Java.  Its goal is to produce a
-modern, efficient, and fully featured toolkit for developing rich client
-applications.  This package contains graphics-related classes for the
-OpenJFX distribution.")))
+       ("java-swt" ,java-swt)))))
 
 (define-public java-openjfx-media
   (package (inherit java-openjfx-build)
-- 
2.26.2