diff options
author | jperkin <jperkin@pkgsrc.org> | 2022-09-12 12:32:30 +0000 |
---|---|---|
committer | jperkin <jperkin@pkgsrc.org> | 2022-09-12 12:32:30 +0000 |
commit | 3709b206ca697d01c1ed5fcb19d10c1dae639957 (patch) | |
tree | 58e662e27a67e2911b68e5392e292acef18a56d5 | |
parent | 21d505c1481ddc2329f2317bb22cca4ab261d508 (diff) | |
download | pkgsrc-3709b206ca697d01c1ed5fcb19d10c1dae639957.tar.gz |
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.
-rw-r--r-- | bootstrap/README.macOS | 7 | ||||
-rwxr-xr-x | bootstrap/bootstrap | 14 | ||||
-rw-r--r-- | mk/platform/Darwin.mk | 28 |
3 files changed, 39 insertions, 10 deletions
diff --git a/bootstrap/README.macOS b/bootstrap/README.macOS index 0f89c706c32..6f5be0ab868 100644 --- a/bootstrap/README.macOS +++ b/bootstrap/README.macOS @@ -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 @@ see "No suitable Xcode SDK or Command Line Tools installed." This 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 --git a/bootstrap/bootstrap b/bootstrap/bootstrap index 5aa0cf6fa52..6df8c86093a 100755 --- a/bootstrap/bootstrap +++ b/bootstrap/bootstrap @@ -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> # All rights reserved. @@ -589,6 +589,14 @@ Darwin) 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 @@ fi 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 --git a/mk/platform/Darwin.mk b/mk/platform/Darwin.mk index e711606907f..acf02778f3a 100644 --- a/mk/platform/Darwin.mk +++ b/mk/platform/Darwin.mk @@ -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 @@ MAKEFLAGS+= OSX_VERSION=${OSX_VERSION:Q} # 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.2= 12.1 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 |