3 B. How to install a new header file from XNU
5 =============================================
10 This builds all the components for kernel, architecture, and machine
11 configurations defined in TARGET_CONFIGS. Additionally, we also support
12 architectures defined in ARCH_CONFIGS and kernel configurations defined in
13 KERNEL_CONFIGS. Note that TARGET_CONFIGS overrides any configurations defined
14 in ARCH_CONFIGS and KERNEL_CONFIGS.
16 By default, architecture defaults to the build machine
17 architecture, and the kernel configuration is set to build for DEVELOPMENT.
19 This will also create a bootable image, mach_kernel, and a kernel binary
20 with symbols, mach_kernel.sys.
23 /* this is all you need to do to build with RELEASE kernel configuration */
24 make TARGET_CONFIGS="release x86_64 default" SDKROOT=/path/to/SDK
26 or the following is equivalent (ommitted SDKROOT will use /)
28 make ARCH_CONFIGS=X86_64
30 2) Building a Component
32 Go to the top directory in your XNU project.
34 If you are using a sh-style shell, run the following command:
37 If you are using a csh-style shell, run the following command:
38 % source SETUP/setup.csh
40 This will define the following environmental variables:
41 SRCROOT, OBJROOT, DSTROOT, SYMROOT
43 From a component top directory:
47 This builds a component for all architectures, kernel configurations, and
48 machine configurations defined in TARGET_CONFIGS (or alternately ARCH_CONFIGS
52 $(OBJROOT)/RELEASE_X86_64/osfmk/RELEASE/osfmk.filelist: list of objects in osfmk component
54 From the component top directory:
58 This includes your component in the bootable image, mach_kernel, and
59 in the kernel binary with symbols, mach_kernel.sys.
61 WARNING: If a component header file has been modified, you will have to do
62 the above procedure 1.
66 Define kernel configuration to DEBUG in your environment or when running a
67 make command. Then, apply procedures 4, 5
69 $ make TARGET_CONFIGS="DEBUG X86_64 DEFAULT" all
73 $ make KERNEL_CONFIGS=DEBUG ARCH_CONFIGS=X86_64 all
77 $ export TARGET_CONFIGS="DEBUG X86_64 DEFAULT"
78 $ export SDKROOT=/path/to/SDK
82 $(OBJROOT)/DEBUG_X86_64/osfmk/DEBUG/osfmk.filelist: list of objects in osfmk component
83 $(OBJROOT)/DEBUG_X86_64/mach_kernel: bootable image
87 Define architectures in your environment or when running a make command.
88 Apply procedures 3, 4, 5
90 $ make TARGET_CONFIGS="RELEASE I386 DEFAULT RELEASE X86_64 DEFAULT" exporthdrs all
94 $ make ARCH_CONFIGS="I386 X86_64" exporthdrs all
98 $ export ARCH_CONFIGS="I386 X86_64"
102 To display complete tool invocations rather than an abbreviated version,
105 6) Debug information formats
106 By default, a DWARF debug information repository is created during the install phase; this is a "bundle" named mach_kernel.dSYM
107 To select the older STABS debug information format (where debug information is embedded in the mach_kernel.sys image), set the BUILD_STABS environment variable.
108 $ export BUILD_STABS=1
111 7) Build check before integration
113 From the top directory, run:
115 $ ~rc/bin/buildit . -arch i386 -arch x86_64 -arch armv7 -arch ppc -noinstallsrc -nosum
118 xnu supports a number of XBS build aliases, which allow B&I to build
119 the same source submission multiple times in different ways, to
120 produce different results. Each build alias supports the standard
121 "clean", "install", "installsrc", "installhdrs" targets, but
122 conditionalize their behavior on the RC_ProjectName make variable
123 which is passed as the -project argument to ~rc/bin/buildit, which
126 -project xnu # the default, builds /mach_kernel, kernel-space
127 # headers, user-space headers, man pages,
130 -project xnu_debug # a DEBUG kernel in /AppleInternal with dSYM
132 -project libkxld # user-space version of kernel linker
134 -project Libsyscall # automatically generate BSD syscall stubs
138 8) Creating tags and cscope
140 Set up your build environment as per instructions in 2a
142 From the top directory, run:
144 $ make tags # this will build ctags and etags on a case-sensitive
145 # volume, only ctags on case-insensitive
147 $ make TAGS # this will build etags
149 $ make cscope # this will build cscope database
151 9) Other makefile options
153 $ make MAKEJOBS=-j8 # this will use 8 processes during the build. The default is 2x the number of active cores
155 $ make -w # trace recursive make invocations. Useful in combination with VERBOSE=YES
157 $ make BUILD_LTO=1 # built with LLVM Link Time Optimization (experimental)
159 =============================================
160 B. How to install a new header file from XNU
162 [Note: This does not cover installing header files in IOKit framework]
164 1) XNU installs header files at the following locations -
165 a. $(DSTROOT)/System/Library/Frameworks/Kernel.framework/Headers
166 b. $(DSTROOT)/System/Library/Frameworks/Kernel.framework/PrivateHeaders
167 c. $(DSTROOT)/System/Library/Frameworks/System.framework/Headers
168 d. $(DSTROOT)/System/Library/Frameworks/System.framework/PrivateHeaders
169 e. $(DSTROOT)/usr/include/
171 Kernel.framework is used by kernel extensions. System.framework
172 and /usr/include are used by user level applications. The header
173 files in framework's "PrivateHeaders" are only available for Apple
174 Internal development.
176 2) The directory containing the header file should have a Makefile that
177 creates the list of files that should be installed at different locations.
178 If you are adding first header file in a directory, you will need to
179 create Makefile similar to xnu/bsd/sys/Makefile.
181 Add your header file to the correct file list depending on where you want
182 to install it. The default locations where the header files are installed
183 from each file list are -
185 a. DATAFILES : To make header file available in user level -
186 $(DSTROOT)/System/Library/Frameworks/System.framework/Headers
187 $(DSTROOT)/System/Library/Frameworks/System.framework/PrivateHeaders
188 $(DSTROOT)/usr/include/
190 b. PRIVATE_DATAFILES : To make header file available to Apple internal in
192 $(DSTROOT)/System/Library/Frameworks/System.framework/PrivateHeaders
194 c. KERNELFILES : To make header file available in kernel level -
195 $(DSTROOT)/System/Library/Frameworks/Kernel.framework/Headers
196 $(DSTROOT)/System/Library/Frameworks/Kernel.framework/PrivateHeaders
198 d. PRIVATE_KERNELFILES : To make header file available to Apple internal
199 for kernel extensions -
200 $(DSTROOT)/System/Library/Frameworks/Kernel.framework/PrivateHeaders
202 3) The Makefile combines the file lists mentioned above into different
203 install lists which are used by build system to install the header files.
205 If the install list that you are interested does not exist, create it
206 by adding the appropriate file lists. The default install lists, its
207 member file lists and their default location are described below -
209 a. INSTALL_MI_LIST : Installs header file to location that is available to
210 everyone in user level.
212 $(DSTROOT)/System/Library/Frameworks/System.framework/Headers
213 $(DSTROOT)/usr/include/
215 INSTALL_MI_LIST = ${DATAFILES}
217 b. INSTALL_MI_LCL_LIST : Installs header file to location that is available
218 for Apple internal in user level.
220 $(DSTROOT)/System/Library/Frameworks/System.framework/PrivateHeaders
222 INSTALL_MI_LCL_LIST = ${DATAFILES} ${PRIVATE_DATAFILES}
224 c. INSTALL_KF_MI_LIST : Installs header file to location that is available
225 to everyone for kernel extensions.
227 $(DSTROOT)/System/Library/Frameworks/Kernel.framework/Headers
229 INSTALL_KF_MI_LIST = ${KERNELFILES}
231 d. INSTALL_KF_MI_LCL_LIST : Installs header file to location that is
232 available for Apple internal for kernel extensions.
234 $(DSTROOT)/System/Library/Frameworks/Kernel.framework/PrivateHeaders
236 INSTALL_KF_MI_LCL_LIST = ${KERNELFILES} ${PRIVATE_KERNELFILES}
238 4) If you want to install the header file in a sub-directory of the paths
239 described in (1), specify the directory name using two variable
240 INSTALL_MI_DIR and EXPORT_MI_DIR as follows -
242 INSTALL_MI_DIR = dirname
243 EXPORT_MI_DIR = dirname
245 5) A single header file can exist at different locations using the steps
246 mentioned above. However it might not be desirable to make all the code
247 in the header file available at all the locations. For example, you
248 want to export a function only to kernel level but not user level.
250 You can use C language's pre-processor directive (#ifdef, #endif, #ifndef)
251 to control the text generated before a header file is installed. The kernel
252 only includes the code if the conditional macro is TRUE and strips out
253 code for FALSE conditions from the header file.
255 Some pre-defined macros and their descriptions are -
256 a. PRIVATE : If true, code is available to all of the xnu kernel and is
257 not available in kernel extensions and user level header files. The
258 header files installed in all the paths described above in (1) will not
259 have code enclosed within this macro.
261 b. KERNEL_PRIVATE : Same as PRIVATE
263 c. BSD_KERNEL_PRIVATE : If true, code is available to the xnu/bsd part of
264 the kernel and is not available to rest of the kernel, kernel extensions
265 and user level header files. The header files installed in all the
266 paths described above in (1) will not have code enclosed within this
269 d. KERNEL : If true, code is available only in kernel and kernel
270 extensions and is not available in user level header files. Only the
271 header files installed in following paths will have the code -
272 $(DSTROOT)/System/Library/Frameworks/Kernel.framework/Headers
273 $(DSTROOT)/System/Library/Frameworks/Kernel.framework/PrivateHeaders