Skip to content

Instantly share code, notes, and snippets.

@shinvou
Created December 4, 2017 04:16
Show Gist options
  • Save shinvou/03e96425f9a9401557b2b8c345c4b000 to your computer and use it in GitHub Desktop.
Save shinvou/03e96425f9a9401557b2b8c345c4b000 to your computer and use it in GitHub Desktop.
Build the macOS High Sierra (10.13.x) xnu kernel.
#!/bin/bash
#
# This is more or less just a bash script for this tutorial: https://0xcc.re/building-xnu-kernel-macosx-sierrra-10-12-x/
# So, huge thanks to Mikal Villa! I updated the tarballs for macOS 10.13 and added line 29.
#
curl -O https://opensource.apple.com/tarballs/dtrace/dtrace-262.tar.gz && \
curl -O https://opensource.apple.com/tarballs/AvailabilityVersions/AvailabilityVersions-32.tar.gz && \
curl -O https://opensource.apple.com/tarballs/libdispatch/libdispatch-913.1.6.tar.gz && \
curl -O https://opensource.apple.com/tarballs/libplatform/libplatform-161.tar.gz
curl -O https://opensource.apple.com/tarballs/xnu/xnu-4570.1.46.tar.gz
export XNUPATH=$(pwd)/xnu-4570.1.46
for file in *.tar.gz; do tar -zxf $file; done && rm -f *.tar.gz
cd dtrace-262
mkdir -p obj sym dst
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 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain
cd ../AvailabilityVersions-32/
mkdir -p dst
make install SRCROOT=$PWD DSTROOT=$PWD/dst
sudo ditto $PWD/dst/usr/local `xcrun -sdk macosx -show-sdk-path`/usr/local
cd ../libplatform-161
sudo ditto $PWD/include `xcrun -sdk macosx -show-sdk-path`/usr/local/include
sudo ditto $PWD/private/os/internal `xcrun -sdk macosx -show-sdk-path`/usr/local/include/os/internal
cd $XNUPATH
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
sudo 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 ditto BUILD.hdrs/dst `xcrun -sdk macosx -show-sdk-path`
cd ../libdispatch-913.1.6
mkdir -p BUILD.hdrs/obj BUILD.hdrs/sym BUILD.hdrs/dst
sudo 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 `xcrun -sdk macosx -show-sdk-path`/usr/local
cd $XNUPATH
# You can choose between RELEASE, DEVELOPMENT or DEBUG, or all.
make SDKROOT=macosx ARCH_CONFIGS=X86_64 KERNEL_CONFIGS="RELEASE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment