changeset 11309:f37d03d2414b

Merge
author kcr
date Thu, 18 Jul 2019 11:47:40 -0700
parents 643499f0033f 0553463dccee
children 791cc9bd7443
files .hgtags
diffstat 15 files changed, 158 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/.hgtags	Thu Jul 18 00:21:27 2019 +0300
+++ b/.hgtags	Thu Jul 18 11:47:40 2019 -0700
@@ -536,3 +536,4 @@
 97c8468bb4c6617ca4b404b2c83c830d203190c3 13+8
 366a34279559f380d4114c8de90d0ca2eb3bcfde 13+9
 26dc4201fad298fe2acd48ea15a76f28d96d165b 14+0
+c91a28ed4845c265cd3d3340755e018da5e10698 13+10
--- a/build.gradle	Thu Jul 18 00:21:27 2019 +0300
+++ b/build.gradle	Thu Jul 18 11:47:40 2019 -0700
@@ -396,6 +396,13 @@
 defineProperty("COMPILE_PARFAIT", "false")
 ext.IS_COMPILE_PARFAIT = Boolean.parseBoolean(COMPILE_PARFAIT)
 
+defineProperty("STATIC_BUILD", "false")
+ext.IS_STATIC_BUILD = Boolean.parseBoolean(STATIC_BUILD)
+
+if (IS_STATIC_BUILD && IS_COMPILE_MEDIA) {
+    throw new GradleException("Can not have COMPILE_MEDIA when STATIC_BUILD is enabled");
+}
+
 // BUILD_TOOLS_DOWNLOAD_SCRIPT specifies a path of a gradle script which downloads
 // required build tools.
 defineProperty("BUILD_TOOLS_DOWNLOAD_SCRIPT", "")
--- a/buildSrc/linux.gradle	Thu Jul 18 00:21:27 2019 +0300
+++ b/buildSrc/linux.gradle	Thu Jul 18 11:47:40 2019 -0700
@@ -37,7 +37,7 @@
 LINUX.libDest = "lib"
 
 // Lambda for naming the generated libs
-LINUX.library = { name -> return "lib${name}.so" as String }
+LINUX.library = { name -> return (IS_STATIC_BUILD ? "lib${name}.a" : "lib${name}.so") as String }
 
 // A set of common parameters to use for both compiling and linking
 def commonFlags = [
@@ -49,6 +49,10 @@
     commonFlags += "-m32"
 }
 
+if (IS_STATIC_BUILD) {
+    commonFlags += "-DSTATIC_BUILD"
+}
+
 // Specify the compilation parameters and link parameters
 def ccFlags = [
         commonFlags, "-I$JDK_HOME/include", "-I$JDK_HOME/include/linux", "-c",
@@ -56,10 +60,14 @@
         IS_DEBUG_NATIVE ? ["-ggdb", "-DVERBOSE"] : ["-O2", "-DNDEBUG"]].flatten()
 def ccFlagsGTK3 = ccFlags
 //ccFlags.addAll(["-Wnon-virtual-dtor", "-Woverloaded-virtual", "-std=c++0x"])
-def linkFlags = ["-static-libgcc", "-static-libstdc++", "-shared", commonFlags,
+def dynamicLinkFlags = ["-static-libgcc", "-static-libstdc++", "-shared", commonFlags,
                  "-z", "relro",
                  "-Wl,--gc-sections"].flatten()
 
+def staticLinkFlags = [].flatten()
+
+def linkFlags = IS_STATIC_BUILD ? staticLinkFlags : dynamicLinkFlags;
+
 if (IS_DEBUG_NATIVE) {
     linkFlags += "-g"
 }
@@ -192,7 +200,9 @@
         def libs = properties.getProperty("libs")
         if (cflags && libs) {
             freetypeCCFlags.addAll(cflags.split(" "))
-            freetypeLinkFlags.addAll(libs.split(" "))
+            if (!IS_STATIC_BUILD) {
+                freetypeLinkFlags.addAll(libs.split(" "))
+            }
         } else {
             throw new IllegalStateException("Linux freetype packages not found.\nIf freetype pacakges are installed, please remove the build directory and try again.")
         }
@@ -200,7 +210,7 @@
 )
 
 def compiler = IS_COMPILE_PARFAIT ? "parfait-gcc" : "${toolchainDir}gcc";
-def linker = IS_COMPILE_PARFAIT ? "parfait-g++" : "${toolchainDir}g++";
+def linker = IS_STATIC_BUILD ? "ar" : IS_COMPILE_PARFAIT ? "parfait-g++" : "${toolchainDir}g++";
 
 LINUX.glass = [:]
 LINUX.glass.variants = ["glass", "glassgtk2"]
@@ -224,23 +234,27 @@
 LINUX.glass.glass.compiler = compiler
 LINUX.glass.glass.ccFlags = [ccFlags, gtk2CCFlags,  "-Werror"].flatten()
 LINUX.glass.glass.linker = linker
-LINUX.glass.glass.linkFlags = [linkFlags, "-lX11", "-ldl" ].flatten()
+LINUX.glass.glass.linkFlags = IS_STATIC_BUILD? linkFlags : [linkFlags, "-lX11", "-ldl"].flatten()
 LINUX.glass.glass.lib = "glass"
 
 LINUX.glass.glassgtk2 = [:]
 LINUX.glass.glassgtk2.nativeSource =  ft_gtk.getFiles()
 LINUX.glass.glassgtk2.compiler = compiler
-LINUX.glass.glassgtk2.ccFlags = [ccFlags, gtk2CCFlags, "-Werror"].flatten()
+LINUX.glass.glassgtk2.ccFlags = IS_STATIC_BUILD ?
+        ["-fno-threadsafe-statics", ccFlags, gtk2CCFlags].flatten() :
+        [ccFlags, gtk2CCFlags, "-Werror"].flatten()
 LINUX.glass.glassgtk2.linker = linker
-LINUX.glass.glassgtk2.linkFlags = [linkFlags, gtk2LinkFlags ].flatten()
+LINUX.glass.glassgtk2.linkFlags = IS_STATIC_BUILD ? linkFlags : [linkFlags, gtk2LinkFlags].flatten()
 LINUX.glass.glassgtk2.lib = "glassgtk2"
 
 LINUX.glass.glassgtk3 = [:]
 LINUX.glass.glassgtk3.nativeSource =  ft_gtk.getFiles()
 LINUX.glass.glassgtk3.compiler = compiler
-LINUX.glass.glassgtk3.ccFlags = [ccFlags, gtk3CCFlags, "-Werror"].flatten()
+LINUX.glass.glassgtk3.ccFlags = IS_STATIC_BUILD ?
+        ["-fno-threadsafe-statics", ccFlags, gtk3CCFlags].flatten() :
+        [ccFlags, gtk3CCFlags, "-Werror"].flatten()
 LINUX.glass.glassgtk3.linker = linker
-LINUX.glass.glassgtk3.linkFlags = [linkFlags, gtk3LinkFlags ].flatten()
+LINUX.glass.glassgtk3.linkFlags = IS_STATIC_BUILD ? linkFlags : [linkFlags, gtk3LinkFlags].flatten()
 LINUX.glass.glassgtk3.lib = "glassgtk3"
 
 LINUX.decora = [:]
@@ -285,7 +299,7 @@
 LINUX.prismES2.compiler = compiler
 LINUX.prismES2.ccFlags = ["-DLINUX", ccFlags].flatten()
 LINUX.prismES2.linker = linker
-LINUX.prismES2.linkFlags = [linkFlags, "-lX11", "-lXxf86vm", "-lGL"].flatten()
+LINUX.prismES2.linkFlags =IS_STATIC_BUILD ? linkFlags : [linkFlags, "-lX11", "-lXxf86vm", "-lGL"].flatten()
 LINUX.prismES2.lib = "prism_es2"
 
 def closedDir = file("$projectDir/../rt-closed")
@@ -302,7 +316,7 @@
 LINUX.fontFreetype.compiler = compiler
 LINUX.fontFreetype.ccFlags = ["-DJFXFONT_PLUS", ccFlags, freetypeCCFlags].flatten()
 LINUX.fontFreetype.linker = linker
-LINUX.fontFreetype.linkFlags = [linkFlags, freetypeLinkFlags].flatten()
+LINUX.fontFreetype.linkFlags = IS_STATIC_BUILD ? linkFlags : [linkFlags, freetypeLinkFlags].flatten()
 LINUX.fontFreetype.lib = "javafx_font_freetype"
 
 LINUX.fontPango = [:]
@@ -310,7 +324,7 @@
 LINUX.fontPango.compiler = compiler
 LINUX.fontPango.ccFlags = ["-DJFXFONT_PLUS", ccFlags, pangoCCFlags].flatten()
 LINUX.fontPango.linker = linker
-LINUX.fontPango.linkFlags = [linkFlags, pangoLinkFlags].flatten()
+LINUX.fontPango.linkFlags =IS_STATIC_BUILD ? linkFlags : [linkFlags, pangoLinkFlags].flatten()
 LINUX.fontPango.lib = "javafx_font_pango"
 
 LINUX.media = [:]
--- a/buildSrc/mac.gradle	Thu Jul 18 00:21:27 2019 +0300
+++ b/buildSrc/mac.gradle	Thu Jul 18 11:47:40 2019 -0700
@@ -35,7 +35,7 @@
 MAC.includeNull3d = true
 
 // Lambda for naming the generated libs
-MAC.library = { name -> return "lib${name}.dylib" as String }
+MAC.library = { name -> return (IS_STATIC_BUILD ? "lib${name}.a" : "lib${name}.dylib") as String }
 
 MAC.libDest = "lib"
 
@@ -117,9 +117,10 @@
         ccBaseFlags,
         "-std=c99",
         "-c",
+        IS_STATIC_BUILD ? "-DSTATIC_BUILD" : "",
         IS_DEBUG_NATIVE ? "-DDEBUG" : ["-O3", "-DNDEBUG"]].flatten()
 
-def linkFlags = [
+def dynamicLinkFlags = [
         commonParams,
         "-framework", "AppKit",
         "-framework", "ApplicationServices",
@@ -127,6 +128,13 @@
         "-framework", "QuartzCore",
         "-framework", "Security",
         "-dynamiclib", "-lobjc"].flatten();
+def dynamicLinkFlagsAlt = ["-dynamiclib", commonParams].flatten()
+
+def staticLinkFlags = ["-static"].flatten();
+
+def linkFlags = IS_STATIC_BUILD ? staticLinkFlags : dynamicLinkFlags
+
+def linkFlagsAlt = IS_STATIC_BUILD ? staticLinkFlags : dynamicLinkFlagsAlt
 
 def toolchainDir
 if (hasProperty('toolchainDir')) {
@@ -136,7 +144,7 @@
 }
 
 def compiler = IS_COMPILE_PARFAIT ? "parfait-clang" : "${toolchainDir}clang";
-def linker = IS_COMPILE_PARFAIT ? "parfait-clang++" : "${toolchainDir}clang++";
+def linker = IS_STATIC_BUILD ? "libtool" : IS_COMPILE_PARFAIT ? "parfait-clang++" : "${toolchainDir}clang++";
 
 MAC.glass = [:]
 MAC.glass.javahInclude = [
@@ -154,7 +162,7 @@
 MAC.decora.compiler = compiler
 MAC.decora.ccFlags = ["-O1", "-ffast-math", "-c", ccBaseFlags].flatten()
 MAC.decora.linker = linker
-MAC.decora.linkFlags = ["-dynamiclib", commonParams].flatten()
+MAC.decora.linkFlags = linkFlagsAlt
 MAC.decora.lib = "decora_sse"
 
 MAC.prism = [:]
@@ -163,7 +171,7 @@
 MAC.prism.compiler = compiler
 MAC.prism.ccFlags = ["-O3", "-DINLINE=inline", "-c", ccBaseFlags].flatten()
 MAC.prism.linker = linker
-MAC.prism.linkFlags = ["-dynamiclib", commonParams].flatten()
+MAC.prism.linkFlags = linkFlagsAlt
 MAC.prism.lib = "prism_common"
 
 MAC.prismSW = [:]
--- a/buildSrc/src/main/groovy/com/sun/javafx/gradle/LinkTask.groovy	Thu Jul 18 00:21:27 2019 +0300
+++ b/buildSrc/src/main/groovy/com/sun/javafx/gradle/LinkTask.groovy	Thu Jul 18 11:47:40 2019 -0700
@@ -39,12 +39,18 @@
         lib.getParentFile().mkdirs();
         project.exec({
             commandLine(linker);
+            if ((project.IS_LINUX) && (project.IS_STATIC_BUILD)) {
+              args("rcs");
+              args("$lib");
+            }
             // Exclude parfait files (.bc)
             args(objectDir.listFiles().findAll{ !it.getAbsolutePath().endsWith(".bc") });
             if (project.IS_WINDOWS) {
                 args("/out:$lib");
             } else {
-                args("-o", "$lib");
+                if (! ((project.IS_LINUX) && (project.IS_STATIC_BUILD))) {
+                    args("-o", "$lib");
+                }
             }
             if (project.IS_DEBUG_NATIVE && !project.IS_WINDOWS) args("-g");
             if (linkParams != null) args(linkParams);
--- a/modules/javafx.graphics/src/main/native-font/MacFontFinder.c	Thu Jul 18 00:21:27 2019 +0300
+++ b/modules/javafx.graphics/src/main/native-font/MacFontFinder.c	Thu Jul 18 11:47:40 2019 -0700
@@ -30,7 +30,7 @@
 #include <jni.h>
 #include <com_sun_javafx_font_MacFontFinder.h>
 
-#if TARGET_OS_IPHONE /* iOS */
+#if TARGET_OS_IPHONE || defined(STATIC_BUILD) /* iOS or static build */
 
 #import <CoreText/CoreText.h>
 
--- a/modules/javafx.graphics/src/main/native-font/fontpath_linux.c	Thu Jul 18 00:21:27 2019 +0300
+++ b/modules/javafx.graphics/src/main/native-font/fontpath_linux.c	Thu Jul 18 11:47:40 2019 -0700
@@ -41,6 +41,22 @@
 
 #include <jni.h>
 
+#ifdef STATIC_BUILD
+JNIEXPORT jint JNICALL
+JNI_OnLoad_javafx_font(JavaVM * vm, void * reserved) {
+#ifdef JNI_VERSION_1_8
+    //min. returned JNI_VERSION required by JDK8 for builtin libraries
+    JNIEnv *env;
+    if ((*vm)->GetEnv(vm, (void **)&env, JNI_VERSION_1_8) != JNI_OK) {
+        return JNI_VERSION_1_4;
+    }
+    return JNI_VERSION_1_8;
+#else
+    return JNI_VERSION_1_4;
+#endif
+}
+#endif
+
 /*
  * We are not explicitly linking against fontconfig. This isn't so
  * relevant for desktop platforms any more but could help on embedded
--- a/modules/javafx.graphics/src/main/native-font/freetype.c	Thu Jul 18 00:21:27 2019 +0300
+++ b/modules/javafx.graphics/src/main/native-font/freetype.c	Thu Jul 18 11:47:40 2019 -0700
@@ -37,6 +37,21 @@
 #define OS_NATIVE(func) Java_com_sun_javafx_font_freetype_OSFreetype_##func
 
 extern jboolean checkAndClearException(JNIEnv *env);
+#ifdef STATIC_BUILD
+JNIEXPORT jint JNICALL
+JNI_OnLoad_javafx_font_freetype(JavaVM * vm, void * reserved) {
+#ifdef JNI_VERSION_1_8
+    JNIEnv *env;
+    if ((*vm)->GetEnv(vm, (void **)&env, JNI_VERSION_1_8) != JNI_OK) {
+        return JNI_VERSION_1_4;
+    }
+    return JNI_VERSION_1_8;
+#else
+    return JNI_VERSION_1_4;
+#endif
+}
+#endif
+
 
 jboolean checkAndClearException(JNIEnv *env)
 {
--- a/modules/javafx.graphics/src/main/native-font/pango.c	Thu Jul 18 00:21:27 2019 +0300
+++ b/modules/javafx.graphics/src/main/native-font/pango.c	Thu Jul 18 11:47:40 2019 -0700
@@ -32,10 +32,27 @@
 #include <pango/pangoft2.h>
 #include <dlfcn.h>
 
+#ifdef STATIC_BUILD
+JNIEXPORT jint JNICALL
+JNI_OnLoad_javafx_font_pango(JavaVM * vm, void * reserved) {
+#ifdef JNI_VERSION_1_8
+    JNIEnv *env;
+    if ((*vm)->GetEnv(vm, (void **)&env, JNI_VERSION_1_8) != JNI_OK) {
+        return JNI_VERSION_1_4;
+    }
+    return JNI_VERSION_1_8;
+#else
+    return JNI_VERSION_1_4;
+#endif
+}
+#endif
+
+
 #define OS_NATIVE(func) Java_com_sun_javafx_font_freetype_OSPango_##func
 
 extern jboolean checkAndClearException(JNIEnv *env);
 
+#ifndef STATIC_BUILD // can't have this twice in a static build
 jboolean checkAndClearException(JNIEnv *env)
 {
     jthrowable t = (*env)->ExceptionOccurred(env);
@@ -45,6 +62,7 @@
     (*env)->ExceptionClear(env);
     return JNI_TRUE;
 }
+#endif
 
 /**************************************************************************/
 /*                                                                        */
--- a/modules/javafx.graphics/src/main/native-glass/gtk/GlassApplication.cpp	Thu Jul 18 00:21:27 2019 +0300
+++ b/modules/javafx.graphics/src/main/native-glass/gtk/GlassApplication.cpp	Thu Jul 18 11:47:40 2019 -0700
@@ -120,6 +120,7 @@
  * Method:    _queryLibrary
  * Signature: Signature: (IZ)I
  */
+#ifndef STATIC_BUILD
 JNIEXPORT jint JNICALL Java_com_sun_glass_ui_gtk_GtkApplication__1queryLibrary
   (JNIEnv *env, jclass clazz, jint suggestedVersion, jboolean verbose)
 {
@@ -143,6 +144,7 @@
 
     return com_sun_glass_ui_gtk_GtkApplication_QUERY_USE_CURRENT;
 }
+#endif
 
 /*
  * Class:     com_sun_glass_ui_gtk_GtkApplication
--- a/modules/javafx.graphics/src/main/native-glass/gtk/glass_general.cpp	Thu Jul 18 00:21:27 2019 +0300
+++ b/modules/javafx.graphics/src/main/native-glass/gtk/glass_general.cpp	Thu Jul 18 11:47:40 2019 -0700
@@ -120,8 +120,15 @@
 
 JavaVM* javaVM;
 
+#ifdef STATIC_BUILD
+extern "C" {
+#endif
 JNIEXPORT jint JNICALL
+#ifdef STATIC_BUILD
+JNI_OnLoad_glassgtk3(JavaVM *jvm, void *reserved)
+#else
 JNI_OnLoad(JavaVM *jvm, void *reserved)
+#endif
 {
     (void)reserved;
 
@@ -324,6 +331,10 @@
     return JNI_VERSION_1_6;
 }
 
+#ifdef STATIC_BUILD
+}
+#endif
+
 void
 glass_throw_exception(JNIEnv * env,
                       const char * exceptionClass,
--- a/modules/javafx.graphics/src/main/native-glass/gtk/launcher.c	Thu Jul 18 00:21:27 2019 +0300
+++ b/modules/javafx.graphics/src/main/native-glass/gtk/launcher.c	Thu Jul 18 11:47:40 2019 -0700
@@ -58,7 +58,11 @@
 static JavaVM* javaVM;
 
 JNIEXPORT jint JNICALL
+#ifdef STATIC_BUILD
+JNI_OnLoad_glass(JavaVM *jvm, void *reserved)
+#else
 JNI_OnLoad(JavaVM *jvm, void *reserved)
+#endif
 {
     (void) reserved;
 
--- a/modules/javafx.graphics/src/main/native-glass/mac/GlassApplication.m	Thu Jul 18 00:21:27 2019 +0300
+++ b/modules/javafx.graphics/src/main/native-glass/mac/GlassApplication.m	Thu Jul 18 11:47:40 2019 -0700
@@ -56,7 +56,11 @@
 static BOOL isEmbedded = NO;
 static BOOL disableSyncRendering = NO;
 
+#ifdef STATIC_BUILD
+jint JNICALL JNI_OnLoad_glass(JavaVM *vm, void *reserved)
+#else
 jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)
+#endif
 {
     pthread_key_create(&GlassThreadDataKey, NULL);
 
--- a/modules/javafx.graphics/src/main/native-prism-es2/macosx/MacGLFactory.c	Thu Jul 18 00:21:27 2019 +0300
+++ b/modules/javafx.graphics/src/main/native-prism-es2/macosx/MacGLFactory.c	Thu Jul 18 11:47:40 2019 -0700
@@ -33,6 +33,23 @@
 #include "../PrismES2Defs.h"
 #include "com_sun_prism_es2_MacGLFactory.h"
 
+#ifdef STATIC_BUILD
+JNIEXPORT jint JNICALL
+JNI_OnLoad_prism_es2(JavaVM *vm, void * reserved) {
+#ifdef JNI_VERSION_1_8
+    //min. returned JNI_VERSION required by JDK8 for builtin libraries
+    JNIEnv *env;
+    if ((*vm)->GetEnv(vm, (void **)&env, JNI_VERSION_1_8) != JNI_OK) {
+        return JNI_VERSION_1_4;
+    }
+    return JNI_VERSION_1_8;
+#else
+    return JNI_VERSION_1_4;
+#endif
+}
+#endif
+
+
 void printAndReleaseResources(jlong pf, jlong ctx, const char *message) {
     if (message != NULL) {
         fprintf(stderr, "%s\n", message);
--- a/modules/javafx.graphics/src/main/native-prism-es2/x11/X11GLFactory.c	Thu Jul 18 00:21:27 2019 +0300
+++ b/modules/javafx.graphics/src/main/native-prism-es2/x11/X11GLFactory.c	Thu Jul 18 11:47:40 2019 -0700
@@ -33,6 +33,22 @@
 
 #include "../PrismES2Defs.h"
 #include "com_sun_prism_es2_X11GLFactory.h"
+#ifdef STATIC_BUILD
+JNIEXPORT jint JNICALL
+JNI_OnLoad_prism_es2(JavaVM *vm, void * reserved) {
+#ifdef JNI_VERSION_1_8
+    //min. returned JNI_VERSION required by JDK8 for builtin libraries
+    JNIEnv *env;
+    if ((*vm)->GetEnv(vm, (void **)&env, JNI_VERSION_1_8) != JNI_OK) {
+        return JNI_VERSION_1_4;
+    }
+    return JNI_VERSION_1_8;
+#else
+    return JNI_VERSION_1_4;
+#endif
+}
+#endif
+
 
 void setGLXAttrs(jint *attrs, int *glxAttrs) {
     int index = 0;