[gdk-pixbuf] io: extend support for relotations to OS X and Linux



commit a55aa6ebd4c8a1892bb17b72f3bd18ca90bce01d
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Sun Sep 28 13:21:59 2014 +0200

    io: extend support for relotations to OS X and Linux
    
    https://bugzilla.gnome.org/show_bug.cgi?id=737523

 configure.ac                    |   26 +++++++++++++++++
 gdk-pixbuf/gdk-pixbuf-io.c      |   58 +++++++++++++++++++++++++++-----------
 gdk-pixbuf/gdk-pixbuf-private.h |    4 +-
 gdk-pixbuf/gdk-pixbuf-util.c    |   26 +++++++++++-------
 4 files changed, 85 insertions(+), 29 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 650a63c..e2c1f67 100644
--- a/configure.ac
+++ b/configure.ac
@@ -129,6 +129,10 @@ AC_SUBST(EXE_MANIFEST_ARCHITECTURE)
 case $host in
   *-*-linux*)
     os_linux=yes
+    AC_DEFINE(OS_LINUX, 1, [Define to 1 if it's a Linux platform])
+    ;;
+  *-*-darwin*)
+    AC_DEFINE(OS_DARWIN, 1, [Define to 1 if it's a darwin platform])
     ;;
 esac
 
@@ -1065,6 +1069,28 @@ AC_SUBST(LCOV)
 AC_SUBST(GCOV)
 AC_SUBST(GENHTML)
 
+#######################################################
+# Enable replacing the build-time prefix in the loaders
+# cache with the installation prefix on this machine
+# for relocatable packages such as Windows and OS X
+# applicationsapplications and linux bundles
+#######################################################
+
+enable_relocations=no
+case $host in
+  *-*-mingw*)
+    enable_relocations=yes
+    ;;
+  *-*-darwin*)
+    enable_relocations=yes
+    ;;
+esac
+
+if test "x$enable_relocations" = "xyes"; then
+  AC_DEFINE(GDK_PIXBUF_RELOCATABLE, 1,
+                  [Define to 1 to replace the build-time prefix in modules])
+fi
+
 ##################################################
 # Output commands
 ##################################################
diff --git a/gdk-pixbuf/gdk-pixbuf-io.c b/gdk-pixbuf/gdk-pixbuf-io.c
index efff246..d1d6cf8 100644
--- a/gdk-pixbuf/gdk-pixbuf-io.c
+++ b/gdk-pixbuf/gdk-pixbuf-io.c
@@ -44,6 +44,9 @@
 #include <windows.h>
 #undef STRICT
 #endif
+#ifdef OS_DARWIN
+#include <mach-o/dyld.h>
+#endif
 
 /**
  * SECTION:file-loading
@@ -208,17 +211,6 @@ DllMain (HINSTANCE hinstDLL,
 
   return TRUE;
 }
-
-char *
-gdk_pixbuf_win32_get_toplevel (void)
-{
-  static char *toplevel = NULL;
-
-  if (toplevel == NULL)
-          toplevel = g_win32_get_package_installation_directory_of_module (gdk_pixbuf_dll);
-
-  return toplevel;
-}
 #endif
 
 
@@ -302,8 +294,40 @@ skip_space (const char **pos)
         
         return !(*p == '\0');
 }
-  
-#ifdef G_OS_WIN32
+
+#ifdef GDK_PIXBUF_RELOCATABLE
+
+gchar *
+gdk_pixbuf_get_toplevel (void)
+{
+  static gchar *toplevel = NULL;
+
+  if (toplevel == NULL) {
+#if defined(G_OS_WIN32)
+    toplevel = g_win32_get_package_installation_directory_of_module (gdk_pixbuf_dll);
+#elif defined(OS_DARWIN)
+    char pathbuf[PATH_MAX + 1];
+    uint32_t  bufsize = sizeof(pathbuf);
+    gchar *bin_dir;
+
+    _NSGetExecutablePath(pathbuf, &bufsize);
+    bin_dir = g_dirname(pathbuf);
+    toplevel = g_build_path (G_DIR_SEPARATOR_S, bin_dir, "..", NULL);
+    g_free (bin_dir);
+#elif defined (OS_LINUX)
+    gchar *exe_path, *bin_dir;
+
+    exe_path = g_file_read_link ("/proc/self/exe", NULL);
+    bin_dir = g_dirname(exe_path);
+    toplevel = g_build_path (G_DIR_SEPARATOR_S, bin_dir, "..", NULL);
+    g_free (exe_path);
+    g_free (bin_dir);
+#else
+#error "Relocations not supported for this platform"
+#endif
+  }
+  return toplevel;
+}
 
 static char *
 get_libdir (void)
@@ -311,7 +335,7 @@ get_libdir (void)
   static char *libdir = NULL;
 
   if (libdir == NULL)
-          libdir = g_build_filename (gdk_pixbuf_win32_get_toplevel (), "lib", NULL);
+          libdir = g_build_filename (gdk_pixbuf_get_toplevel (), "lib", NULL);
 
   return libdir;
 }
@@ -340,12 +364,12 @@ correct_prefix (gchar **path)
        * installation prefix on this machine.
        */
       tem = *path;
-      *path = g_strconcat (gdk_pixbuf_win32_get_toplevel (), tem + strlen (GDK_PIXBUF_PREFIX), NULL);
+      *path = g_strconcat (gdk_pixbuf_get_toplevel (), tem + strlen (GDK_PIXBUF_PREFIX), NULL);
       g_free (tem);
     }
 }
 
-#endif  /* G_OS_WIN32 */
+#endif  /* GDK_PIXBUF_RELOCATABLE */
 
 static gchar *
 gdk_pixbuf_get_module_file (void)
@@ -496,7 +520,7 @@ gdk_pixbuf_io_init (void)
                                 /* Blank line marking the end of a module
                                  */
                         if (module && *p != '#') {
-#ifdef G_OS_WIN32
+#ifdef GDK_PIXBUF_RELOCATABLE
                                 correct_prefix (&module->module_path);
 #endif
                                 file_formats = g_slist_prepend (file_formats, module);
diff --git a/gdk-pixbuf/gdk-pixbuf-private.h b/gdk-pixbuf/gdk-pixbuf-private.h
index edfa262..5628dda 100644
--- a/gdk-pixbuf/gdk-pixbuf-private.h
+++ b/gdk-pixbuf/gdk-pixbuf-private.h
@@ -115,8 +115,8 @@ GdkPixbufLoader *_gdk_pixbuf_loader_new_with_filename (const char *filename);
 
 #endif /* GDK_PIXBUF_PRIVATE_H */
 
-#ifdef G_OS_WIN32
+#ifdef GDK_PIXBUF_RELOCATABLE
 
-gchar * gdk_pixbuf_win32_get_toplevel (void);
+gchar * gdk_pixbuf_get_toplevel (void);
 
 #endif /* G_OS_WIN32 */
diff --git a/gdk-pixbuf/gdk-pixbuf-util.c b/gdk-pixbuf/gdk-pixbuf-util.c
index 6a7a8f3..49d44f6 100644
--- a/gdk-pixbuf/gdk-pixbuf-util.c
+++ b/gdk-pixbuf/gdk-pixbuf-util.c
@@ -349,22 +349,28 @@ gdk_pixbuf_apply_embedded_orientation (GdkPixbuf *src)
         return dest;
 }
 
-#ifdef G_OS_WIN32
+#ifdef GDK_PIXBUF_RELOCATABLE
 
 static const gchar *
 get_localedir (void)
 {
     gchar *temp;
-    gchar *retval;
     
-    temp = g_build_filename (gdk_pixbuf_win32_get_toplevel (), "share/locale", NULL);
-
-    /* The localedir is passed to bindtextdomain() which isn't
-     * UTF-8-aware.
-     */
-    retval = g_win32_locale_filename_from_utf8 (temp);
-    g_free (temp);
-    return retval;
+    temp = g_build_filename (gdk_pixbuf_get_toplevel (), "share/locale", NULL);
+
+#ifdef G_OS_WIN32
+    {
+      gchar *retval;
+      /* The localedir is passed to bindtextdomain() which isn't
+      * UTF-8-aware.
+      */
+      retval = g_win32_locale_filename_from_utf8 (temp);
+      g_free (temp);
+      return retval;
+    }
+#else
+    return temp;
+#endif
 }
 
 #undef GDK_PIXBUF_LOCALEDIR


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]