Hi,

In many installations, clang has strange/odd/buggy library search paths. In
particular, on the Ubuntu binaries from http://releases.llvm.org/download.html
search in /lib64/ although this directory contains no libraries (only the 
ld.so).
This confuses the AC_LIB_PREPARE_MULTILIB macro: it expects 64-bit libraries
in $PREFIX/lib64 (this hack was implemented for the sake of openSUSE systems).
But in Ubuntu, 64-bit binaries are in $PREFIX/lib.

I'm adding two patches:

1) The ability for the user to override the results of AC_LIB_PREPARE_MULTILIB.
   With this patch, I can run the configuration with
      acl_cv_libdirstems=lib,lib64 CC=clang ./configure 
--with-libsigsegv-prefix=...
   and it (i.e. gl_LIBSIGSEGV) will find the installed 64-bit binaries of
   libsigsegv, whereas before with just
      CC=clang ./configure --with-libsigsegv-prefix=...
   it did not find them.

2) Prefer to ask the system compiler (/usr/bin/gcc) about the characteristics of
   the system, rather than $CC.

>From be5c1e45939c46b33432fce4c919964617c7d5b5 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Sun, 19 Feb 2017 19:07:09 +0100
Subject: [PATCH 1/2] havelib: Support overriding the result of
 AC_LIB_PREPARE_MULTILIB.

* m4/lib-prefix.m4 (AC_LIB_PREPARE_MULTILIB): Use AC_CACHE_CHECK.
---
 ChangeLog        |  5 +++
 m4/lib-prefix.m4 | 98 ++++++++++++++++++++++++++++++--------------------------
 2 files changed, 58 insertions(+), 45 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 1adb3f4..2f2a8b7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2017-02-19  Bruno Haible  <br...@clisp.org>
 
+	havelib: Support overriding the result of AC_LIB_PREPARE_MULTILIB.
+	* m4/lib-prefix.m4 (AC_LIB_PREPARE_MULTILIB): Use AC_CACHE_CHECK.
+
+2017-02-19  Bruno Haible  <br...@clisp.org>
+
 	gnulib-tool: Avoid conflict of havelib-tests with --single-configure.
 	* gnulib_tool (func_create_testdir): Avoid havelib-tests when
 	--with-tests --single-configure is specified.
diff --git a/m4/lib-prefix.m4 b/m4/lib-prefix.m4
index 68a0835..afd5b93 100644
--- a/m4/lib-prefix.m4
+++ b/m4/lib-prefix.m4
@@ -1,4 +1,4 @@
-# lib-prefix.m4 serial 7 (gettext-0.18)
+# lib-prefix.m4 serial 8
 dnl Copyright (C) 2001-2005, 2008-2017 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -174,51 +174,59 @@ AC_DEFUN([AC_LIB_PREPARE_MULTILIB],
   dnl $prefix/lib/64 (which is a symlink to either $prefix/lib/sparcv9 or
   dnl $prefix/lib/amd64) and 32-bit libraries go under $prefix/lib.
   AC_REQUIRE([AC_CANONICAL_HOST])
-  acl_libdirstem=lib
-  acl_libdirstem2=
-  case "$host_os" in
-    solaris*)
-      dnl See Solaris 10 Software Developer Collection > Solaris 64-bit Developer's Guide > The Development Environment
-      dnl <http://docs.sun.com/app/docs/doc/816-5138/dev-env?l=en&a=view>.
-      dnl "Portable Makefiles should refer to any library directories using the 64 symbolic link."
-      dnl But we want to recognize the sparcv9 or amd64 subdirectory also if the
-      dnl symlink is missing, so we set acl_libdirstem2 too.
-      AC_CACHE_CHECK([for 64-bit host], [gl_cv_solaris_64bit],
-        [AC_EGREP_CPP([sixtyfour bits], [
+  dnl Allow the user to override the result by setting acl_cv_libdirstems.
+  AC_CACHE_CHECK([for the common suffixes of directories in the library search path],
+    [acl_cv_libdirstems],
+    [acl_libdirstem=lib
+     acl_libdirstem2=
+     case "$host_os" in
+       solaris*)
+         dnl See Solaris 10 Software Developer Collection > Solaris 64-bit Developer's Guide > The Development Environment
+         dnl <http://docs.sun.com/app/docs/doc/816-5138/dev-env?l=en&a=view>.
+         dnl "Portable Makefiles should refer to any library directories using the 64 symbolic link."
+         dnl But we want to recognize the sparcv9 or amd64 subdirectory also if the
+         dnl symlink is missing, so we set acl_libdirstem2 too.
+         AC_CACHE_CHECK([for 64-bit host], [gl_cv_solaris_64bit],
+           [AC_EGREP_CPP([sixtyfour bits], [
 #ifdef _LP64
 sixtyfour bits
 #endif
-           ], [gl_cv_solaris_64bit=yes], [gl_cv_solaris_64bit=no])
-        ])
-      if test $gl_cv_solaris_64bit = yes; then
-        acl_libdirstem=lib/64
-        case "$host_cpu" in
-          sparc*)        acl_libdirstem2=lib/sparcv9 ;;
-          i*86 | x86_64) acl_libdirstem2=lib/amd64 ;;
-        esac
-      fi
-      ;;
-    *)
-      searchpath=`(LC_ALL=C $CC -print-search-dirs) 2>/dev/null | sed -n -e 's,^libraries: ,,p' | sed -e 's,^=,,'`
-      if test -n "$searchpath"; then
-        acl_save_IFS="${IFS= 	}"; IFS=":"
-        for searchdir in $searchpath; do
-          if test -d "$searchdir"; then
-            case "$searchdir" in
-              */lib64/ | */lib64 ) acl_libdirstem=lib64 ;;
-              */../ | */.. )
-                # Better ignore directories of this form. They are misleading.
-                ;;
-              *) searchdir=`cd "$searchdir" && pwd`
-                 case "$searchdir" in
-                   */lib64 ) acl_libdirstem=lib64 ;;
-                 esac ;;
-            esac
-          fi
-        done
-        IFS="$acl_save_IFS"
-      fi
-      ;;
-  esac
-  test -n "$acl_libdirstem2" || acl_libdirstem2="$acl_libdirstem"
+              ], [gl_cv_solaris_64bit=yes], [gl_cv_solaris_64bit=no])
+           ])
+         if test $gl_cv_solaris_64bit = yes; then
+           acl_libdirstem=lib/64
+           case "$host_cpu" in
+             sparc*)        acl_libdirstem2=lib/sparcv9 ;;
+             i*86 | x86_64) acl_libdirstem2=lib/amd64 ;;
+           esac
+         fi
+         ;;
+       *)
+         searchpath=`(LC_ALL=C $CC -print-search-dirs) 2>/dev/null | sed -n -e 's,^libraries: ,,p' | sed -e 's,^=,,'`
+         if test -n "$searchpath"; then
+           acl_save_IFS="${IFS= 	}"; IFS=":"
+           for searchdir in $searchpath; do
+             if test -d "$searchdir"; then
+               case "$searchdir" in
+                 */lib64/ | */lib64 ) acl_libdirstem=lib64 ;;
+                 */../ | */.. )
+                   # Better ignore directories of this form. They are misleading.
+                   ;;
+                 *) searchdir=`cd "$searchdir" && pwd`
+                    case "$searchdir" in
+                      */lib64 ) acl_libdirstem=lib64 ;;
+                    esac ;;
+               esac
+             fi
+           done
+           IFS="$acl_save_IFS"
+         fi
+         ;;
+     esac
+     test -n "$acl_libdirstem2" || acl_libdirstem2="$acl_libdirstem"
+     acl_cv_libdirstems="$acl_libdirstem,$acl_libdirstem2"
+    ])
+  # Decompose acl_cv_libdirstems into acl_libdirstem and acl_libdirstem2.
+  acl_libdirstem=`echo "$acl_cv_libdirstems" | sed -e 's/,.*//'`
+  acl_libdirstem2=`echo "$acl_cv_libdirstems" | sed -e '/,/s/.*,//'`
 ])
-- 
2.7.4

>From a7fbc7bdbea8160ab03e29e20e704702b0441517 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Sun, 19 Feb 2017 19:46:14 +0100
Subject: [PATCH 2/2] havelib: Prefer the search path of /usr/bin/gcc over the
 one of $CC.

---
 ChangeLog        |  5 +++++
 m4/lib-prefix.m4 | 11 ++++++++++-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 2f2a8b7..2feb632 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2017-02-19  Bruno Haible  <br...@clisp.org>
 
+	havelib: Prefer the search path of /usr/bin/gcc over the one of $CC.
+	This helps when CC=clang.
+	* m4/lib-prefix.m4 (AC_LIB_PREPARE_MULTILIB): Prefer the search path
+	of /usr/bin/gcc.
+
 	havelib: Support overriding the result of AC_LIB_PREPARE_MULTILIB.
 	* m4/lib-prefix.m4 (AC_LIB_PREPARE_MULTILIB): Use AC_CACHE_CHECK.
 
diff --git a/m4/lib-prefix.m4 b/m4/lib-prefix.m4
index afd5b93..a5d56c8 100644
--- a/m4/lib-prefix.m4
+++ b/m4/lib-prefix.m4
@@ -202,7 +202,16 @@ sixtyfour bits
          fi
          ;;
        *)
-         searchpath=`(LC_ALL=C $CC -print-search-dirs) 2>/dev/null | sed -n -e 's,^libraries: ,,p' | sed -e 's,^=,,'`
+         dnl The result is a property of the system. However, non-system
+         dnl compilers sometimes have odd library search paths. Therefore
+         dnl prefer asking /usr/bin/gcc, if available, rather than $CC.
+         searchpath=`(if test -f /usr/bin/gcc \
+                         && LC_ALL=C /usr/bin/gcc -print-search-dirs >/dev/null 2>/dev/null; then \
+                        LC_ALL=C /usr/bin/gcc -print-search-dirs; \
+                      else \
+                        LC_ALL=C $CC -print-search-dirs; \
+                      fi) 2>/dev/null \
+                     | sed -n -e 's,^libraries: ,,p' | sed -e 's,^=,,'`
          if test -n "$searchpath"; then
            acl_save_IFS="${IFS= 	}"; IFS=":"
            for searchdir in $searchpath; do
-- 
2.7.4

Reply via email to