8043805: Allow using a system-installed libjpeg
authoromajid
Fri, 23 May 2014 11:04:37 -0400
changeset 25103 4dcb7cd7652e
parent 25102 669df2eb0922
child 25104 9a002d75bd42
8043805: Allow using a system-installed libjpeg Reviewed-by: andrew, anthony, prr
jdk/make/lib/Awt2dLibraries.gmk
jdk/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageReader.java
jdk/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageWriter.java
jdk/src/share/classes/sun/awt/image/JPEGImageDecoder.java
jdk/src/share/native/sun/awt/image/jpeg/imageioJPEG.c
--- a/jdk/make/lib/Awt2dLibraries.gmk	Thu May 22 13:54:52 2014 -0700
+++ b/jdk/make/lib/Awt2dLibraries.gmk	Fri May 23 11:04:37 2014 -0400
@@ -709,21 +709,24 @@
 
 ##########################################################################################
 
+BUILD_LIBJAVAJPEG_DIR := $(JDK_TOPDIR)/src/share/native/sun/awt/image/jpeg
+
 ifdef OPENJDK
-  BUILD_LIBJPEG_MAPFILE := $(JDK_TOPDIR)/make/mapfiles/libjpeg/mapfile-vers
+  BUILD_LIBJAVAJPEG_MAPFILE := $(JDK_TOPDIR)/make/mapfiles/libjpeg/mapfile-vers
 else
-  BUILD_LIBJPEG_MAPFILE := $(JDK_TOPDIR)/make/mapfiles/libjpeg/mapfile-vers-closed
-  BUILD_LIBJPEG_CLOSED_SRC := $(JDK_TOPDIR)/src/closed/share/native/sun/awt/image/jpeg
-  BUILD_LIBJPEG_CLOSED_INCLUDES := -I$(BUILD_LIBJPEG_CLOSED_SRC)
+  BUILD_LIBJAVAJPEG_MAPFILE := $(JDK_TOPDIR)/make/mapfiles/libjpeg/mapfile-vers-closed
+  BUILD_LIBJAVAJPEG_CLOSED_SRC := $(JDK_TOPDIR)/src/closed/share/native/sun/awt/image/jpeg
+  BUILD_LIBJAVAJPEG_CLOSED_INCLUDES := -I$(BUILD_LIBJAVAJPEG_CLOSED_SRC)
 endif
 
-BUILD_LIBJPEG_REORDER :=
+BUILD_LIBJAVAJPEG_REORDER :=
 ifeq ($(OPENJDK_TARGET_OS), solaris)
   ifneq ($(OPENJDK_TARGET_CPU), x86_64)
-    BUILD_LIBJPEG_REORDER := $(JDK_TOPDIR)/make/mapfiles/libjpeg/reorder-$(OPENJDK_TARGET_CPU)
+    BUILD_LIBJAVAJPEG_REORDER := $(JDK_TOPDIR)/make/mapfiles/libjpeg/reorder-$(OPENJDK_TARGET_CPU)
   endif
 endif
 
+
 # Suppress gcc warnings like "variable might be clobbered by 'longjmp'
 # or 'vfork'": this warning indicates that some variable is placed to
 # a register by optimized compiler and it's value might be lost on longjmp().
@@ -735,37 +738,50 @@
 #      $(shell $(EXPR) $(CC_MAJORVER) \> 4 \| \
 #          \( $(CC_MAJORVER) = 4 \& $(CC_MINORVER) \>= 3 \) )
 #  ifeq ($(CC_43_OR_NEWER), 1)
-#    BUILD_LIBJPEG_CFLAGS_linux += -Wno-clobbered
+#    BUILD_LIBJAVAJPEG_CFLAGS_linux += -Wno-clobbered
 #  endif
 #endif
 
-$(eval $(call SetupNativeCompilation,BUILD_LIBJPEG, \
-    LIBRARY := jpeg, \
+ifeq ($(USE_EXTERNAL_LIBJPEG), true)
+  LIBJPEG_LIBS := -ljpeg
+  BUILD_LIBJAVAJPEG_INCLUDE_FILES := \
+      imageIOJPEG.c \
+      jpegdecoder.c
+  BUILD_LIBJAVAJPEG_HEADERS :=
+else
+  LIBJPEG_LIBS :=
+  BUILD_LIBJAVAJPEG_INCLUDE_FILES :=
+  BUILD_LIBJAVAJPEG_HEADERS := -I$(BUILD_LIBJAVAJPEG_DIR)
+endif
+
+$(eval $(call SetupNativeCompilation,BUILD_LIBJAVAJPEG, \
+    LIBRARY := javajpeg, \
     OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
-    SRC := $(BUILD_LIBJPEG_CLOSED_SRC) \
-        $(JDK_TOPDIR)/src/share/native/sun/awt/image/jpeg, \
+    SRC := $(BUILD_LIBJAVAJPEG_CLOSED_SRC) \
+        $(BUILD_LIBJAVAJPEG_DIR), \
+    INCLUDE_FILES := $(BUILD_LIBJAVAJPEG_INCLUDE_FILES), \
     LANG := C, \
     OPTIMIZATION := HIGHEST, \
     CFLAGS := $(CFLAGS_JDKLIB) \
-        $(BUILD_LIBJPEG_CLOSED_INCLUDES) \
-        -I$(JDK_TOPDIR)/src/share/native/sun/awt/image/jpeg, \
-    MAPFILE := $(BUILD_LIBJPEG_MAPFILE), \
-    LDFLAGS := $(LDFLAGS_JDKLIB) \
+        $(BUILD_LIBJAVAJPEG_CLOSED_INCLUDES) \
+        $(BUILD_LIBJAVAJPEG_HEADERS), \
+    MAPFILE := $(BUILD_LIBJAVAJPEG_MAPFILE), \
+    LDFLAGS := $(LDFLAGS_JDKLIB) $(LIBJPEG_LIBS) \
         $(call SET_SHARED_LIBRARY_ORIGIN), \
     LDFLAGS_windows := $(WIN_JAVA_LIB) jvm.lib, \
     LDFLAGS_SUFFIX := $(LDFLAGS_JDKLIB_SUFFIX), \
     VERSIONINFO_RESOURCE := $(JDK_TOPDIR)/src/windows/resource/version.rc, \
     RC_FLAGS := $(RC_FLAGS) \
-        -D "JDK_FNAME=jpeg.dll" \
-        -D "JDK_INTERNAL_NAME=jpeg" \
+        -D "JDK_FNAME=javajpeg.dll" \
+        -D "JDK_INTERNAL_NAME=javajpeg" \
         -D "JDK_FTYPE=0x2L", \
-    REORDER := $(BUILD_LIBJPEG_REORDER), \
+    REORDER := $(BUILD_LIBJAVAJPEG_REORDER), \
     OBJECT_DIR := $(JDK_OUTPUTDIR)/objs/libjpeg, \
     DEBUG_SYMBOLS := $(DEBUG_ALL_BINARIES)))
 
-$(BUILD_LIBJPEG): $(BUILD_LIBJAVA)
+$(BUILD_LIBJAVAJPEG): $(BUILD_LIBJAVA)
 
-BUILD_LIBRARIES += $(BUILD_LIBJPEG)
+BUILD_LIBRARIES += $(BUILD_LIBJAVAJPEG)
 
 ##########################################################################################
 
@@ -1213,6 +1229,13 @@
     GIFLIB_CFLAGS := -I$(JDK_TOPDIR)/src/share/native/sun/awt/giflib
   endif
 
+  ifeq ($(USE_EXTERNAL_LIBJPEG), true)
+    LIBJPEG_LDFLAGS := -ljpeg
+  else
+    LIBSPLASHSCREEN_DIRS += $(JDK_TOPDIR)/src/share/native/sun/awt/image/jpeg
+    LIBJPEG_CFLAGS := -I$(JDK_TOPDIR)/src/share/native/sun/awt/image/jpeg
+  endif
+
   ifeq ($(USE_EXTERNAL_LIBPNG), false)
     LIBSPLASHSCREEN_DIRS += $(JDK_TOPDIR)/src/share/native/sun/awt/libpng
     LIBPNG_CFLAGS := -I$(JDK_TOPDIR)/src/share/native/sun/awt/libpng
@@ -1276,12 +1299,12 @@
       LANG := C, \
       OPTIMIZATION := LOW, \
       CFLAGS := $(LIBSPLASHSCREEN_CFLAGS) $(CFLAGS_JDKLIB) \
-                $(GIFLIB_CFLAGS) $(PNG_CFLAGS), \
+                $(GIFLIB_CFLAGS) $(LIBJPEG_CFLAGS) $(PNG_CFLAGS), \
       MAPFILE := $(JDK_TOPDIR)/make/mapfiles/libsplashscreen/mapfile-vers, \
       LDFLAGS := $(LDFLAGS_JDKLIB) \
           $(call SET_SHARED_LIBRARY_ORIGIN), \
       LDFLAGS_SUFFIX := $(LIBSPLASHSCREEN_LDFLAGS_SUFFIX) $(LIBZ) \
-                        $(GIFLIB_LDFLAGS) $(PNG_LIBS), \
+                        $(GIFLIB_LDFLAGS) $(LIBJPEG_LDFLAGS) $(PNG_LIBS), \
       LDFLAGS_SUFFIX_solaris := -lc, \
       VERSIONINFO_RESOURCE := $(JDK_TOPDIR)/src/windows/resource/version.rc, \
       RC_FLAGS := $(RC_FLAGS) \
--- a/jdk/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageReader.java	Thu May 22 13:54:52 2014 -0700
+++ b/jdk/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageReader.java	Fri May 23 11:04:37 2014 -0400
@@ -89,7 +89,7 @@
         java.security.AccessController.doPrivileged(
             new java.security.PrivilegedAction<Void>() {
                 public Void run() {
-                    System.loadLibrary("jpeg");
+                    System.loadLibrary("javajpeg");
                     return null;
                 }
             });
--- a/jdk/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageWriter.java	Thu May 22 13:54:52 2014 -0700
+++ b/jdk/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageWriter.java	Fri May 23 11:04:37 2014 -0400
@@ -179,7 +179,7 @@
         java.security.AccessController.doPrivileged(
             new java.security.PrivilegedAction<Void>() {
                 public Void run() {
-                    System.loadLibrary("jpeg");
+                    System.loadLibrary("javajpeg");
                     return null;
                 }
             });
--- a/jdk/src/share/classes/sun/awt/image/JPEGImageDecoder.java	Thu May 22 13:54:52 2014 -0700
+++ b/jdk/src/share/classes/sun/awt/image/JPEGImageDecoder.java	Fri May 23 11:04:37 2014 -0400
@@ -56,7 +56,7 @@
         java.security.AccessController.doPrivileged(
             new java.security.PrivilegedAction<Void>() {
                 public Void run() {
-                    System.loadLibrary("jpeg");
+                    System.loadLibrary("javajpeg");
                     return null;
                 }
             });
--- a/jdk/src/share/native/sun/awt/image/jpeg/imageioJPEG.c	Thu May 22 13:54:52 2014 -0700
+++ b/jdk/src/share/native/sun/awt/image/jpeg/imageioJPEG.c	Fri May 23 11:04:37 2014 -0400
@@ -51,7 +51,7 @@
 
 /* headers from the JPEG library */
 #include <jpeglib.h>
-#include "jerror.h"
+#include <jerror.h>
 
 #undef MAX
 #define MAX(a,b)        ((a) > (b) ? (a) : (b))