commit:     3751da68ae4b9e67a6fdea3ed5d028a4400e11d2
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Sat Jan 27 14:02:32 2024 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Sat Jan 27 14:02:32 2024 +0000
URL:        https://gitweb.gentoo.org/repo/proj/prefix.git/commit/?id=3751da68

scripts/bootstrap-prefix: fix linking on macOS platforms with a real /

Systems that just have /usr/lib populated by dylibs and /usr/include can
just use that instead of an SDK, which is safer under certain
conditions.  A knowledgable user can modify the symlink easily to use
an SDK or something else in this case.

Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 scripts/bootstrap-prefix.sh | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/scripts/bootstrap-prefix.sh b/scripts/bootstrap-prefix.sh
index 8f83bb837f..e743594647 100755
--- a/scripts/bootstrap-prefix.sh
+++ b/scripts/bootstrap-prefix.sh
@@ -433,12 +433,21 @@ bootstrap_profile() {
        if [[ ${CHOST} == *-darwin* ]] ; then
                # setup MacOSX.sdk symlink for GCC, this should probably be
                # managed using an eselect module in the future
+               # FWIW, just use system (/) if it seems OK, for some reason
+               # early versions of TAPI-based SDKs did not include some symbols
+               # like fclose, which ld64 is able to resolve from the dylibs
+               # although they are unvisible using e.g. nm.
                rm -f "${ROOT}"/MacOSX.sdk
-               local SDKPATH=$(xcrun --show-sdk-path --sdk macosx)
-               if [[ ! -e ${SDKPATH} ]] ; then
-                       SDKPATH=$(xcodebuild -showsdks | sort -nr \
-                               | grep -o "macosx.*" | head -n1)
-                       SDKPATH=$(xcode-select 
-print-path)/SDKs/MacOSX${SDKPATH#macosx}.sdk
+               local SDKPATH
+               if [[ -e /usr/lib/libSystem.B.dylib && -d /usr/include ]] ; then
+                       SDKPATH=/
+               else
+                       SDKPATH=$(xcrun --show-sdk-path --sdk macosx)
+                       if [[ ! -e ${SDKPATH} ]] ; then
+                               SDKPATH=$(xcodebuild -showsdks | sort -nr \
+                                       | grep -o "macosx.*" | head -n1)
+                               SDKPATH=$(xcode-select 
-print-path)/SDKs/MacOSX${SDKPATH#macosx}.sdk
+                       fi
                fi
                ( cd "${ROOT}" && ln -s "${SDKPATH}" MacOSX.sdk )
                einfo "using system sources from ${SDKPATH}"

Reply via email to