summaryrefslogtreecommitdiff
path: root/m4/lib-prefix.m4
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2019-11-17 23:56:55 +0100
committerBruno Haible <bruno@clisp.org>2019-11-17 23:56:55 +0100
commita053340dd3663f820b61ceb90583595984d89b9e (patch)
tree680c1fa23d8b4c48c967c669e721014b18790eea /m4/lib-prefix.m4
parentd3603f83124c4c51a366633d11f628723b1aa128 (diff)
downloadgnulib-a053340dd3663f820b61ceb90583595984d89b9e.tar.gz
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.
Diffstat (limited to 'm4/lib-prefix.m4')
-rw-r--r--m4/lib-prefix.m462
1 files changed, 61 insertions, 1 deletions
diff --git a/m4/lib-prefix.m4 b/m4/lib-prefix.m4
index dbe4e85f18..976c1a7099 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],