Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixup-libgfortran.sh: Use patchelf instead of parsing ldd output #34155

Merged
merged 1 commit into from
Jan 12, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions contrib/fixup-libgfortran.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down