From 49f410105f9c7108259f254b5595cd7b2d8246bd Mon Sep 17 00:00:00 2001 From: Elliot Saba Date: Thu, 19 Dec 2019 19:59:51 +0000 Subject: [PATCH] `fixup-libgfortran.sh`: Use `patchelf` instead of parsing `ldd` output This should be less brittle, and even better, work on `musl` Also ask `$FC` where `libgfortran` lives if we have no dirname Ask `libgfortran` where to get its libraries, don't rely on recursive dep printing --- contrib/fixup-libgfortran.sh | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/contrib/fixup-libgfortran.sh b/contrib/fixup-libgfortran.sh index d1f00bdf85950..c40ea8af5971e 100755 --- a/contrib/fixup-libgfortran.sh +++ b/contrib/fixup-libgfortran.sh @@ -36,7 +36,7 @@ find_shlib() lib_path="$1" if [ -f "$lib_path" ]; then if [ "$UNAME" = "Linux" ]; then - ldd "$lib_path" | grep $2 | grep -v "not found" | cut -d' ' -f3 | xargs + "${PATCHELF}" --print-needed "$lib_path" | grep $2 | xargs else # $UNAME is "Darwin", we only have two options, see above otool -L "$lib_path" | grep $2 | cut -d' ' -f1 | xargs fi @@ -50,7 +50,7 @@ find_shlib_dir() # only get something like `@rpath/libgfortran.5.dylib` when inspecting the # libraries. We can, as a last resort, ask `$FC` directly what the full # filepath for this library is, but only if we don't have a direct path to it: - if [ $(dirname "$1") = "@rpath" ]; then + if [ $(dirname "$1") = "@rpath" ] || [ $(dirname "$1") = "." ]; then dirname "$($FC -print-file-name="$(basename "$1")" 2>/dev/null)" else dirname "$1" 2>/dev/null @@ -62,19 +62,25 @@ for lib in lapack blas openblas; do for private_libname in ${private_libdir}/lib$lib*.$SHLIB_EXT*; do # Find the paths to the libraries we're interested in. These are almost # always within the same directory, but we like to be general. - LIBGFORTRAN_PATH=$(find_shlib "$private_libname" libgfortran) - LIBGCC_PATH=$(find_shlib "$private_libname" libgcc_s) - LIBQUADMATH_PATH=$(find_shlib "$private_libname" libquadmath) + LIBGFORTRAN_PATH="$(find_shlib "$private_libname" libgfortran)" # Take the directories, add them onto LIBGFORTRAN_DIRS, which we use to # search for these libraries in the future. If there is no directory, try # asking `$FC` where such a file could be found. - LIBGFORTRAN_DIRS="$LIBGFORTRAN_DIRS $(find_shlib_dir $LIBGFORTRAN_PATH)" + LIBGFORTRAN_DIR="$(find_shlib_dir "$LIBGFORTRAN_PATH")" + LIBGFORTRAN_DIRS="$LIBGFORTRAN_DIRS $LIBGFORTRAN_DIR" + + # Save the SONAME + LIBGFORTRAN_SONAME="$(basename "$LIBGFORTRAN_PATH")" + LIBGFORTRAN_SONAMES="$LIBGFORTRAN_SONAMES $LIBGFORTRAN_SONAME" + + + # Now that we've (maybe) found a libgfortran, ask _it_ for things like libgcc_s and libquadmath: + LIBGCC_PATH="$(find_shlib "${LIBGFORTRAN_DIR}/${LIBGFORTRAN_SONAME}" libgcc_s)" + LIBQUADMATH_PATH="$(find_shlib "${LIBGFORTRAN_DIR}/${LIBGFORTRAN_SONAME}" libquadmath)" + LIBGFORTRAN_DIRS="$LIBGFORTRAN_DIRS $(find_shlib_dir $LIBGCC_PATH)" LIBGFORTRAN_DIRS="$LIBGFORTRAN_DIRS $(find_shlib_dir $LIBQUADMATH_PATH)" - - # Save the SONAMES - LIBGFORTRAN_SONAMES="$LIBGFORTRAN_SONAMES $(basename "$LIBGFORTRAN_PATH")" LIBGCC_SONAMES="$LIBGCC_SONAMES $(basename "$LIBGCC_PATH")" LIBQUADMATH_SONAMES="$LIBQUADMATH_SONAMES $(basename "$LIBQUADMATH_PATH")" done