cd /news/developer-tools/a-script-to-build-xnu-version-4570-1… · home topics developer-tools article
[ARTICLE · art-12350] src=gist.github.com ↗ pub= topic=developer-tools verified=true sentiment=· neutral

A script to build XNU version 4570.1.46 (macOS High Sierra 10.13).

This article provides a shell script by Brandon Azad for building XNU version 4570.1.46, which corresponds to macOS High Sierra 10.13. The script downloads the necessary source code from Apple's open-source repository, installs required tools and headers, and modifies Xcode's SDK files to successfully compile the XNU kernel.

read2 min views23 publishedOct 6, 2017
build-xnu-4570.1.46.sh

      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.

Learn more about bidirectional Unicode characters

Show hidden characters

#! /bin/bash

#

#

#

#

WORKDIR="${WORKDIR:-build-xnu-4570.1.46}" umask 022

set -ex

SDKPATH="$(xcrun --sdk macosx --show-sdk-path)"

TOOLCHAINPATH="$(xcode-select -p)/Toolchains/XcodeDefault.xctoolchain"

[ -d "${SDKPATH}" ] && [ -d "${TOOLCHAINPATH}" ]


mkdir "${WORKDIR}"

cd "${WORKDIR}"


if [ -n "${BACKUP_SDK}" ]; then

	sudo ditto "${SDKPATH}" "$(basename "${SDKPATH}")"

fi

curl https://opensource.apple.com/tarballs/xnu/xnu-4570.1.46.tar.gz | tar -xf-

curl https://opensource.apple.com/tarballs/dtrace/dtrace-262.tar.gz | tar -xf-

curl https://opensource.apple.com/tarballs/AvailabilityVersions/AvailabilityVersions-32.tar.gz | tar -xf-

curl https://opensource.apple.com/tarballs/libplatform/libplatform-161.tar.gz | tar -xf-

curl https://opensource.apple.com/tarballs/libdispatch/libdispatch-913.1.6.tar.gz | tar -xf-

cd dtrace-262

mkdir -p obj dst sym

xcodebuild install -target ctfconvert -target ctfdump -target ctfmerge ARCHS="x86_64" SRCROOT="${PWD}" OBJROOT="${PWD}/obj" SYMROOT="${PWD}/sym" DSTROOT="${PWD}/dst" sudo ditto "${PWD}/dst/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain" "${TOOLCHAINPATH}"

cd ..

cd AvailabilityVersions-32

mkdir -p dst

make install SRCROOT="${PWD}" DSTROOT="${PWD}/dst"

sudo ditto "${PWD}/dst/usr/local" "${SDKPATH}/usr/local"

cd ..

cd xnu-4570.1.46

mkdir -p BUILD.hdrs/obj BUILD.hdrs/sym BUILD.hdrs/dst

make installhdrs SDKROOT=macosx ARCH_CONFIGS=X86_64 SRCROOT="${PWD}" OBJROOT="${PWD}/BUILD.hdrs/obj" SYMROOT="${PWD}/BUILD.hdrs/sym" DSTROOT="${PWD}/BUILD.hdrs/dst" touch libsyscall/os/thread_self_restrict.h

xcodebuild installhdrs -project libsyscall/Libsyscall.xcodeproj -sdk macosx ARCHS="x86_64 i386" SRCROOT="${PWD}/libsyscall" OBJROOT="${PWD}/BUILD.hdrs/obj" SYMROOT="${PWD}/BUILD.hdrs/sym" DSTROOT="${PWD}/BUILD.hdrs/dst"

sudo chown -R root:wheel BUILD.hdrs/dst/

sudo ditto BUILD.hdrs/dst "${SDKPATH}" cd ..

cd libplatform-161

sudo ditto "${PWD}/include" "${SDKPATH}/usr/local/include"

sudo ditto "${PWD}/private"  "${SDKPATH}/usr/local/include"

cd ..

cd libdispatch-913.1.6

mkdir -p obj sym dst

xcodebuild install -project libdispatch.xcodeproj -target libfirehose_kernel -sdk macosx ARCHS="x86_64 i386" SRCROOT="${PWD}" OBJROOT="${PWD}/obj" SYMROOT="${PWD}/sym" DSTROOT="${PWD}/dst"

sudo ditto "${PWD}/dst/usr/local" "${SDKPATH}/usr/local"

cd ..

cd xnu-4570.1.46

make SDKROOT=macosx ARCH_CONFIGS=X86_64 KERNEL_CONFIGS="RELEASE"

── more in #developer-tools 4 stories · sorted by recency
── more on @brandon azad 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
Live at https://your-agent.zahid.host
Get free account → Pricing
from €0/mo · no card required
LIVE [news/a-script-to-build-xn…] indexed:0 read:2min 2017-10-06 ·