diff --git a/build/make/Makefile.in b/build/make/Makefile.in index 49c0cc4ebcf..7a13e5a9e23 100644 --- a/build/make/Makefile.in +++ b/build/make/Makefile.in @@ -17,6 +17,7 @@ # Always use bash for make rules SHELL = @SHELL@ +ifndef DEBUG_RULES # Check a variable that is only set in build/make/install, but not in sage-env, for example ifndef SAGE_PKGCONFIG # Set by build/bin/sage-sdist, which invokes the Makefile directly in @@ -25,6 +26,7 @@ ifndef SAGE_SPKG_COPY_UPSTREAM $(error This Makefile needs to be invoked by build/make/install) endif endif +endif # Directory to keep track of which packages are installed - relative to installation prefix SPKG_INST_RELDIR = var/lib/sage/installed diff --git a/build/pkgs/bliss/spkg-install.in b/build/pkgs/bliss/spkg-install.in index 4124a2338e5..b988d6262ce 100644 --- a/build/pkgs/bliss/spkg-install.in +++ b/build/pkgs/bliss/spkg-install.in @@ -1,3 +1,7 @@ +if [ "$UNAME" = "Darwin" ]; then + LDFLAGS="${LDFLAGS} -Wl,-rpath,${SAGE_LOCAL}/lib" + export LDFLAGS +fi cd src sdh_cmake -DUSE_GMP=OFF -DCMAKE_VERBOSE_MAKEFILE=ON sdh_make diff --git a/build/pkgs/primecount/spkg-install.in b/build/pkgs/primecount/spkg-install.in index 0a63840d8cb..7589fad8cb9 100644 --- a/build/pkgs/primecount/spkg-install.in +++ b/build/pkgs/primecount/spkg-install.in @@ -1,3 +1,7 @@ +if [ "$UNAME" = "Darwin" ]; then + LDFLAGS="${LDFLAGS} -Wl,-rpath,${SAGE_LOCAL}/lib" + export LDFLAGS +fi cd src # Issue #33054: primecount needs "-std=gnu++..." diff --git a/build/pkgs/primecountpy/spkg-install.in b/build/pkgs/primecountpy/spkg-install.in index 37ac1a53437..829ebe2fcc5 100644 --- a/build/pkgs/primecountpy/spkg-install.in +++ b/build/pkgs/primecountpy/spkg-install.in @@ -1,2 +1,7 @@ +if [ "$UNAME" = "Darwin" ]; then + LDFLAGS="${LDFLAGS} -Wl,-rpath,${SAGE_LOCAL}/lib" + export LDFLAGS +fi + cd src sdh_pip_install . diff --git a/build/pkgs/symengine_py/spkg-install.in b/build/pkgs/symengine_py/spkg-install.in index 37ac1a53437..829ebe2fcc5 100644 --- a/build/pkgs/symengine_py/spkg-install.in +++ b/build/pkgs/symengine_py/spkg-install.in @@ -1,2 +1,7 @@ +if [ "$UNAME" = "Darwin" ]; then + LDFLAGS="${LDFLAGS} -Wl,-rpath,${SAGE_LOCAL}/lib" + export LDFLAGS +fi + cd src sdh_pip_install . diff --git a/src/bin/sage-env b/src/bin/sage-env index 61901897bcd..b9221fe3567 100644 --- a/src/bin/sage-env +++ b/src/bin/sage-env @@ -370,22 +370,38 @@ if [ -n "$PYTHONHOME" ]; then fi if [ -n "$SAGE_LOCAL" ]; then - # On OS X, test whether "ld-classic" is present in the installed - # version of the command-line tools. If so, we add "-ld_classic" - # to LD_FLAGS. See #36599. - # When the full XCode is installed and in use, for example after - # "sudo xcode-select -s /Applications/Xcode.app", then "xcode-select -p" - # gives "/Applications/Xcode.app/Contents/Developer", but "ld-classic" - # is not in the subdirectory "usr/bin/" but rather in the subdirectory - # "Toolchains/XcodeDefault.xctoolchain/usr/bin/". See #37237. - # However, if LD is set explicitly, as it is within conda on macOS, - # do not not do this. - if [ "$UNAME" = "Darwin" ] && [ -z "$LD" ] && [ -x "$(xcode-select -p)/usr/bin/ld-classic" -o -x "$(xcode-select -p)/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld-classic" ] ; then - LDFLAGS="-L$SAGE_LOCAL/lib -Wl,-ld_classic,-rpath,$SAGE_LOCAL/lib $LDFLAGS" - else - LDFLAGS="-L$SAGE_LOCAL/lib -Wl,-rpath,$SAGE_LOCAL/lib $LDFLAGS" + # Construct and export LDFLAGS + if [ "$UNAME" = "Darwin" ]; then + LDFLAGS="-L$SAGE_LOCAL/lib $LDFLAGS" + # On OS X, use the old linker if it is available. + # if "ld-classic" is present in the selected XCode + # toolchain, add "-Wl,-ld_classic" to LDFLAGS (see #36599) unless + # LD is already set, as it will be with conda on macOS. When the + # selected toolchain is in the Xcode app the output of "xcode-select -p" + # is "/Applications/Xcode.app/Contents/Developer", but "ld-classic" is + # not in the subdirectory "usr/bin/" but rather in the subdirectory + # "Toolchains/XcodeDefault.xctoolchain/usr/bin/". (See #37237.) + if [ -z "$LD" ]; then + # Running xcode-select on a system with no toolchain writes an + # error message to stderr, so redirect stderr to /dev/null. + XCODE_PATH=$(/usr/bin/xcode-select -p 2> /dev/null) + if [ -n $XCODE_PATH ]; then + if [ -x "$XCODE_PATH/usr/bin/ld-classic" -o \ + -x "$XCODE_PATH/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld-classic" ]; then + LDFLAGS="$LDFLAGS -Wl,-ld_classic" + fi + else + # On a macOS system with no toolchain we don't want this script + # to call gcc because that will also print an error message to + # stderr. We can avoid this by setting AS and LD to their + # default values. + AS=as + LD=ld + fi + fi fi if [ "$UNAME" = "Linux" ]; then + LDFLAGS="-L$SAGE_LOCAL/lib -Wl,-rpath,$SAGE_LOCAL/lib $LDFLAGS" LDFLAGS="-Wl,-rpath-link,$SAGE_LOCAL/lib $LDFLAGS" fi export LDFLAGS