From b78ef1670a34526700e102a11f7c257781269875 Mon Sep 17 00:00:00 2001 From: Elliot Saba Date: Thu, 27 Dec 2018 02:16:54 -0800 Subject: [PATCH] Enable `fixup-libgfortran.sh` to directly ask `$FC` for paths --- contrib/fixup-libgfortran.sh | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/contrib/fixup-libgfortran.sh b/contrib/fixup-libgfortran.sh index a994515d2356d..897c067de6a83 100755 --- a/contrib/fixup-libgfortran.sh +++ b/contrib/fixup-libgfortran.sh @@ -2,6 +2,7 @@ # This file is a part of Julia. License is MIT: https://julialang.org/license # Run as: fixup-libgfortran.sh [--verbose] <$private_libdir> +FC=${FC:-gfortran} # If we're invoked with "--verbose", create a `debug` function that prints stuff out if [ "$1" = "--verbose" ] || [ "$1" = "-v" ]; then @@ -22,7 +23,7 @@ if [ "$UNAME" = "Linux" ]; then elif [ "$UNAME" = "Darwin" ]; then SHLIB_EXT="dylib" else - echo "WARNING: Could not autodetect platform type ('uname -s' == $UNAME); assuming Linux" >&2 + echo "WARNING: Could not autodetect platform type ('uname -s' = $UNAME); assuming Linux" >&2 UNAME="Linux" SHLIB_EXT="so" fi @@ -41,6 +42,20 @@ find_shlib() fi } +find_shlib_dir() +{ + # Usually, on platforms like OSX we get full paths when linking. However, + # if we are inspecting, say, BinaryBuilder-built OpenBLAS libraries, we will + # 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 + dirname "$($FC -print-file-name="$(basename "$1")" 2>/dev/null)" + else + dirname "$1" 2>/dev/null + fi +} + # First, discover all the places where libgfortran/libgcc is, as well as their true SONAMES for lib in lapack blas openblas; do for private_libname in ${private_libdir}/lib$lib*.$SHLIB_EXT*; do @@ -51,10 +66,11 @@ for lib in lapack blas openblas; do LIBQUADMATH_PATH=$(find_shlib "$private_libname" libquadmath) # Take the directories, add them onto LIBGFORTRAN_DIRS, which we use to - # search for these libraries in the future. - LIBGFORTRAN_DIRS="$LIBGFORTRAN_DIRS $(dirname $LIBGFORTRAN_PATH 2>/dev/null)" - LIBGFORTRAN_DIRS="$LIBGFORTRAN_DIRS $(dirname $LIBGCC_PATH 2>/dev/null)" - LIBGFORTRAN_DIRS="$LIBGFORTRAN_DIRS $(dirname $LIBQUADMATH_PATH 2>/dev/null)" + # 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_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")"