]> granicus.if.org Git - graphviz/commitdiff
apply patch ito support rlocatability on Macs from Thomas Keller <me@thomaskeller...
authorellson <devnull@localhost>
Sun, 22 May 2011 14:19:22 +0000 (14:19 +0000)
committerellson <devnull@localhost>
Sun, 22 May 2011 14:19:22 +0000 (14:19 +0000)
lib/gvc/gvconfig.c

index d4617ead0b5e81f4885a9e006c9987fc1ebfad6a..e1eb3b90c0e239422fc021b80ec54d0e71a9ba2b 100644 (file)
@@ -49,6 +49,10 @@ static int glob (GVC_t * gvc, char*, int, int (*errfunc)(const char *, int), glo
 #endif
 #endif
 
+#ifdef __APPLE__
+#include <mach-o/dyld.h>
+#endif
+
 #include        "memory.h"
 #include        "const.h"
 #include        "types.h"
@@ -293,8 +297,25 @@ char * gvconfig_libdir(GVC_t * gvc)
            *s = '\0';
            libdir = line;
 #else
-           /* this only works on linux, other systems will get GVLIBDIR only */
-           libdir = GVLIBDIR;
+        libdir = GVLIBDIR;         
+#ifdef __APPLE__
+        uint32_t i, c = _dyld_image_count();
+        for (i=0; i<c; ++i) {
+            tmp = _dyld_get_image_name(i);
+            strcpy(path, tmp);
+            tmp = strstr(path, "/libgvc.");
+            if (tmp) {
+            *tmp = '\0';
+            /* Check for real /lib dir. Don't accept pre-install /.libs */
+            if (strcmp(strrchr(path,'/'), "/.libs") == 0)
+                continue;
+            strcpy(line, path);  /* use line buffer for result */
+            strcat(line, "/graphviz");  /* plugins are in "graphviz" subdirectory */
+            libdir = line;
+            break;
+            }
+        }
+#else
            f = fopen ("/proc/self/maps", "r");
            if (f) {
                while (!feof (f)) {
@@ -319,6 +340,7 @@ char * gvconfig_libdir(GVC_t * gvc)
                }
                fclose (f);
            }
+#endif
 #endif
        }
     }