Account for multilib Linux installations in imake.
authorDavid Cantrell <david.l.cantrell@gmail.com>
Tue, 21 Aug 2012 13:34:23 +0000 (09:34 -0400)
committerDavid Cantrell <david.l.cantrell@gmail.com>
Tue, 21 Aug 2012 14:08:16 +0000 (10:08 -0400)
The libc.so file is not always in /usr/lib.  On multilib systems, the
file we care about could be in /usr/lib64.  Likewise, common Linux
conventions call for 64-bit libraries to go in lib64 directories, so
check there first when on a Linux 64-bit system.

cde/config/imake/imake.c

index 77df8007cbd76ad1429e5485cb2d28a1340e64a2..5e26133a42088605b457428327b0735e569043e2 100644 (file)
@@ -885,7 +885,7 @@ get_distrib(FILE *inFile)
   /* would like to know what version of the distribution it is */
 }
 
-static const char *libc_c=
+static const char libc_c[]=
 "#include <stdio.h>\n"
 "#include <ctype.h>\n"
 "\n"
@@ -953,11 +953,34 @@ static const char *libc_c=
 static void
 get_libc_version(FILE *inFile)
 {
-  static char* libcso = "/usr/lib/libc.so";
+  char* libcso = NULL;
   struct stat sb;
   char buf[PATH_MAX];
   char* ptr;
   int libcmajor, libcminor, libcteeny;
+  struct utsname u;
+
+  /*
+   * If we are on a 64-bit Linux system and we see /usr/lib64/libc.so,
+   * we should use it.  Otherwise go with /usr/lib/libc.so.  It is entirely
+   * possible that someone will be running a 32-bit userland on a 64-bit
+   * system.
+   */
+  if (uname(&u) == -1) {
+    fprintf(stderr, "%s (%d): %s\n", __func__, __LINE__, strerror(errno));
+    abort();
+  }
+
+  if (!strcmp(u.sysname, "Linux") &&
+      (!strcmp(u.machine, "x86_64"))) {
+    if (!lstat ("/usr/lib64/libc.so", &sb) && S_ISREG(sb.st_mode)) {
+      libcso = strdup("/usr/lib64/libc.so");
+    }
+  }
+
+  if (libcso == NULL) {
+    libcso = strdup("/usr/lib/libc.so");
+  }
 
   if (lstat (libcso, &sb) == 0) {
     if (S_ISLNK (sb.st_mode)) {
@@ -1011,6 +1034,8 @@ get_libc_version(FILE *inFile)
        abort ();
     }
   }
+
+  free(libcso);
 }
 
 static void