From 5251c2fa964b0e510d2043fee805d9c9c95c2781 Mon Sep 17 00:00:00 2001 From: "John H. Palmieri" Date: Mon, 30 Oct 2023 15:56:20 -0700 Subject: [PATCH 1/3] sage-env: identify the version of command-line tools (OS X) --- src/bin/sage-env | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/bin/sage-env b/src/bin/sage-env index 5c1b4b87ac7..9cdd5db453f 100644 --- a/src/bin/sage-env +++ b/src/bin/sage-env @@ -277,6 +277,15 @@ export UNAME=`uname | sed 's/CYGWIN.*/CYGWIN/' ` # Mac OS X-specific setup if [ "$UNAME" = "Darwin" ]; then export MACOSX_VERSION=`uname -r | awk -F. '{print $1}'` + # Try to identify command-line tools version. + # See https://apple.stackexchange.com/q/180957/351985. + XCLT_VERSION=`pkgutil --pkg-info=com.apple.pkg.CLTools_Executables | awk '/version: / { print $NF }' | cut -d. -f-1` + # If this didn't produce an integer, set to 0. + case $XCLT_VERSION in + ''|*[!0-9]*) export XCLT_VERSION=0 ;; # bad + *) : ;; # good + esac + export XCLT_VERSION # Work around problems on recent OS X crashing with an error message # "... may have been in progress in another thread when fork() was called" # when objective-C functions are called after fork(). See Issue #25921. From 2341fb400fa20b673422c56337ba03d9befed48e Mon Sep 17 00:00:00 2001 From: "John H. Palmieri" Date: Wed, 1 Nov 2023 21:39:31 -0700 Subject: [PATCH 2/3] Set LDFLAGS depending on version of OS X command-line tools --- src/bin/sage-env | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/bin/sage-env b/src/bin/sage-env index 9cdd5db453f..72aa454bf4a 100644 --- a/src/bin/sage-env +++ b/src/bin/sage-env @@ -383,7 +383,11 @@ if [ -n "$PYTHONHOME" ]; then fi if [ -n "$SAGE_LOCAL" ]; then - LDFLAGS="-L$SAGE_LOCAL/lib -Wl,-rpath,$SAGE_LOCAL/lib $LDFLAGS" + if [ "$UNAME" = "Darwin" ] && [ "$XCLT_VERSION" -ge 15 ]; 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" + fi if [ "$UNAME" = "Linux" ]; then LDFLAGS="-Wl,-rpath-link,$SAGE_LOCAL/lib $LDFLAGS" fi From 543cd2dca5f88a23aacd5c50132b32639a87c083 Mon Sep 17 00:00:00 2001 From: "John H. Palmieri" Date: Sat, 4 Nov 2023 15:52:23 -0700 Subject: [PATCH 3/3] Check whether command-line tools includes the executable ld-classic, and if so, set LDFLAGS to use it. --- src/bin/sage-env | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/bin/sage-env b/src/bin/sage-env index 72aa454bf4a..b4fca91b314 100644 --- a/src/bin/sage-env +++ b/src/bin/sage-env @@ -277,15 +277,6 @@ export UNAME=`uname | sed 's/CYGWIN.*/CYGWIN/' ` # Mac OS X-specific setup if [ "$UNAME" = "Darwin" ]; then export MACOSX_VERSION=`uname -r | awk -F. '{print $1}'` - # Try to identify command-line tools version. - # See https://apple.stackexchange.com/q/180957/351985. - XCLT_VERSION=`pkgutil --pkg-info=com.apple.pkg.CLTools_Executables | awk '/version: / { print $NF }' | cut -d. -f-1` - # If this didn't produce an integer, set to 0. - case $XCLT_VERSION in - ''|*[!0-9]*) export XCLT_VERSION=0 ;; # bad - *) : ;; # good - esac - export XCLT_VERSION # Work around problems on recent OS X crashing with an error message # "... may have been in progress in another thread when fork() was called" # when objective-C functions are called after fork(). See Issue #25921. @@ -383,7 +374,10 @@ if [ -n "$PYTHONHOME" ]; then fi if [ -n "$SAGE_LOCAL" ]; then - if [ "$UNAME" = "Darwin" ] && [ "$XCLT_VERSION" -ge 15 ]; 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. + if [ "$UNAME" = "Darwin" ] && [ -x "$(xcode-select -p)/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"