|
|
< Previous PageNext Page > |
Before you can build a kernel, you must first obtain source code. Source code for the Mac OS X kernel can be found in the Darwin xnu
project on http://www.opensource.apple.com. To find out your current kernel version, use the command uname -a
. If you run into trouble, search the archives of the darwin-kernel and darwin-development mailing lists for information. If that doesn’t help, ask for assistance on either list. The list archives and subscription information can be found at http://www.lists.apple.com.
Note: Before you begin, make sure you extract the sources in a directory whose path does not contain any “special” characters (non-alphanumeric characters other than dash and underscore), as having such characters in the path leading up to the build directory can cause compiling to fail.
Also, make sure that /usr/local/bin
is in your PATH
environment variable as follows:
If you are using a csh derivative such as tcsh, you should add set path = (/usr/local/bin $path)
to your .tcshrc
file
If you are using a Bourne shell derivative, you should add export PATH=/usr/local/bin:$PATH
to your .bashrc
file.
Important: Once you have obtained and extracted the sources, before you begin compiling kernel support tools, you should configure your system to build using gcc 3.3. The Mac OS X 10.4 kernel will not build using gcc 4.0. To do this, type:
sudo gcc_select 3.3 |
Important:
Before building anything, you should make sure you are running the latest version of Mac OS X with the latest developer tools. The xnu compile process may reference various external headers from /System/Library/Frameworks
. These headers are only installed as part of a developer tools installation, not as part of the normal Mac OS X install process.
Next, you will need to compile several support tools. Get the bootstrap_cmds
, Libstreams
, kext_tools
, IOKitUser
, and cctools
packages from http://www.opensource.apple.com. Extract the files from these .tar
packages, then do the following:
sudo mkdir -p /usr/local/bin |
sudo mkdir -p /usr/local/lib |
cd bootstrap_cmds-version/relpath.tproj |
make |
sudo make install |
cd ../../Libstreams-version |
make |
sudo make install |
cd ../cctools-version |
sudo cp /usr/include/ar.h \ |
/System/Library/Frameworks/Kernel.framework/Headers |
In the cctools
package, modify the Makefile
, and change the COMMON_SUBDIRS
line (including the continuation line after it) to read:
COMMON_SUBDIRS = libstuff libmacho misc |
Finally, issue the following commands:
make RC_OS=macos |
sudo cp misc/seg_hack.NEW /usr/local/bin/seg_hack |
cd ld |
make RC_OS=macos kld_build |
sudo cp static_kld/libkld.a /usr/local/lib |
sudo ranlib /usr/local/lib/libkld.a |
Now you’re done with the cctools project. One final step remains: compiling kextsymboltool
. To do this, extract the kext_tools
tarball, then do the following:
sudo mkdir -p /System/Library/Frameworks/IOKit.framework/Versions/A/PrivateHeaders/kext |
cd /System/Library/Frameworks/IOKit.framework/ |
sudo ln -s Versions/A/PrivateHeaders PrivateHeaders |
sudo cp PATH_TO_IOKITUSER/IOKitUser-version/kext.subproj/*.h PrivateHeaders/kext |
cd PATH_TO_KEXT_TOOLS/kext_tools-version |
gcc kextsymboltool.c -o kextsymboltool |
sudo cp kextsymboltool /usr/local/bin |
Warning:
If you do not use a version of kextsymboltool
that is at least as current as your kernel, you will get serious compile failures. If you see the error message “exported name not in import list”, there’s a good chance you aren’t using a current kextsymboltool
.
Congratulations. You now have all the necessary tools, libraries, and header files to build a kernel.
The next step is to compile the kernel itself. First, change directories into the xnu
directory. Next, you need to set a few environment variables appropriately. For your convenience, the kernel sources contain shell scripts to do this for you. If you are using sh, bash, zsh, or some other Bourne-compatible shell, issue the following command:
source SETUP/setup.sh |
If you are using csh, tcsh, or a similar shell, use the following command:
source SETUP/setup.csh |
Then, you should be able to type
make exporthdrs |
make all |
and get a working kernel in BUILD/obj/RELEASE_PPC/mach_kernel
(assuming you are building a RELEASE
kernel for PowerPC, of course).
If things don’t work, the darwin-kernel mailing list a good place to get help.
< Previous PageNext Page > |
Last updated: 2006-11-07
|
Get information on Apple products.
Visit the Apple Store online or at retail locations. 1-800-MY-APPLE Copyright © 2007 Apple Inc. All rights reserved. | Terms of use | Privacy Notice |