Skip to content

Commit

Permalink
m4/ax_realpath_lib.m4: recognize "GNU ld script" files which redirect…
Browse files Browse the repository at this point in the history
… to a real library

Signed-off-by: Jim Klimov <[email protected]>
  • Loading branch information
jimklimov committed Sep 11, 2024
1 parent 2532b05 commit 9e16b0e
Showing 1 changed file with 38 additions and 10 deletions.
48 changes: 38 additions & 10 deletions m4/ax_realpath_lib.m4
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,44 @@ AC_DEFUN([AX_REALPATH_LIB],
AS_IF([test -n "${myLIBPATH}" && test -s "${myLIBPATH}"], [
AC_MSG_RESULT([initially '${myLIBPATH}'])
dnl # Resolving the directory location is a nice bonus
dnl # (usually the paths are relative to toolkit and ugly,
dnl # though maybe arguably portable with regard to symlinks).
dnl # The primary goal is to resolve the actual library file
dnl # name like "libnetsnmp.so.1.2.3", so we can preferentially
dnl # try to dlopen() it on a system with a packaged footprint
dnl # that does not serve short (developer-friendly) links like
dnl # "libnetsnmp.so".
myLIBPATH_REAL="${myLIBPATH}"
AX_REALPATH([${myLIBPATH}], [myLIBPATH_REAL])
AC_MSG_CHECKING([whether the file is a "GNU ld script" and not a binary])
AS_IF([LANG=C LC_ALL=C file "${myLIBPATH}" | grep -Ei '(ascii|text)' && grep -w GROUP "${myLIBPATH}" >/dev/null], [
# dnl e.g. # cat /usr/lib/x86_64-linux-gnu/libusb.so
# dnl /* GNU ld script. */
# dnl GROUP ( /lib/x86_64-linux-gnu/libusb-0.1.so.4.4.4 )
# dnl Note that spaces around parentheses vary, more keywords
# dnl may be present in a group (e.g. AS_NEEDED), and comment
# dnl strings are inconsistent (useless to match by).
AC_MSG_RESULT([yes, iterate further])
myLIBPATH_LDSCRIPT="`grep -w GROUP "${myLIBPATH}" | sed 's,^.*GROUP *( *\(/@<:@^ @:>@*\.so@<:@^ @:>@*\)@<:@^0-9a-zA-Z_.-@:>@.*$,\1,'`"
AS_IF([test -n "${myLIBPATH_LDSCRIPT}" && test -s "${myLIBPATH_LDSCRIPT}"], [
AC_MSG_NOTICE([will dig into ${myLIBPATH_LDSCRIPT}])
dnl # See detailed comments just below
myLIBPATH_REAL="${myLIBPATH_LDSCRIPT}"
AX_REALPATH([${myLIBPATH_LDSCRIPT}], [myLIBPATH_REAL])
], [
AC_MSG_NOTICE([could not determine a further path name, will use what we have])
dnl # See detailed comments just below
myLIBPATH_REAL="${myLIBPATH}"
AX_REALPATH([${myLIBPATH}], [myLIBPATH_REAL])
])
],[
AC_MSG_RESULT([no, seems like a normal binary])
dnl # Resolving the directory location is a nice bonus
dnl # (usually the paths are relative to toolkit and ugly,
dnl # though maybe arguably portable with regard to symlinks).
dnl # The primary goal is to resolve the actual library file
dnl # name like "libnetsnmp.so.1.2.3", so we can preferentially
dnl # try to dlopen() it on a system with a packaged footprint
dnl # that does not serve short (developer-friendly) links like
dnl # "libnetsnmp.so".
myLIBPATH_REAL="${myLIBPATH}"
AX_REALPATH([${myLIBPATH}], [myLIBPATH_REAL])
])
AC_MSG_RESULT(${myLIBPATH_REAL})
$2="${myLIBPATH_REAL}"
],[
Expand Down

0 comments on commit 9e16b0e

Please sign in to comment.