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
    Password:
    $ 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
    $ make ARCH_CONFIGS=X86_64 KERNEL_CONFIGS=RELEASE
    
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