Tuesday, July 31, 2012

Building xnu for OS X 10.8 Mountain Lion

The OS X kernel source (xnu) has been released for OS X 10.8 Mountain Lion: here

Building xnu requires Xcode and some additional open-source (but not pre-installed) dependencies. You can build xnu manually by doing:

  1. Install OS X Mountain Lion and Xcode 4.4
  2. Launch Xcode, go to Preferences... > Downloads and install the Command Line Tools
  3. Download the source for the dtrace and AvailabilityVersions projects, which are required dependencies, as well as xnu itself
    $ curl -O http://opensource.apple.com/tarballs/dtrace/dtrace-96.tar.gz
    $ curl -O http://opensource.apple.com/tarballs/AvailabilityVersions/AvailabilityVersions-4.2.tar.gz
    $ curl -O http://opensource.apple.com/tarballs/xnu/xnu-2050.7.9.tar.gz
  4. Build and install CTF tools from dtrace
    $ tar zxf dtrace-96.tar.gz
    $ cd dtrace-96
    $ 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/usr/local /usr/local
    $ cd ..
  5. Install AvailabilityVersions
    $ tar zxf AvailabilityVersions-4.2.tar.gz
    $ cd AvailabilityVersions-4.2
    $ mkdir -p dst
    $ make install SRCROOT=$PWD DSTROOT=$PWD/dst
    $ sudo ditto $PWD/dst/usr/local /usr/local
    $ cd ..
  6. Build xnu
    $ tar zxf xnu-2050.7.9.tar.gz 
    $ cd xnu-2050.7.9
Update: If you are using Xcode 4.6, add CWARNFLAGS_STD="-Wall" CXXWARNFLAGS_STD="-Wall" to your make(1) invocation to avoid new warnings-as-errors


Mridul said...

Thank you for this!

Mridul said...
This comment has been removed by the author.
Unknown said...

Thanks for the write-up - you saved me time an effort, kudos for caring enough to write it up!

Unknown said...

Thanks for these great instructions. When tested with XCode 5 tools, building 10.8.4 generates a multitude of 'use of __private_extern__ on' errors. Any clue as to how to get rid of it, short of reinstalling XCode 4.6? Thanks, once again.

Unknown said...
This comment has been removed by the author.
Gili Satenspiel said...

Thanks you so much!

guest said...

This works on 10.9 as well.
Just the versions of the source is different and there are some newer tools available

I used those versions: