-
-
Save below/8482f56dd98e1c3802dd436a1e865090 to your computer and use it in GitHub Desktop.
Build the macOS High Sierra (10.13.3) xnu kernel.
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
#!/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. | |
# | |
function checkError { | |
if [ $? -ne 0 ] ; then | |
echo "Script failed" | |
exit | |
fi | |
} | |
bold=$(tput bold) | |
normal=$(tput sgr0) | |
echo "${bold}Downloading sources${normal}" | |
curl -O https://opensource.apple.com/tarballs/dtrace/dtrace-262.tar.gz && \ | |
checkError | |
curl -O https://opensource.apple.com/tarballs/AvailabilityVersions/AvailabilityVersions-32.30.1.tar.gz && \ | |
checkError | |
curl -O https://opensource.apple.com/tarballs/libdispatch/libdispatch-913.30.4.tar.gz && \ | |
checkError | |
curl -O https://opensource.apple.com/tarballs/libplatform/libplatform-161.20.1.tar.gz | |
checkError | |
curl -O https://opensource.apple.com/tarballs/xnu/xnu-4570.41.2.tar.gz | |
checkError | |
export XNUPATH=$(pwd)/xnu-4570.41.2 | |
for file in *.tar.gz; do tar -zxf $file; done && rm -f *.tar.gz | |
echo "${bold}Building dtrace${normal}" | |
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 | |
checkError | |
sudo ditto $PWD/dst/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain | |
checkError | |
echo "${bold}Building AvailabilityVersions${normal}" | |
cd ../AvailabilityVersions-32.30.1/ | |
mkdir -p dst | |
make install SRCROOT=$PWD DSTROOT=$PWD/dst | |
checkError | |
sudo ditto $PWD/dst/usr/local `xcrun -sdk macosx -show-sdk-path`/usr/local | |
checkError | |
echo "${bold}Building libplatform${normal}" | |
cd ../libplatform-161.20.1 | |
sudo ditto $PWD/include `xcrun -sdk macosx -show-sdk-path`/usr/local/include | |
checkError | |
sudo ditto $PWD/private/os/internal `xcrun -sdk macosx -show-sdk-path`/usr/local/include/os/internal | |
checkError | |
echo "${bold}Installing Headers${normal}" | |
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 | |
checkError | |
# HACK: The subsequent build command fails with a missing file error. We create | |
# that file so that the build continues. | |
touch libsyscall/os/thread_self_restrict.h | |
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 | |
checkError | |
# Set permissions correctly before dittoing over MacOSX10.13.sdk. | |
sudo chown -R root:wheel BUILD.hdrs/dst/ | |
checkError | |
sudo ditto BUILD.hdrs/dst `xcrun -sdk macosx -show-sdk-path` | |
checkError | |
echo "${bold}Building libdispatch${normal}" | |
cd ../libdispatch-913.30.4 | |
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 | |
checkError | |
sudo ditto $PWD/dst/usr/local `xcrun -sdk macosx -show-sdk-path`/usr/local | |
checkError | |
echo "${bold}Building xnu${normal}" | |
cd $XNUPATH | |
# You can choose between RELEASE, DEVELOPMENT or DEBUG, or all. | |
make SDKROOT=macosx ARCH_CONFIGS=X86_64 KERNEL_CONFIGS="RELEASE" BUILD_WERROR=0 LOGCOLORS=y |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment