pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc macOS: Support MACOSX_DEPLOYMENT_TARGET.



details:   https://anonhg.NetBSD.org/pkgsrc/rev/4111f5f02232
branches:  trunk
changeset: 385259:4111f5f02232
user:      jperkin <jperkin%pkgsrc.org@localhost>
date:      Mon Sep 12 12:32:30 2022 +0000

description:
macOS: Support MACOSX_DEPLOYMENT_TARGET.

This allows the user to specify an exact SDK to use, and can be used to build
packages for an older release of macOS than the host.  The user should ideally
set this via environment variable at bootstrap time, and pkgsrc will then
encode that into mk.conf and use it for all builds.

Tested on macOS 12.x building against an 11.3 SDK for both arm64 and x86_64.

diffstat:

 bootstrap/README.macOS |   7 ++++++-
 bootstrap/bootstrap    |  14 +++++++++++++-
 mk/platform/Darwin.mk  |  28 ++++++++++++++++++++--------
 3 files changed, 39 insertions(+), 10 deletions(-)

diffs (107 lines):

diff -r 12e2f815baa2 -r 4111f5f02232 bootstrap/README.macOS
--- a/bootstrap/README.macOS    Mon Sep 12 12:16:05 2022 +0000
+++ b/bootstrap/README.macOS    Mon Sep 12 12:32:30 2022 +0000
@@ -1,4 +1,4 @@
-$NetBSD: README.macOS,v 1.9 2022/08/01 14:49:09 jperkin Exp $
+$NetBSD: README.macOS,v 1.10 2022/09/12 12:32:30 jperkin Exp $
 
 Please read the general README file as well.
 
@@ -36,6 +36,11 @@
 usually means a pkgsrc developer needs to add another `OSX_SDK_MAP`
 entry to `mk/platform/Darwin.mk`.
 
+If you wish to build for a specific SDK, first ensure is is available in the
+correct location, and then you can set the regular MACOSX_DEPLOYMENT_TARGET
+variable during bootstrap and pkgsrc will ensure that SDK is used for both
+the bootstrap build as well as all packages built by those tools.
+
 -----
 
 Additional historical details, likely useful with older systems:
diff -r 12e2f815baa2 -r 4111f5f02232 bootstrap/bootstrap
--- a/bootstrap/bootstrap       Mon Sep 12 12:16:05 2022 +0000
+++ b/bootstrap/bootstrap       Mon Sep 12 12:32:30 2022 +0000
@@ -1,6 +1,6 @@
 #! /bin/sh
 
-# $NetBSD: bootstrap,v 1.313 2022/09/09 10:58:15 jperkin Exp $
+# $NetBSD: bootstrap,v 1.314 2022/09/12 12:32:30 jperkin Exp $
 #
 # Copyright (c) 2001-2011 Alistair Crooks <agc%NetBSD.org@localhost>
 # All rights reserved.
@@ -589,6 +589,14 @@
        machine_arch=`get_machine_arch_darwin`
        check_compiler=yes
 
+       if [ -n "${MACOSX_DEPLOYMENT_TARGET}" ]; then
+               SDK_PATH=`/usr/bin/xcrun \
+                       --sdk macosx${MACOSX_DEPLOYMENT_TARGET} \
+                       --show-sdk-path 2>/dev/null || echo /nonexistent`
+               CFLAGS="-isysroot ${SDK_PATH} ${CFLAGS}"
+               export CFLAGS
+       fi
+
        # Combine major.minor product version for simpler numerical tests.
        macos_version=`sw_vers -productVersion | \
            awk -F. '{ printf("%02d%02d", $1, $2) }'`
@@ -1393,6 +1401,10 @@
 if test -n "$LIBS"; then
        echo "LIBS+=            $LIBS" >> ${TARGET_MKCONF}
 fi
+if test -n "$MACOSX_DEPLOYMENT_TARGET"; then
+       echo "MACOSX_DEPLOYMENT_TARGET= $MACOSX_DEPLOYMENT_TARGET" >>${TARGET_MKCONF}
+       echo "MACOSX_DEPLOYMENT_TARGET= $MACOSX_DEPLOYMENT_TARGET" >>${BOOTSTRAP_MKCONF}
+fi
 
 # opsys specific fiddling
 opsys_finish
diff -r 12e2f815baa2 -r 4111f5f02232 mk/platform/Darwin.mk
--- a/mk/platform/Darwin.mk     Mon Sep 12 12:16:05 2022 +0000
+++ b/mk/platform/Darwin.mk     Mon Sep 12 12:32:30 2022 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Darwin.mk,v 1.115 2022/07/22 00:53:58 schmonz Exp $
+# $NetBSD: Darwin.mk,v 1.116 2022/09/12 12:32:31 jperkin Exp $
 #
 # Variable definitions for the Darwin operating system.
 
@@ -101,13 +101,6 @@
 # into /usr/include, so we need to query their location if /usr/include is
 # not available.
 #
-# Use current system version SDK (avoid newer SDKs).
-#
-.if exists(/usr/include/stdio.h)
-_OPSYS_INCLUDE_DIRS?=  /usr/include
-.elif exists(/usr/bin/xcrun)
-.  if !defined(OSX_SDK_PATH)
-#
 # Apple do not always keep the SDK version in step with the OS version.  When
 # that happens add a mapping below, but only within the same OS release major.
 #
@@ -119,6 +112,25 @@
 OSX_SDK_MAP.12.4=      12.3
 OSX_SDK_MAP.12.5=      12.3
 #
+# If the user has set MACOSX_DEPLOYMENT_TARGET (ideally at bootstrap time) to
+# select a specific SDK then we prefer that.
+#
+.if defined(MACOSX_DEPLOYMENT_TARGET)
+.  if !defined(OSX_SDK_PATH)
+OSX_SDK_PATH!= /usr/bin/xcrun --sdk macosx${MACOSX_DEPLOYMENT_TARGET} \
+                   --show-sdk-path 2>/dev/null || echo /nonexistent
+.  endif
+ALL_ENV+=              MACOSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET}
+MAKEFLAGS+=            OSX_SDK_PATH=${OSX_SDK_PATH:Q}
+_OPSYS_INCLUDE_DIRS?=  ${OSX_SDK_PATH}/usr/include
+CWRAPPERS_APPEND.cc+=  -isysroot ${OSX_SDK_PATH}
+CWRAPPERS_APPEND.cxx+= -isysroot ${OSX_SDK_PATH}
+_WRAP_EXTRA_ARGS.CC+=  -isysroot ${OSX_SDK_PATH}
+_WRAP_EXTRA_ARGS.CXX+= -isysroot ${OSX_SDK_PATH}
+.elif exists(/usr/include/stdio.h)
+_OPSYS_INCLUDE_DIRS?=  /usr/include
+.elif exists(/usr/bin/xcrun)
+.  if !defined(OSX_SDK_PATH)
 OSX_SDK_PATH!= /usr/bin/xcrun \
                    --sdk macosx${OSX_SDK_MAP.${OSX_VERSION}:U${OSX_VERSION}} \
                    --show-sdk-path 2>/dev/null || echo /nonexistent



Home | Main Index | Thread Index | Old Index