changeset 4535:005c45393f0d

Support building using system CUPS (USE_SYSTEM_CUPS, CUPS_CFLAGS, CUPS_LIBS)
author andrew
date Thu, 18 Aug 2011 02:14:45 +0100
parents 8317cb1976d6
children 0c4ae84c071e
files make/sun/awt/FILES_c_unix.gmk make/sun/awt/mawt.gmk make/sun/xawt/FILES_c_unix.gmk make/sun/xawt/Makefile src/solaris/native/sun/awt/CUPSfuncs.c src/solaris/native/sun/awt/cups_fp.c src/solaris/native/sun/awt/cups_fp.h
diffstat 7 files changed, 224 insertions(+), 109 deletions(-) [+]
line wrap: on
line diff
--- a/make/sun/awt/FILES_c_unix.gmk	Tue Aug 16 10:52:27 2011 +0100
+++ b/make/sun/awt/FILES_c_unix.gmk	Thu Aug 18 02:14:45 2011 +0100
@@ -229,3 +229,8 @@
         GLXSurfaceData.c \
         AccelGlyphCache.c \
 	CUPSfuncs.c
+
+ifndef USE_SYSTEM_CUPS
+FILES_NO_MOTIF_c = \
+	cups_fp.c
+endif
--- a/make/sun/awt/mawt.gmk	Tue Aug 16 10:52:27 2011 +0100
+++ b/make/sun/awt/mawt.gmk	Thu Aug 18 02:14:45 2011 +0100
@@ -193,7 +193,16 @@
 #
 # Other extra flags needed for compiling.
 #
-CPPFLAGS += -I$(CUPS_HEADERS_PATH)
+ifdef CUPS_CFLAGS
+  CPPFLAGS += $(CUPS_CFLAGS)
+else
+  CPPFLAGS += -I$(CUPS_HEADERS_PATH)
+endif
+
+ifdef USE_SYSTEM_CUPS
+  CPPFLAGS += -DUSE_SYSTEM_CUPS
+  LDFLAGS += $(CUPS_LIBS)
+endif
 
 ifndef HEADLESS
 CPPFLAGS += -I$(OPENWIN_HOME)/include 
--- a/make/sun/xawt/FILES_c_unix.gmk	Tue Aug 16 10:52:27 2011 +0100
+++ b/make/sun/xawt/FILES_c_unix.gmk	Thu Aug 18 02:14:45 2011 +0100
@@ -88,3 +88,8 @@
 FILES_c += \
 	gtk_fp.c
 endif
+
+ifndef USE_SYSTEM_CUPS
+FILES_c += \
+	cups_fp.c
+endif
--- a/make/sun/xawt/Makefile	Tue Aug 16 10:52:27 2011 +0100
+++ b/make/sun/xawt/Makefile	Thu Aug 18 02:14:45 2011 +0100
@@ -103,12 +103,20 @@
   OTHER_LDLIBS += $(GTK_LIBS)
 endif
 
+ifdef USE_SYSTEM_CUPS
+  OTHER_LDLIBS += $(CUPS_LIBS)
+endif
+
 ifeq  ($(PLATFORM), solaris)
 CPPFLAGS += -DFUNCPROTO=15
 dummy := $(shell $(MKDIR) -p $(LIB_LOCATION))
 endif
 
-CPPFLAGS += -I$(CUPS_HEADERS_PATH)
+ifdef CUPS_CFLAGS
+  CPPFLAGS += $(CUPS_CFLAGS)
+else
+  CPPFLAGS += -I$(CUPS_HEADERS_PATH)
+endif
 
 CPPFLAGS += -DXAWT -DXAWT_HACK \
         -I$(TEMPDIR)/../../sun.awt/awt/CClassHeaders \
@@ -142,6 +150,10 @@
   CPPFLAGS += -I$(PLATFORM_SRC)/native/sun/awt/gtk2
 endif
 
+ifdef USE_SYSTEM_CUPS
+  CPPFLAGS += -DUSE_SYSTEM_CUPS
+endif
+
 ifeq ($(PLATFORM), linux)
   ifndef CROSS_COMPILE_ARCH
     # Allows for builds on Debian GNU Linux, X11 is in a different place 
--- a/src/solaris/native/sun/awt/CUPSfuncs.c	Tue Aug 16 10:52:27 2011 +0100
+++ b/src/solaris/native/sun/awt/CUPSfuncs.c	Thu Aug 18 02:14:45 2011 +0100
@@ -25,10 +25,13 @@
 
 #include <jni.h>
 #include <jni_util.h>
-#include <dlfcn.h>
 #include <cups/cups.h>
 #include <cups/ppd.h>
 
+#ifndef USE_SYSTEM_CUPS
+#include <cups_fp.h>
+#endif
+
 //#define CUPS_DEBUG
 
 #ifdef CUPS_DEBUG
@@ -37,27 +40,6 @@
 #define DPRINTF(x, y)
 #endif
 
-typedef const char* (*fn_cupsServer)(void);
-typedef int (*fn_ippPort)(void);
-typedef http_t* (*fn_httpConnect)(const char *, int);
-typedef void (*fn_httpClose)(http_t *);
-typedef char* (*fn_cupsGetPPD)(const char *);
-typedef ppd_file_t* (*fn_ppdOpenFile)(const char *);
-typedef void (*fn_ppdClose)(ppd_file_t *);
-typedef ppd_option_t* (*fn_ppdFindOption)(ppd_file_t *, const char *);
-typedef ppd_size_t* (*fn_ppdPageSize)(ppd_file_t *, char *);
-
-fn_cupsServer j2d_cupsServer;
-fn_ippPort j2d_ippPort;
-fn_httpConnect j2d_httpConnect;
-fn_httpClose j2d_httpClose;
-fn_cupsGetPPD j2d_cupsGetPPD;
-fn_ppdOpenFile j2d_ppdOpenFile;
-fn_ppdClose j2d_ppdClose;
-fn_ppdFindOption j2d_ppdFindOption;
-fn_ppdPageSize j2d_ppdPageSize;
-
-
 /*
  * Initialize library functions.
  * // REMIND : move tab , add dlClose before return
@@ -65,72 +47,11 @@
 JNIEXPORT jboolean JNICALL
 Java_sun_print_CUPSPrinter_initIDs(JNIEnv *env,
                                          jobject printObj) {
-  void *handle = dlopen("libcups.so.2", RTLD_LAZY | RTLD_GLOBAL);
-
-  if (handle == NULL) {
-    handle = dlopen("libcups.so", RTLD_LAZY | RTLD_GLOBAL);
-    if (handle == NULL) {
-      return JNI_FALSE;
-    }
-  }
-
-  j2d_cupsServer = (fn_cupsServer)dlsym(handle, "cupsServer");
-  if (j2d_cupsServer == NULL) {
-    dlclose(handle);
-    return JNI_FALSE;
-  }
-
-  j2d_ippPort = (fn_ippPort)dlsym(handle, "ippPort");
-  if (j2d_ippPort == NULL) {
-    dlclose(handle);
-    return JNI_FALSE;
-  }
-
-  j2d_httpConnect = (fn_httpConnect)dlsym(handle, "httpConnect");
-  if (j2d_httpConnect == NULL) {
-    dlclose(handle);
-    return JNI_FALSE;
-  }
-
-  j2d_httpClose = (fn_httpClose)dlsym(handle, "httpClose");
-  if (j2d_httpClose == NULL) {
-    dlclose(handle);
-    return JNI_FALSE;
-  }
-
-  j2d_cupsGetPPD = (fn_cupsGetPPD)dlsym(handle, "cupsGetPPD");
-  if (j2d_cupsGetPPD == NULL) {
-    dlclose(handle);
-    return JNI_FALSE;
-  }
-
-  j2d_ppdOpenFile = (fn_ppdOpenFile)dlsym(handle, "ppdOpenFile");
-  if (j2d_ppdOpenFile == NULL) {
-    dlclose(handle);
-    return JNI_FALSE;
-
-  }
-
-  j2d_ppdClose = (fn_ppdClose)dlsym(handle, "ppdClose");
-  if (j2d_ppdClose == NULL) {
-    dlclose(handle);
-    return JNI_FALSE;
-
-  }
-
-  j2d_ppdFindOption = (fn_ppdFindOption)dlsym(handle, "ppdFindOption");
-  if (j2d_ppdFindOption == NULL) {
-    dlclose(handle);
-    return JNI_FALSE;
-  }
-
-  j2d_ppdPageSize = (fn_ppdPageSize)dlsym(handle, "ppdPageSize");
-  if (j2d_ppdPageSize == NULL) {
-    dlclose(handle);
-    return JNI_FALSE;
-  }
-
+#ifndef USE_SYSTEM_CUPS
+  return cups_init();
+#else
   return JNI_TRUE;
+#endif
 }
 
 /*
@@ -142,7 +63,7 @@
                                          jobject printObj)
 {
     jstring cServer = NULL;
-    const char* server = j2d_cupsServer();
+    const char* server = cupsServer();
     if (server != NULL) {
         // Is this a local domain socket?
         if (strncmp(server, "/", 1) == 0) {
@@ -162,7 +83,7 @@
 Java_sun_print_CUPSPrinter_getCupsPort(JNIEnv *env,
                                          jobject printObj)
 {
-    int port = j2d_ippPort();
+    int port = ippPort();
     return (jint) port;
 }
 
@@ -180,10 +101,10 @@
     const char *serverName;
     serverName = (*env)->GetStringUTFChars(env, server, NULL);
     if (serverName != NULL) {
-        http_t *http = j2d_httpConnect(serverName, (int)port);
+        http_t *http = httpConnect(serverName, (int)port);
         (*env)->ReleaseStringUTFChars(env, server, serverName);
         if (http != NULL) {
-            j2d_httpClose(http);
+            httpClose(http);
             return JNI_TRUE;
         }
     }
@@ -216,7 +137,7 @@
 
     // NOTE: cupsGetPPD returns a pointer to a filename of a temporary file.
     // unlink() must be caled to remove the file when finished using it.
-    filename = j2d_cupsGetPPD(name);
+    filename = cupsGetPPD(name);
     (*env)->ReleaseStringUTFChars(env, printer, name);
 
     cls = (*env)->FindClass(env, "java/lang/String");
@@ -225,18 +146,18 @@
         return NULL;
     }
 
-    if ((ppd = j2d_ppdOpenFile(filename)) == NULL) {
+    if ((ppd = ppdOpenFile(filename)) == NULL) {
         unlink(filename);
         DPRINTF("CUPSfuncs::unable to open PPD  %s\n", filename);
         return NULL;
     }
 
-    optionPage = j2d_ppdFindOption(ppd, "PageSize");
+    optionPage = ppdFindOption(ppd, "PageSize");
     if (optionPage != NULL) {
         nPages = optionPage->num_choices;
     }
 
-    optionTray = j2d_ppdFindOption(ppd, "InputSlot");
+    optionTray = ppdFindOption(ppd, "InputSlot");
     if (optionTray != NULL) {
         nTrays = optionTray->num_choices;
     }
@@ -245,7 +166,7 @@
         nameArray = (*env)->NewObjectArray(env, nTotal, cls, NULL);
         if (nameArray == NULL) {
             unlink(filename);
-            j2d_ppdClose(ppd);
+            ppdClose(ppd);
             DPRINTF("CUPSfuncs::bad alloc new array\n", "")
             JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError");
             return NULL;
@@ -256,7 +177,7 @@
             utf_str = JNU_NewStringPlatform(env, choice->text);
             if (utf_str == NULL) {
                 unlink(filename);
-                j2d_ppdClose(ppd);
+                ppdClose(ppd);
                 DPRINTF("CUPSfuncs::bad alloc new string ->text\n", "")
                 JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError");
                 return NULL;
@@ -266,7 +187,7 @@
             utf_str = JNU_NewStringPlatform(env, choice->choice);
             if (utf_str == NULL) {
                 unlink(filename);
-                j2d_ppdClose(ppd);
+                ppdClose(ppd);
                 DPRINTF("CUPSfuncs::bad alloc new string ->choice\n", "")
                 JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError");
                 return NULL;
@@ -280,7 +201,7 @@
             utf_str = JNU_NewStringPlatform(env, choice->text);
             if (utf_str == NULL) {
                 unlink(filename);
-                j2d_ppdClose(ppd);
+                ppdClose(ppd);
                 DPRINTF("CUPSfuncs::bad alloc new string text\n", "")
                 JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError");
                 return NULL;
@@ -291,7 +212,7 @@
             utf_str = JNU_NewStringPlatform(env, choice->choice);
             if (utf_str == NULL) {
                 unlink(filename);
-                j2d_ppdClose(ppd);
+                ppdClose(ppd);
                 DPRINTF("CUPSfuncs::bad alloc new string choice\n", "")
                 JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError");
                 return NULL;
@@ -301,7 +222,7 @@
             (*env)->DeleteLocalRef(env, utf_str);
         }
     }
-    j2d_ppdClose(ppd);
+    ppdClose(ppd);
     unlink(filename);
     return nameArray;
 }
@@ -328,17 +249,17 @@
 
     // NOTE: cupsGetPPD returns a pointer to a filename of a temporary file.
     // unlink() must be called to remove the file after using it.
-    filename = j2d_cupsGetPPD(name);
+    filename = cupsGetPPD(name);
     (*env)->ReleaseStringUTFChars(env, printer, name);
     if (filename == NULL) {
         return NULL;
     }
-    if ((ppd = j2d_ppdOpenFile(filename)) == NULL) {
+    if ((ppd = ppdOpenFile(filename)) == NULL) {
         unlink(filename);
         DPRINTF("unable to open PPD  %s\n", filename)
         return NULL;
     }
-    option = j2d_ppdFindOption(ppd, "PageSize");
+    option = ppdFindOption(ppd, "PageSize");
     if (option != NULL && option->num_choices > 0) {
         // create array of dimensions - (num_choices * 6)
         //to cover length & height
@@ -346,7 +267,7 @@
         sizeArray = (*env)->NewFloatArray(env, option->num_choices*6);
         if (sizeArray == NULL) {
             unlink(filename);
-            j2d_ppdClose(ppd);
+            ppdClose(ppd);
             DPRINTF("CUPSfuncs::bad alloc new float array\n", "")
             JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError");
             return NULL;
@@ -355,7 +276,7 @@
         dims = (*env)->GetFloatArrayElements(env, sizeArray, NULL);
         for (i = 0; i<option->num_choices; i++) {
             choice = (option->choices)+i;
-            size = j2d_ppdPageSize(ppd, choice->choice);
+            size = ppdPageSize(ppd, choice->choice);
             if (size != NULL) {
                 // paper width and height
                 dims[i*6] = size->width;
@@ -371,7 +292,7 @@
         (*env)->ReleaseFloatArrayElements(env, sizeArray, dims, 0);
     }
 
-    j2d_ppdClose(ppd);
+    ppdClose(ppd);
     unlink(filename);
     return sizeArray;
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/solaris/native/sun/awt/cups_fp.c	Thu Aug 18 02:14:45 2011 +0100
@@ -0,0 +1,102 @@
+/*
+ * Copyright (c) 2003, 2006, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#include <dlfcn.h>
+#include <jni.h>
+
+#include <cups/cups.h>
+#include <cups/ppd.h>
+
+#include <cups_fp.h>
+
+jboolean cups_init()
+{
+  void *handle = dlopen("libcups.so.2", RTLD_LAZY | RTLD_GLOBAL);
+
+  if (handle == NULL) {
+    handle = dlopen("libcups.so", RTLD_LAZY | RTLD_GLOBAL);
+    if (handle == NULL) {
+      return JNI_FALSE;
+    }
+  }
+
+  j2d_cupsServer = (fn_cupsServer)dlsym(handle, "cupsServer");
+  if (j2d_cupsServer == NULL) {
+    dlclose(handle);
+    return JNI_FALSE;
+  }
+
+  j2d_ippPort = (fn_ippPort)dlsym(handle, "ippPort");
+  if (j2d_ippPort == NULL) {
+    dlclose(handle);
+    return JNI_FALSE;
+  }
+
+  j2d_httpConnect = (fn_httpConnect)dlsym(handle, "httpConnect");
+  if (j2d_httpConnect == NULL) {
+    dlclose(handle);
+    return JNI_FALSE;
+  }
+
+  j2d_httpClose = (fn_httpClose)dlsym(handle, "httpClose");
+  if (j2d_httpClose == NULL) {
+    dlclose(handle);
+    return JNI_FALSE;
+  }
+
+  j2d_cupsGetPPD = (fn_cupsGetPPD)dlsym(handle, "cupsGetPPD");
+  if (j2d_cupsGetPPD == NULL) {
+    dlclose(handle);
+    return JNI_FALSE;
+  }
+
+  j2d_ppdOpenFile = (fn_ppdOpenFile)dlsym(handle, "ppdOpenFile");
+  if (j2d_ppdOpenFile == NULL) {
+    dlclose(handle);
+    return JNI_FALSE;
+
+  }
+
+  j2d_ppdClose = (fn_ppdClose)dlsym(handle, "ppdClose");
+  if (j2d_ppdClose == NULL) {
+    dlclose(handle);
+    return JNI_FALSE;
+
+  }
+
+  j2d_ppdFindOption = (fn_ppdFindOption)dlsym(handle, "ppdFindOption");
+  if (j2d_ppdFindOption == NULL) {
+    dlclose(handle);
+    return JNI_FALSE;
+  }
+
+  j2d_ppdPageSize = (fn_ppdPageSize)dlsym(handle, "ppdPageSize");
+  if (j2d_ppdPageSize == NULL) {
+    dlclose(handle);
+    return JNI_FALSE;
+  }
+
+  return JNI_TRUE;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/solaris/native/sun/awt/cups_fp.h	Thu Aug 18 02:14:45 2011 +0100
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2003, 2006, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#ifndef __CUPS_FP_H__
+#define __CUPS_FP_H__
+
+typedef const char* (*fn_cupsServer)(void);
+typedef int (*fn_ippPort)(void);
+typedef http_t* (*fn_httpConnect)(const char *, int);
+typedef void (*fn_httpClose)(http_t *);
+typedef char* (*fn_cupsGetPPD)(const char *);
+typedef ppd_file_t* (*fn_ppdOpenFile)(const char *);
+typedef void (*fn_ppdClose)(ppd_file_t *);
+typedef ppd_option_t* (*fn_ppdFindOption)(ppd_file_t *, const char *);
+typedef ppd_size_t* (*fn_ppdPageSize)(ppd_file_t *, char *);
+
+fn_cupsServer j2d_cupsServer;
+fn_ippPort j2d_ippPort;
+fn_httpConnect j2d_httpConnect;
+fn_httpClose j2d_httpClose;
+fn_cupsGetPPD j2d_cupsGetPPD;
+fn_ppdOpenFile j2d_ppdOpenFile;
+fn_ppdClose j2d_ppdClose;
+fn_ppdFindOption j2d_ppdFindOption;
+fn_ppdPageSize j2d_ppdPageSize;
+
+#define cupsServer (*j2d_cupsServer)
+#define ippPort (*j2d_ippPort)
+#define httpConnect (*j2d_httpConnect)
+#define httpClose (*j2d_httpClose)
+#define cupsGetPPD (*j2d_cupsGetPPD)
+#define ppdOpenFile (*j2d_ppdOpenFile)
+#define ppdClose (*j2d_ppdClose)
+#define ppdFindOption (*j2d_ppdFindOption)
+#define ppdPageSize (*j2d_ppdPageSize)
+
+jboolean cups_init();
+
+#endif