[glade/wip/tingping/dylibs-osx: 3/5] Fix loading dylibs on OSX



commit 27c2286bd9062d2c77cfc1b0eb26fb02523a50b6
Author: TingPing <tingping tingping se>
Date:   Fri Jul 4 20:53:42 2014 -0400

    Fix loading dylibs on OSX

 configure.ac          | 16 ++++++++++++++++
 gladeui/glade-utils.c | 25 +++++++++++++++++++++++++
 2 files changed, 41 insertions(+)
---
diff --git a/configure.ac b/configure.ac
index fffccfba..79e4d58d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -276,6 +276,22 @@ case $host_os in
 esac
 AM_CONDITIONAL(NATIVE_WIN32, test x"$native_win32" = "xyes")
 
+dnl ================================================================
+dnl Check for osx
+dnl ================================================================
+AC_MSG_CHECKING([for Mac OS X platform])
+case "$host" in
+  *-*-darwin*)
+    platform_osx=yes
+    ;;
+  *)
+    platform_osx=no
+    ;;
+esac
+AC_MSG_RESULT([$platform_osx])
+AM_CONDITIONAL(PLATFORM_OSX, test x"$platform_osx" = "xyes")
+AC_DEFINE(PLATFORM_OSX, test x"$platform_osx" = "xyes", [On OSX Platform])
+
 if test "$native_win32" = "yes"; then
   AC_CHECK_TOOL(WINDRES, windres, no)
   if test "$WINDRES" = no; then
diff --git a/gladeui/glade-utils.c b/gladeui/glade-utils.c
index 6148561a..82bd34c2 100644
--- a/gladeui/glade-utils.c
+++ b/gladeui/glade-utils.c
@@ -876,6 +876,31 @@ try_load_library (const gchar *library_path, const gchar *library_name)
         g_warning ("Failed to load %s: %s", path, g_module_error ());
     }
 
+#ifdef PLATFORM_OSX
+  /* Handle .dylib's on OSX */
+  if (!module)
+    {
+      gchar *osx_path;
+
+      /* Remove possible trailing .so */
+      if (g_str_has_suffix (path, ".so"))
+        {
+          gchar *tmp = g_strndup (path, strlen(path) - 3);
+          g_free (path);
+          path = tmp;
+        }
+
+      osx_path = g_strconcat (path, ".dylib", NULL);
+      if (!library_path || g_file_test (osx_path, G_FILE_TEST_EXISTS))
+        {
+          if (!(module = g_module_open (osx_path, G_MODULE_BIND_LAZY)))
+            g_warning ("Failed to load %s: %s", osx_path, g_module_error ());
+        }
+
+      g_free (osx_path);
+    }
+#endif
+
   g_free (path);
 
   return module;


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