This series of patches improves the bi-arch support in the AC_LIB_LINKFLAGS macro.
Two situations are now supported that were not supported before: * A distro might store 64-bit libs in $PREFIX/lib and 32-bit libs in $PREFIX/lib32. This is how it is e.g. in Manjaro Linux. Until a couple of years ago, virtually all distros were using the opposite situation: 64-bit libs in $PREFIX/lib64 and 32-bit libs in $PREFIX/lib. * A library may be installed in $PREFIX/lib64 or $PREFIX/lib32 AND, in the opposite bitness, in $PREFIX/lib. The macro will now pick the library from the right directory, depending on whether $CC is compiling for 32-bit or for 64-bit. 2019-11-17 Bruno Haible <br...@clisp.org> havelib: Remove redundant code. * m4/lib-prefix.m4 (AC_LIB_PREPARE_MULTILIB): Remove Solaris specific test for 64-bit host. Use gl_HOST_CPU_C_ABI_32BIT result instead. host-cpu-c-abi: Add support for unknown CPUs. * m4/host-cpu-c-abi.m4 (gl_HOST_CPU_C_ABI_32BIT): Set gl_cv_host_cpu_c_abi_32bit to 'unknown' if we don't know whether it's 32-bit or 64-bit. havelib: Match the bitness when searching for libraries. * m4/lib-prefix.m4 (AC_LIB_PREPARE_MULTILIB): Define a function acl_is_expected_elfclass. * m4/lib-link.m4 (AC_LIB_LINKFLAGS_BODY): When testing whether a library file exists, in ELF, also test whether it has the ELF class that corresponds to the host's bitness. havelib: Make libdirstems processing more flexible. * m4/lib-prefix.m4 (AC_LIB_PREPARE_MULTILIB): Set 3 libdirstem variables: Consider 'lib' always, also on Solaris. Look for lib32 in addition to lib64. Don't invoke /usr/bin/gcc (reverting the second patch from 2017-02-19). * m4/lib-link.m4 (AC_LIB_LINKFLAGS_BODY): Consider up to 3 additional libdirs, even when the first one exists as a directory.
>From 4ba07b7db7567c8d3ebcbfdea547c6403e87ce6d Mon Sep 17 00:00:00 2001 From: Bruno Haible <br...@clisp.org> Date: Sun, 17 Nov 2019 23:56:47 +0100 Subject: [PATCH 1/4] havelib: Remove redundant code. * m4/lib-prefix.m4 (AC_LIB_PREPARE_MULTILIB): Remove Solaris specific test for 64-bit host. Use gl_HOST_CPU_C_ABI_32BIT result instead. --- ChangeLog | 6 ++++++ m4/lib-prefix.m4 | 20 ++------------------ 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index 053fce4..549152c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2019-11-17 Bruno Haible <br...@clisp.org> + havelib: Remove redundant code. + * m4/lib-prefix.m4 (AC_LIB_PREPARE_MULTILIB): Remove Solaris specific + test for 64-bit host. Use gl_HOST_CPU_C_ABI_32BIT result instead. + +2019-11-17 Bruno Haible <br...@clisp.org> + havelib: Fix a bug in dependency processing. * m4/lib-link.m4 (AC_LIB_LINKFLAGS_BODY): During dependency processing of .la files, don't overwrite the value of additional_libdir for the diff --git a/m4/lib-prefix.m4 b/m4/lib-prefix.m4 index 8adb17b..dbe4e85 100644 --- a/m4/lib-prefix.m4 +++ b/m4/lib-prefix.m4 @@ -1,4 +1,4 @@ -# lib-prefix.m4 serial 14 +# lib-prefix.m4 serial 15 dnl Copyright (C) 2001-2005, 2008-2019 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -169,22 +169,6 @@ AC_DEFUN([AC_LIB_PREPARE_MULTILIB], AC_REQUIRE([AC_CANONICAL_HOST]) AC_REQUIRE([gl_HOST_CPU_C_ABI_32BIT]) - case "$host_os" in - solaris*) - AC_CACHE_CHECK([for 64-bit host], [gl_cv_solaris_64bit], - [AC_COMPILE_IFELSE( - [AC_LANG_SOURCE( - [[#ifdef _LP64 - int ok; - #else - error fail - #endif - ]])], - [gl_cv_solaris_64bit=yes], - [gl_cv_solaris_64bit=no]) - ]);; - esac - 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], @@ -197,7 +181,7 @@ AC_DEFUN([AC_LIB_PREPARE_MULTILIB], 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. - if test $gl_cv_solaris_64bit = yes; then + if test $HOST_CPU_C_ABI_32BIT = no; then acl_libdirstem=lib/64 case "$host_cpu" in sparc*) acl_libdirstem2=lib/sparcv9 ;; -- 2.7.4
>From d3603f83124c4c51a366633d11f628723b1aa128 Mon Sep 17 00:00:00 2001 From: Bruno Haible <br...@clisp.org> Date: Sun, 17 Nov 2019 23:56:51 +0100 Subject: [PATCH 2/4] host-cpu-c-abi: Add support for unknown CPUs. * m4/host-cpu-c-abi.m4 (gl_HOST_CPU_C_ABI_32BIT): Set gl_cv_host_cpu_c_abi_32bit to 'unknown' if we don't know whether it's 32-bit or 64-bit. --- ChangeLog | 7 +++++++ m4/host-cpu-c-abi.m4 | 19 +++++++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 549152c..45eacfe 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2019-11-17 Bruno Haible <br...@clisp.org> + host-cpu-c-abi: Add support for unknown CPUs. + * m4/host-cpu-c-abi.m4 (gl_HOST_CPU_C_ABI_32BIT): Set + gl_cv_host_cpu_c_abi_32bit to 'unknown' if we don't know whether it's + 32-bit or 64-bit. + +2019-11-17 Bruno Haible <br...@clisp.org> + havelib: Remove redundant code. * m4/lib-prefix.m4 (AC_LIB_PREPARE_MULTILIB): Remove Solaris specific test for 64-bit host. Use gl_HOST_CPU_C_ABI_32BIT result instead. diff --git a/m4/host-cpu-c-abi.m4 b/m4/host-cpu-c-abi.m4 index af8c05c..6fc31bc 100644 --- a/m4/host-cpu-c-abi.m4 +++ b/m4/host-cpu-c-abi.m4 @@ -1,4 +1,4 @@ -# host-cpu-c-abi.m4 serial 12 +# host-cpu-c-abi.m4 serial 13 dnl Copyright (C) 2002-2019 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -457,7 +457,8 @@ EOF dnl Sets the HOST_CPU_C_ABI_32BIT variable to 'yes' if the C language ABI -dnl (application binary interface) is a 32-bit one, or to 'no' otherwise. +dnl (application binary interface) is a 32-bit one, to 'no' if it is a 64-bit +dnl one, or to 'unknown' if unknown. dnl This is a simplified variant of gl_HOST_CPU_C_ABI. AC_DEFUN([gl_HOST_CPU_C_ABI_32BIT], [ @@ -467,8 +468,10 @@ AC_DEFUN([gl_HOST_CPU_C_ABI_32BIT], case "$gl_cv_host_cpu_c_abi" in i386 | x86_64-x32 | arm | armhf | arm64-ilp32 | hppa | ia64-ilp32 | mips | mipsn32 | powerpc | riscv*-ilp32* | s390 | sparc) gl_cv_host_cpu_c_abi_32bit=yes ;; - *) + x86_64 | alpha | arm64 | hppa64 | ia64 | mips64 | powerpc64 | powerpc64-elfv2 | riscv*-lp64* | s390x | sparc64 ) gl_cv_host_cpu_c_abi_32bit=no ;; + *) + gl_cv_host_cpu_c_abi_32bit=unknown ;; esac else case "$host_cpu" in @@ -493,6 +496,14 @@ AC_DEFUN([gl_HOST_CPU_C_ABI_32BIT], gl_cv_host_cpu_c_abi_32bit=yes ;; + # CPUs that only support a 64-bit ABI. +changequote(,)dnl + alpha | alphaev[4-8] | alphaev56 | alphapca5[67] | alphaev6[78] \ + | mmix ) +changequote([,])dnl + gl_cv_host_cpu_c_abi_32bit=no + ;; + changequote(,)dnl i[34567]86 ) changequote([,])dnl @@ -654,7 +665,7 @@ changequote([,])dnl ;; *) - gl_cv_host_cpu_c_abi_32bit=no + gl_cv_host_cpu_c_abi_32bit=unknown ;; esac fi -- 2.7.4
>From a053340dd3663f820b61ceb90583595984d89b9e Mon Sep 17 00:00:00 2001 From: Bruno Haible <br...@clisp.org> Date: Sun, 17 Nov 2019 23:56:55 +0100 Subject: [PATCH 3/4] havelib: Match the bitness when searching for libraries. * m4/lib-prefix.m4 (AC_LIB_PREPARE_MULTILIB): Define a function acl_is_expected_elfclass. * m4/lib-link.m4 (AC_LIB_LINKFLAGS_BODY): When testing whether a library file exists, in ELF, also test whether it has the ELF class that corresponds to the host's bitness. --- ChangeLog | 9 ++++++++ m4/lib-link.m4 | 18 ++++++++-------- m4/lib-prefix.m4 | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 79 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 45eacfe..3b5fcb1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,14 @@ 2019-11-17 Bruno Haible <br...@clisp.org> + havelib: Match the bitness when searching for libraries. + * m4/lib-prefix.m4 (AC_LIB_PREPARE_MULTILIB): Define a function + acl_is_expected_elfclass. + * m4/lib-link.m4 (AC_LIB_LINKFLAGS_BODY): When testing whether a library + file exists, in ELF, also test whether it has the ELF class that + corresponds to the host's bitness. + +2019-11-17 Bruno Haible <br...@clisp.org> + host-cpu-c-abi: Add support for unknown CPUs. * m4/host-cpu-c-abi.m4 (gl_HOST_CPU_C_ABI_32BIT): Set gl_cv_host_cpu_c_abi_32bit to 'unknown' if we don't know whether it's diff --git a/m4/lib-link.m4 b/m4/lib-link.m4 index e9158f2..5efbbff 100644 --- a/m4/lib-link.m4 +++ b/m4/lib-link.m4 @@ -1,4 +1,4 @@ -# lib-link.m4 serial 29 +# lib-link.m4 serial 30 dnl Copyright (C) 2001-2019 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -274,7 +274,7 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY], dnl The same code as in the loop below: dnl First look for a shared library. if test -n "$acl_shlibext"; then - if test -f "$dir/$libname$shrext"; then + if test -f "$dir/$libname$shrext" && acl_is_expected_elfclass < "$dir/$libname$shrext"; then found_dir="$dir" found_so="$dir/$libname$shrext" else @@ -284,14 +284,14 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY], | sed -e "s,^$libname$shrext\\\\.,," \ | sort -t '.' -n -r -k1,1 -k2,2 -k3,3 -k4,4 -k5,5 \ | sed 1q ) 2>/dev/null` - if test -n "$ver" && test -f "$dir/$libname$shrext.$ver"; then + if test -n "$ver" && test -f "$dir/$libname$shrext.$ver" && acl_is_expected_elfclass < "$dir/$libname$shrext.$ver"; then found_dir="$dir" found_so="$dir/$libname$shrext.$ver" fi else eval library_names=\"$acl_library_names_spec\" for f in $library_names; do - if test -f "$dir/$f"; then + if test -f "$dir/$f" && acl_is_expected_elfclass < "$dir/$f"; then found_dir="$dir" found_so="$dir/$f" break @@ -302,7 +302,7 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY], fi dnl Then look for a static library. if test "X$found_dir" = "X"; then - if test -f "$dir/$libname.$acl_libext"; then + if test -f "$dir/$libname.$acl_libext" && ${AR-ar} -p "$dir/$libname.$acl_libext" | acl_is_expected_elfclass; then found_dir="$dir" found_a="$dir/$libname.$acl_libext" fi @@ -321,7 +321,7 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY], dir=`echo "X$x" | sed -e 's/^X-L//'` dnl First look for a shared library. if test -n "$acl_shlibext"; then - if test -f "$dir/$libname$shrext"; then + if test -f "$dir/$libname$shrext" && acl_is_expected_elfclass < "$dir/$libname$shrext"; then found_dir="$dir" found_so="$dir/$libname$shrext" else @@ -331,14 +331,14 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY], | sed -e "s,^$libname$shrext\\\\.,," \ | sort -t '.' -n -r -k1,1 -k2,2 -k3,3 -k4,4 -k5,5 \ | sed 1q ) 2>/dev/null` - if test -n "$ver" && test -f "$dir/$libname$shrext.$ver"; then + if test -n "$ver" && test -f "$dir/$libname$shrext.$ver" && acl_is_expected_elfclass < "$dir/$libname$shrext.$ver"; then found_dir="$dir" found_so="$dir/$libname$shrext.$ver" fi else eval library_names=\"$acl_library_names_spec\" for f in $library_names; do - if test -f "$dir/$f"; then + if test -f "$dir/$f" && acl_is_expected_elfclass < "$dir/$f"; then found_dir="$dir" found_so="$dir/$f" break @@ -349,7 +349,7 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY], fi dnl Then look for a static library. if test "X$found_dir" = "X"; then - if test -f "$dir/$libname.$acl_libext"; then + if test -f "$dir/$libname.$acl_libext" && ${AR-ar} -p "$dir/$libname.$acl_libext" | acl_is_expected_elfclass; then found_dir="$dir" found_a="$dir/$libname.$acl_libext" fi diff --git a/m4/lib-prefix.m4 b/m4/lib-prefix.m4 index dbe4e85..976c1a7 100644 --- a/m4/lib-prefix.m4 +++ b/m4/lib-prefix.m4 @@ -1,4 +1,4 @@ -# lib-prefix.m4 serial 15 +# lib-prefix.m4 serial 16 dnl Copyright (C) 2001-2005, 2008-2019 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -147,6 +147,8 @@ AC_DEFUN([AC_LIB_WITH_FINAL_PREFIX], ]) dnl AC_LIB_PREPARE_MULTILIB creates +dnl - a function acl_is_expected_elfclass, that tests whether standard input +dn; has a 32-bit or 64-bit ELF header, depending on the host CPU ABI, dnl - a variable acl_libdirstem, containing the basename of the libdir, either dnl "lib" or "lib64" or "lib/64", dnl - a variable acl_libdirstem2, as a secondary possible value for @@ -169,6 +171,64 @@ AC_DEFUN([AC_LIB_PREPARE_MULTILIB], AC_REQUIRE([AC_CANONICAL_HOST]) AC_REQUIRE([gl_HOST_CPU_C_ABI_32BIT]) + AC_CACHE_CHECK([for ELF binary format], [gl_cv_elf], + [AC_EGREP_CPP([Extensible Linking Format], + [#ifdef __ELF__ + Extensible Linking Format + #endif + ], + [gl_cv_elf=yes], + [gl_cv_elf=no]) + ]) + if test $gl_cv_elf; then + # Extract the ELF class of a file (5th byte) in decimal. + # Cf. https://en.wikipedia.org/wiki/Executable_and_Linkable_Format#File_header + if od -A x < /dev/null >/dev/null 2>/dev/null; then + # Use POSIX od. + func_elfclass () + { + od -A n -t d1 -j 4 -N 1 + } + else + # Use BSD hexdump. + func_elfclass () + { + dd bs=1 count=1 skip=4 2>/dev/null | hexdump -e '1/1 "%3d "' + echo + } + fi +changequote(,)dnl + case $HOST_CPU_C_ABI_32BIT in + yes) + # 32-bit ABI. + acl_is_expected_elfclass () + { + test "`func_elfclass | sed -e 's/[ ]//g'`" = 1 + } + ;; + no) + # 64-bit ABI. + acl_is_expected_elfclass () + { + test "`func_elfclass | sed -e 's/[ ]//g'`" = 2 + } + ;; + *) + # Unknown. + acl_is_expected_elfclass () + { + : + } + ;; + esac +changequote([,])dnl + else + acl_is_expected_elfclass () + { + : + } + fi + 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], -- 2.7.4
>From f79253a9753cf35616474ffb6d6b73c5525d2a7a Mon Sep 17 00:00:00 2001 From: Bruno Haible <br...@clisp.org> Date: Sun, 17 Nov 2019 23:57:00 +0100 Subject: [PATCH 4/4] havelib: Make libdirstems processing more flexible. * m4/lib-prefix.m4 (AC_LIB_PREPARE_MULTILIB): Set 3 libdirstem variables: Consider 'lib' always, also on Solaris. Look for lib32 in addition to lib64. Don't invoke /usr/bin/gcc (reverting the second patch from 2017-02-19). * m4/lib-link.m4 (AC_LIB_LINKFLAGS_BODY): Consider up to 3 additional libdirs, even when the first one exists as a directory. --- ChangeLog | 10 +++++ m4/lib-link.m4 | 120 +++++++++++++++++++++++++++++++--------------------- m4/lib-prefix.m4 | 125 +++++++++++++++++++++++++++++++++---------------------- 3 files changed, 159 insertions(+), 96 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3b5fcb1..2c5b818 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,15 @@ 2019-11-17 Bruno Haible <br...@clisp.org> + havelib: Make libdirstems processing more flexible. + * m4/lib-prefix.m4 (AC_LIB_PREPARE_MULTILIB): Set 3 libdirstem + variables: Consider 'lib' always, also on Solaris. Look for lib32 in + addition to lib64. Don't invoke /usr/bin/gcc (reverting the second + patch from 2017-02-19). + * m4/lib-link.m4 (AC_LIB_LINKFLAGS_BODY): Consider up to 3 additional + libdirs, even when the first one exists as a directory. + +2019-11-17 Bruno Haible <br...@clisp.org> + havelib: Match the bitness when searching for libraries. * m4/lib-prefix.m4 (AC_LIB_PREPARE_MULTILIB): Define a function acl_is_expected_elfclass. diff --git a/m4/lib-link.m4 b/m4/lib-link.m4 index 5efbbff..b9fa364 100644 --- a/m4/lib-link.m4 +++ b/m4/lib-link.m4 @@ -1,4 +1,4 @@ -# lib-link.m4 serial 30 +# lib-link.m4 serial 31 dnl Copyright (C) 2001-2019 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -192,6 +192,8 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY], AC_LIB_WITH_FINAL_PREFIX([ eval additional_includedir=\"$includedir\" eval additional_libdir=\"$libdir\" + eval additional_libdir2=\"$exec_prefix/$acl_libdirstem2\" + eval additional_libdir3=\"$exec_prefix/$acl_libdirstem3\" ]) AC_ARG_WITH(PACK[-prefix], [[ --with-]]PACK[[-prefix[=DIR] search for ]PACKLIBS[ in DIR/include and DIR/lib @@ -204,17 +206,23 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY], AC_LIB_WITH_FINAL_PREFIX([ eval additional_includedir=\"$includedir\" eval additional_libdir=\"$libdir\" + eval additional_libdir2=\"$exec_prefix/$acl_libdirstem2\" + eval additional_libdir3=\"$exec_prefix/$acl_libdirstem3\" ]) else additional_includedir="$withval/include" additional_libdir="$withval/$acl_libdirstem" - if test "$acl_libdirstem2" != "$acl_libdirstem" \ - && test ! -d "$withval/$acl_libdirstem"; then - additional_libdir="$withval/$acl_libdirstem2" - fi + additional_libdir2="$withval/$acl_libdirstem2" + additional_libdir3="$withval/$acl_libdirstem3" fi fi ]) + if test "X$additional_libdir2" = "X$additional_libdir"; then + additional_libdir2= + fi + if test "X$additional_libdir3" = "X$additional_libdir"; then + additional_libdir3= + fi dnl Search the library and its dependencies in $additional_libdir and dnl $LDFLAGS. Using breadth-first-seach. LIB[]NAME= @@ -270,48 +278,54 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY], shrext= fi if test $use_additional = yes; then - dir="$additional_libdir" - dnl The same code as in the loop below: - dnl First look for a shared library. - if test -n "$acl_shlibext"; then - if test -f "$dir/$libname$shrext" && acl_is_expected_elfclass < "$dir/$libname$shrext"; then - found_dir="$dir" - found_so="$dir/$libname$shrext" - else - if test "$acl_library_names_spec" = '$libname$shrext$versuffix'; then - ver=`(cd "$dir" && \ - for f in "$libname$shrext".*; do echo "$f"; done \ - | sed -e "s,^$libname$shrext\\\\.,," \ - | sort -t '.' -n -r -k1,1 -k2,2 -k3,3 -k4,4 -k5,5 \ - | sed 1q ) 2>/dev/null` - if test -n "$ver" && test -f "$dir/$libname$shrext.$ver" && acl_is_expected_elfclass < "$dir/$libname$shrext.$ver"; then - found_dir="$dir" - found_so="$dir/$libname$shrext.$ver" + for additional_libdir_variable in additional_libdir additional_libdir2 additional_libdir3; do + if test "X$found_dir" = "X"; then + eval dir=\$$additional_libdir_variable + if test -n "$dir"; then + dnl The same code as in the loop below: + dnl First look for a shared library. + if test -n "$acl_shlibext"; then + if test -f "$dir/$libname$shrext" && acl_is_expected_elfclass < "$dir/$libname$shrext"; then + found_dir="$dir" + found_so="$dir/$libname$shrext" + else + if test "$acl_library_names_spec" = '$libname$shrext$versuffix'; then + ver=`(cd "$dir" && \ + for f in "$libname$shrext".*; do echo "$f"; done \ + | sed -e "s,^$libname$shrext\\\\.,," \ + | sort -t '.' -n -r -k1,1 -k2,2 -k3,3 -k4,4 -k5,5 \ + | sed 1q ) 2>/dev/null` + if test -n "$ver" && test -f "$dir/$libname$shrext.$ver" && acl_is_expected_elfclass < "$dir/$libname$shrext.$ver"; then + found_dir="$dir" + found_so="$dir/$libname$shrext.$ver" + fi + else + eval library_names=\"$acl_library_names_spec\" + for f in $library_names; do + if test -f "$dir/$f" && acl_is_expected_elfclass < "$dir/$f"; then + found_dir="$dir" + found_so="$dir/$f" + break + fi + done + fi + fi fi - else - eval library_names=\"$acl_library_names_spec\" - for f in $library_names; do - if test -f "$dir/$f" && acl_is_expected_elfclass < "$dir/$f"; then + dnl Then look for a static library. + if test "X$found_dir" = "X"; then + if test -f "$dir/$libname.$acl_libext" && ${AR-ar} -p "$dir/$libname.$acl_libext" | acl_is_expected_elfclass; then found_dir="$dir" - found_so="$dir/$f" - break + found_a="$dir/$libname.$acl_libext" fi - done + fi + if test "X$found_dir" != "X"; then + if test -f "$dir/$libname.la"; then + found_la="$dir/$libname.la" + fi + fi fi fi - fi - dnl Then look for a static library. - if test "X$found_dir" = "X"; then - if test -f "$dir/$libname.$acl_libext" && ${AR-ar} -p "$dir/$libname.$acl_libext" | acl_is_expected_elfclass; then - found_dir="$dir" - found_a="$dir/$libname.$acl_libext" - fi - fi - if test "X$found_dir" != "X"; then - if test -f "$dir/$libname.la"; then - found_la="$dir/$libname.la" - fi - fi + done fi if test "X$found_dir" = "X"; then for x in $LDFLAGS $LTLIB[]NAME; do @@ -375,7 +389,8 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY], dnl standard /usr/lib. if test "$enable_rpath" = no \ || test "X$found_dir" = "X/usr/$acl_libdirstem" \ - || test "X$found_dir" = "X/usr/$acl_libdirstem2"; then + || test "X$found_dir" = "X/usr/$acl_libdirstem2" \ + || test "X$found_dir" = "X/usr/$acl_libdirstem3"; then dnl No hardcoding is needed. LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so" else @@ -475,6 +490,13 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY], fi additional_includedir="$basedir/include" ;; + */$acl_libdirstem3 | */$acl_libdirstem3/) + basedir=`echo "X$found_dir" | sed -e 's,^X,,' -e "s,/$acl_libdirstem3/"'*$,,'` + if test "$name" = '$1'; then + LIB[]NAME[]_PREFIX="$basedir" + fi + additional_includedir="$basedir/include" + ;; esac if test "X$additional_includedir" != "X"; then dnl Potentially add $additional_includedir to $INCNAME. @@ -534,10 +556,12 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY], dnl constructed $LIBNAME, dnl 4. if it doesn't exist as a directory. if test "X$dependency_libdir" != "X/usr/$acl_libdirstem" \ - && test "X$dependency_libdir" != "X/usr/$acl_libdirstem2"; then + && test "X$dependency_libdir" != "X/usr/$acl_libdirstem2" \ + && test "X$dependency_libdir" != "X/usr/$acl_libdirstem3"; then haveit= if test "X$dependency_libdir" = "X/usr/local/$acl_libdirstem" \ - || test "X$dependency_libdir" = "X/usr/local/$acl_libdirstem2"; then + || test "X$dependency_libdir" = "X/usr/local/$acl_libdirstem2" \ + || test "X$dependency_libdir" = "X/usr/local/$acl_libdirstem3"; then if test -n "$GCC"; then case $host_os in linux* | gnu* | k*bsd*-gnu) haveit=yes;; @@ -718,7 +742,8 @@ AC_DEFUN([AC_LIB_LINKFLAGS_FROM_LIBS], dir="$next" dnl No need to hardcode the standard /usr/lib. if test "X$dir" != "X/usr/$acl_libdirstem" \ - && test "X$dir" != "X/usr/$acl_libdirstem2"; then + && test "X$dir" != "X/usr/$acl_libdirstem2" \ + && test "X$dir" != "X/usr/$acl_libdirstem3"; then rpathdirs="$rpathdirs $dir" fi next= @@ -728,7 +753,8 @@ AC_DEFUN([AC_LIB_LINKFLAGS_FROM_LIBS], -L*) dir=`echo "X$opt" | sed -e 's,^X-L,,'` dnl No need to hardcode the standard /usr/lib. if test "X$dir" != "X/usr/$acl_libdirstem" \ - && test "X$dir" != "X/usr/$acl_libdirstem2"; then + && test "X$dir" != "X/usr/$acl_libdirstem2" \ + && test "X$dir" != "X/usr/$acl_libdirstem3"; then rpathdirs="$rpathdirs $dir" fi next= ;; diff --git a/m4/lib-prefix.m4 b/m4/lib-prefix.m4 index 976c1a7..52ea5ae 100644 --- a/m4/lib-prefix.m4 +++ b/m4/lib-prefix.m4 @@ -1,4 +1,4 @@ -# lib-prefix.m4 serial 16 +# lib-prefix.m4 serial 17 dnl Copyright (C) 2001-2005, 2008-2019 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -149,21 +149,22 @@ AC_DEFUN([AC_LIB_WITH_FINAL_PREFIX], dnl AC_LIB_PREPARE_MULTILIB creates dnl - a function acl_is_expected_elfclass, that tests whether standard input dn; has a 32-bit or 64-bit ELF header, depending on the host CPU ABI, -dnl - a variable acl_libdirstem, containing the basename of the libdir, either -dnl "lib" or "lib64" or "lib/64", -dnl - a variable acl_libdirstem2, as a secondary possible value for -dnl acl_libdirstem, either the same as acl_libdirstem or "lib/sparcv9" or -dnl "lib/amd64". +dnl - 3 variables acl_libdirstem, acl_libdirstem2, acl_libdirstem3, containing +dnl the basename of the libdir to try in turn, either "lib" or "lib64" or +dnl "lib/64" or "lib32" or "lib/sparcv9" or "lib/amd64" or similar. AC_DEFUN([AC_LIB_PREPARE_MULTILIB], [ - dnl There is no formal standard regarding lib and lib64. - dnl On glibc systems, the current practice is that on a system supporting + dnl There is no formal standard regarding lib, lib32, and lib64. + dnl On most glibc systems, the current practice is that on a system supporting dnl 32-bit and 64-bit instruction sets or ABIs, 64-bit libraries go under - dnl $prefix/lib64 and 32-bit libraries go under $prefix/lib. We determine - dnl the compiler's default mode by looking at the compiler's library search - dnl path. If at least one of its elements ends in /lib64 or points to a - dnl directory whose absolute pathname ends in /lib64, we assume a 64-bit ABI. - dnl Otherwise we use the default, namely "lib". + dnl $prefix/lib64 and 32-bit libraries go under $prefix/lib. However, on + dnl Arch Linux based distributions, it's the opposite: 32-bit libraries go + dnl under $prefix/lib32 and 64-bit libraries go under $prefix/lib. + dnl We determine the compiler's default mode by looking at the compiler's + dnl library search path. If at least one of its elements ends in /lib64 or + dnl points to a directory whose absolute pathname ends in /lib64, we use that + dnl for 64-bit ABIs. Similarly for 32-bit ABIs. Otherwise we use the default, + dnl namely "lib". dnl On Solaris systems, the current practice is that on a system supporting dnl 32-bit and 64-bit instruction sets or ABIs, 64-bit libraries go under dnl $prefix/lib/64 (which is a symlink to either $prefix/lib/sparcv9 or @@ -232,8 +233,11 @@ changequote([,])dnl 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 + [dnl Try 'lib' first, because that's the default for libdir in GNU, see + dnl <https://www.gnu.org/prep/standards/html_node/Directory-Variables.html>. + acl_libdirstem=lib acl_libdirstem2= + acl_libdirstem3= case "$host_os" in solaris*) dnl See Solaris 10 Software Developer Collection > Solaris 64-bit Developer's Guide > The Development Environment @@ -242,52 +246,75 @@ changequote([,])dnl dnl But we want to recognize the sparcv9 or amd64 subdirectory also if the dnl symlink is missing, so we set acl_libdirstem2 too. if test $HOST_CPU_C_ABI_32BIT = no; then - acl_libdirstem=lib/64 + acl_libdirstem2=lib/64 case "$host_cpu" in - sparc*) acl_libdirstem2=lib/sparcv9 ;; - i*86 | x86_64) acl_libdirstem2=lib/amd64 ;; + sparc*) acl_libdirstem3=lib/sparcv9 ;; + i*86 | x86_64) acl_libdirstem3=lib/amd64 ;; esac fi ;; *) dnl If $CC generates code for a 32-bit ABI, the libraries are - dnl surely under $prefix/lib, not $prefix/lib64. - if test "$HOST_CPU_C_ABI_32BIT" != yes; then - 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 - 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" + dnl surely under $prefix/lib or $prefix/lib32, not $prefix/lib64. + dnl Similarly, if $CC generates code for a 64-bit ABI, the libraries + dnl are surely under $prefix/lib or $prefix/lib64, not $prefix/lib32. + dnl Find the compiler's search path. However, non-system compilers + dnl sometimes have odd library search paths. But we can't simply invoke + dnl '/usr/bin/gcc -print-search-dirs' because that would not take into + dnl account the -m32/-m31 or -m64 options from the $CC or $CFLAGS. + searchpath=`(LC_ALL=C $CC $CPPFLAGS $CFLAGS -print-search-dirs) 2>/dev/null \ + | sed -n -e 's,^libraries: ,,p' | sed -e 's,^=,,'` + if test $HOST_CPU_C_ABI_32BIT != no; then + # 32-bit or unknown ABI. + if test -d /usr/lib32; then + acl_libdirstem2=lib32 + fi + fi + if test $HOST_CPU_C_ABI_32BIT != yes; then + # 64-bit or unknown ABI. + if test -d /usr/lib64; then + acl_libdirstem3=lib64 + fi + fi + if test -n "$searchpath"; then + acl_save_IFS="${IFS= }"; IFS=":" + for searchdir in $searchpath; do + if test -d "$searchdir"; then + case "$searchdir" in + */lib32/ | */lib32 ) acl_libdirstem2=lib32 ;; + */lib64/ | */lib64 ) acl_libdirstem3=lib64 ;; + */../ | */.. ) + # Better ignore directories of this form. They are misleading. + ;; + *) searchdir=`cd "$searchdir" && pwd` + case "$searchdir" in + */lib32 ) acl_libdirstem2=lib32 ;; + */lib64 ) acl_libdirstem3=lib64 ;; + esac ;; + esac + fi + done + IFS="$acl_save_IFS" + if test $HOST_CPU_C_ABI_32BIT = yes; then + # 32-bit ABI. + acl_libdirstem3= + fi + if test $HOST_CPU_C_ABI_32BIT = no; then + # 64-bit ABI. + acl_libdirstem2= fi fi ;; esac test -n "$acl_libdirstem2" || acl_libdirstem2="$acl_libdirstem" - acl_cv_libdirstems="$acl_libdirstem,$acl_libdirstem2" + test -n "$acl_libdirstem3" || acl_libdirstem3="$acl_libdirstem" + acl_cv_libdirstems="$acl_libdirstem,$acl_libdirstem2,$acl_libdirstem3" ]) - # Decompose acl_cv_libdirstems into acl_libdirstem and acl_libdirstem2. + dnl Decompose acl_cv_libdirstems into acl_libdirstem, acl_libdirstem2, and + dnl acl_libdirstem3. +changequote(,)dnl acl_libdirstem=`echo "$acl_cv_libdirstems" | sed -e 's/,.*//'` - acl_libdirstem2=`echo "$acl_cv_libdirstems" | sed -e '/,/s/.*,//'` + acl_libdirstem2=`echo "$acl_cv_libdirstems" | sed -e 's/^[^,]*,//' -e 's/,.*//'` + acl_libdirstem3=`echo "$acl_cv_libdirstems" | sed -e 's/^[^,]*,[^,]*,//' -e 's/,.*//'` +changequote([,])dnl ]) -- 2.7.4