543165
2011-04-04  Jakub Jelinek  <jakub@redhat.com>
543165
543165
	* toplev.c (toplev_main_argv): New variable.
543165
	(toplev_main): Initialize it.
543165
	* graphite.c (init_cloog_pointers): Load libcloog-isl.so.4 from gcc's private
543165
	directory.
543165
543165
--- gcc/toplev.c.jj	2008-12-09 23:59:10.000000000 +0100
543165
+++ gcc/toplev.c	2009-01-27 14:33:52.000000000 +0100
543165
@@ -107,6 +107,8 @@ static bool no_backend;
543165
 /* Length of line when printing switch values.  */
543165
 #define MAX_LINE 75
543165
 
543165
+const char **toplev_main_argv;
543165
+
543165
 /* Decoded options, and number of such options.  */
543165
 struct cl_decoded_option *save_decoded_options;
543165
 unsigned int save_decoded_options_count;
543165
@@ -1909,6 +1911,8 @@ toplev_main (int argc, char **argv)
543165
 
543165
   expandargv (&argc, &argv);
543165
 
543165
+  toplev_main_argv = CONST_CAST2 (const char **, char **, argv);
543165
+
543165
   /* Initialization of GCC's environment, and diagnostics.  */
543165
   general_init (argv[0]);
543165
 
543165
--- gcc/graphite.c.jj	2010-12-01 10:24:32.000000000 -0500
543165
+++ gcc/graphite.c	2010-12-01 11:46:07.832118193 -0500
543165
@@ -72,11 +72,39 @@ __typeof (cloog_pointers__) cloog_pointe
543165
 static bool
543165
 init_cloog_pointers (void)
543165
 {
543165
-  void *h;
543165
-
543165
-  if (cloog_pointers__.inited)
543165
-    return cloog_pointers__.h != NULL;
543165
-  h = dlopen ("libcloog-isl.so.4", RTLD_LAZY);
543165
+  void *h = NULL;
543165
+  extern const char **toplev_main_argv;
543165
+  char *buf, *p;
543165
+  size_t len;
543165
+
543165
+  if (cloog_pointers__.inited)
543165
+    return cloog_pointers__.h != NULL;
543165
+  len = progname - toplev_main_argv[0];
543165
+  buf = XALLOCAVAR (char, len + sizeof "libcloog-isl.so.4");
543165
+  memcpy (buf, toplev_main_argv[0], len);
543165
+  strcpy (buf + len, "libcloog-isl.so.4");
543165
+  len += sizeof "libcloog-isl.so.4";
543165
+  p = strstr (buf, "/libexec/");
543165
+  if (p != NULL)
543165
+    {
543165
+      while (1)
543165
+	{
543165
+	  char *q = strstr (p + 8, "/libexec/");
543165
+	  if (q == NULL)
543165
+	    break;
543165
+	  p = q;
543165
+	}
543165
+      memmove (p + 4, p + 8, len - (p + 8 - buf));
543165
+      h = dlopen (buf, RTLD_LAZY);
543165
+      if (h == NULL)
543165
+	{
543165
+	  len = progname - toplev_main_argv[0];
543165
+	  memcpy (buf, toplev_main_argv[0], len);
543165
+	  strcpy (buf + len, "libcloog-isl.so.4");
543165
+	}
543165
+    }
543165
+  if (h == NULL)
543165
+    h = dlopen (buf, RTLD_LAZY);
543165
   cloog_pointers__.h = h;
543165
   if (h == NULL)
543165
     return false;