Building xnu requires Xcode and some additional open-source (but not pre-installed) dependencies. You can build xnu manually by doing:
- Install OS X El Capitan and Xcode 7.0, 7.1, or 7.2 from the Mac App Store, make sure the Xcode license has been agreed-to with "sudo xcodebuild -license"
- Download the source for the dtrace and AvailabilityVersions projects, which are required dependencies, as well as xnu itself
$ curl -O https://opensource.apple.com/tarballs/dtrace/dtrace-168.tar.gz $ curl -O https://opensource.apple.com/tarballs/AvailabilityVersions/AvailabilityVersions-20.tar.gz $ curl -O https://opensource.apple.com/tarballs/xnu/xnu-3247.1.106.tar.gz
- Build and install CTF tools from dtrace
$ tar zxf dtrace-168.tar.gz $ cd dtrace-168 $ 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 Password: $ cd ..
- Install AvailabilityVersions
$ tar zxf AvailabilityVersions-20.tar.gz $ cd AvailabilityVersions-20 $ 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 ..
- Build xnu
$ tar zxf xnu-3247.1.106.tar.gz $ cd xnu-3247.1.106 $ make SDKROOT=macosx ARCH_CONFIGS=X86_64 KERNEL_CONFIGS=RELEASE
Update: If you are attempting to add system calls, you may also need to build Libsyscall.
- Download the Libsystem source
$ curl -O https://opensource.apple.com/tarballs/Libsystem/Libsystem-1225.1.1.tar.gz
- Install Libsystem headers
$ tar zxf Libsystem-1225.1.1.tar.gz $ cd Libsystem-1225.1.1 $ xcodebuild installhdrs -sdk macosx ARCHS='x86_64 i386' SRCROOT=$PWD OBJROOT=$PWD/obj SYMROOT=$PWD/sym DSTROOT=$PWD/dst $ sudo ditto $PWD/dst `xcrun -sdk macosx -show-sdk-path` $ cd ..
- Install xnu and Libsyscall headers
$ cd xnu-3247.1.106 $ 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`
- Build Libsyscall
$ mkdir -p BUILD.libsyscall/obj BUILD.libsyscall/sym BUILD.libsyscall/dst $ sudo xcodebuild install -project libsyscall/Libsyscall.xcodeproj -sdk macosx ARCHS='x86_64 i386' SRCROOT=$PWD/libsyscall OBJROOT=$PWD/BUILD.libsyscall/obj SYMROOT=$PWD/BUILD.libsyscall/sym DSTROOT=$PWD/BUILD.libsyscall/dst
- To install custom OS components, System Integrity Protection must be disabled.
- To install the resulting new binaries, execute:
- xnu:
$ sudo cp BUILD/obj/RELEASE_X86_64/kernel /System/Library/Kernels/ $ sudo kextcache -invalidate / / locked; waiting for lock. Lock acquired; proceeding. ... $ sudo reboot
- Libsyscall:
$ sudo cp BUILD.libsyscall/dst/usr/lib/system/libsystem_kernel.dylib /usr/lib/system/ $ sudo update_dyld_shared_cache ... $ sudo reboot
- xnu: