1 # -*- mode: makefile;-*-
3 # Copyright (C) 1999-2012 Apple Inc. All rights reserved.
5 # MakeInc.kernel augments the single-architecture
6 # recursive build system with rules specific
7 # to assembling and linking a kernel.
11 # Validate configuration options
13 ifeq ($(filter $(CURRENT_ARCH_CONFIG),$(SUPPORTED_ARCH_CONFIGS)),)
14 $(error Unsupported CURRENT_ARCH_CONFIG $(CURRENT_ARCH_CONFIG))
17 ifeq ($(filter $(CURRENT_KERNEL_CONFIG),$(SUPPORTED_KERNEL_CONFIGS)),)
18 $(error Unsupported CURRENT_KERNEL_CONFIG $(CURRENT_KERNEL_CONFIG))
21 ifeq ($(filter $(CURRENT_MACHINE_CONFIG),$(SUPPORTED_$(CURRENT_ARCH_CONFIG)_MACHINE_CONFIGS)),)
22 $(error Unsupported CURRENT_MACHINE_CONFIG $(CURRENT_MACHINE_CONFIG))
25 ifeq ($(filter $(PLATFORM),$(SUPPORTED_PLATFORMS)),)
26 $(error Unsupported PLATFORM $(PLATFORM))
29 STATIC_KMODS = $(SRCROOT)/kmods.a
31 ifeq ($(BUILD_JSON_COMPILATION_DATABASE),1)
33 $(_v)$(CAT) > $(OBJPATH)/compile_commands.json < /dev/null
37 # Rules for the highly parallel "build" phase, where each build configuration
38 # writes into their own $(TARGET) independent of other build configs
40 # There are 3 primary build outputs:
41 # 1) $(KERNEL_FILE_NAME).unstripped (raw linked kernel, unstripped)
42 # 2) $(KERNEL_FILE_NAME) (stripped kernel, with optional CTF data)
43 # 3) $(KERNEL_FILE_NAME).dSYM (dSYM)
46 do_build_all:: do_build_kernel
48 .PHONY: do_build_kernel
50 do_build_kernel: $(TARGET)/$(KERNEL_FILE_NAME) $(TARGET)/$(KERNEL_FILE_NAME).unstripped
53 ifeq ($(BUILD_DSYM),1)
54 do_build_all:: do_build_kernel_dSYM
57 .PHONY: do_build_kernel_dSYM
59 do_build_kernel_dSYM: $(TARGET)/$(KERNEL_FILE_NAME).dSYM
63 $(_v)$(REPLACECONTENTS) $@ $(LD) $(LDFLAGS_KERNEL) $(LD_KERNEL_LIBS)
65 $(_v)$(REPLACECONTENTS) $@ $(KCC) $(CFLAGS) $(INCFLAGS)
67 $(TARGET)/$(KERNEL_FILE_NAME): $(TARGET)/$(KERNEL_FILE_NAME).unstripped
69 $(_v)$(STRIP) $(STRIP_FLAGS) $< -o $@
71 ifeq ($(DO_CTFMERGE),1)
73 $(_v)$(FIND) $(TARGET)/ -name \*.ctf -size +0 | \
74 $(XARGS) $(CTFMERGE) -l xnu -o $@ -Z $@.ctfdata || true
76 $(_v)if [ -s $@.ctfdata ]; then \
77 echo CTFINSERT $(@F); \
78 $(CTFINSERT) $@ $(ARCH_FLAGS_$(CURRENT_ARCH_CONFIG)) \
81 $(_v)$(LN) $(call function_convert_build_config_to_objdir,$(CURRENT_BUILD_CONFIG))/$(KERNEL_FILE_NAME) $(OBJROOT)/$(KERNEL_FILE_NAME)
83 $(TARGET)/$(KERNEL_FILE_NAME).dSYM: $(TARGET)/$(KERNEL_FILE_NAME).unstripped
84 $(_v)echo DSYMUTIL $(@F)
85 $(_v)$(DSYMUTIL) $(DSYMUTIL_FLAGS) $< -o $@
86 $(_v)$(MV) $@/$(DSYMDWARFDIR)/$(KERNEL_FILE_NAME).unstripped $@/$(DSYMDWARFDIR)/$(KERNEL_FILE_NAME)
89 $(TARGET)/$(KERNEL_FILE_NAME).unstripped: $(addprefix $(TARGET)/,$(foreach component,$(COMPONENT_LIST),$(component)/$(CURRENT_KERNEL_CONFIG)/$(component).filelist)) lastkerneldataconst.o lastkernelconstructor.o $(SRCROOT)/config/version.c $(SRCROOT)/config/MasterVersion .LDFLAGS $(filter %/MakeInc.kernel,$(MAKEFILE_LIST))
90 $(_v)${MAKE} -f $(firstword $(MAKEFILE_LIST)) version.o
92 $(_v)$(CAT) $(filter %.filelist,$+) < /dev/null > link.filelist
93 $(_v)$(LD) $(LDFLAGS_KERNEL) -filelist link.filelist version.o $(filter %.o,$+) -o $@ $(LD_KERNEL_LIBS)
96 version.o: .CFLAGS $(filter %/MakeInc.kernel,$(MAKEFILE_LIST))
97 version.o: $(OBJPATH)/version.c
103 # Always recreate version.sh
104 $(OBJPATH)/version.c: $(SRCROOT)/config/version.c $(NEWVERS) $(SRCROOT)/config/MasterVersion ALWAYS
106 $(_v)$(NEWVERS) $(OBJPATH)/version.c > /dev/null;
108 -include lastkerneldataconst.d
109 lastkerneldataconst.o: .CFLAGS $(filter %/MakeInc.kernel,$(MAKEFILE_LIST))
110 lastkerneldataconst.o: $(SRCROOT)/libsa/lastkerneldataconst.c
116 lastkernelconstructor.o_CFLAGS_RM = -fprofile-instr-generate
117 # the LAST segment is mapped read-only on arm, so if we include llvm profiling
118 # here it will segfault the kernel. (see arm_vm_init.c) We don't currently have
119 # a way of retrieving these counters from LAST anyway, so there's no harm in just
122 LAST_FILES=lastkernelconstructor.o
123 -include lastkernelconstructor.d
124 lastkernelconstructor.o: .CFLAGS $(filter %/MakeInc.kernel,$(MAKEFILE_LIST))
125 lastkernelconstructor.o: $(SRCROOT)/libsa/lastkernelconstructor.c
127 ${C_RULE_1A}$< $(CFLAGS_NOLTO_FLAG)
131 $(_v)for last_file in ${LAST_FILES}; \
133 $(SEG_HACK) -s __DATA -n __LAST -o $${last_file}__ $${last_file} || exit 1; \
134 mv $${last_file}__ $${last_file} || exit 1; \
138 # Install rules. Each build config is classified as "primary" (the first
139 # config for an architecture) or "non-primary". Primary build configs
140 # have the semantic of competing to *combine* single-architecture
141 # files into a multi-architecture output in the DSTROOT, like
142 # $(DSTROOT)/$(KERNEL_FILE_NAME), and consequently each primary build config
143 # has its install target run serially with respect to other primary
144 # build configs. Non-primary build configs will never compete for
145 # files in the DSTROOT or SYMROOT, and can be installed in parallel
146 # with other non-primary configs (and even primary configs)
149 do_build_install_primary:: do_install_machine_specific_kernel
150 ifeq ($(BUILD_DSYM),1)
151 do_build_install_primary:: do_install_machine_specific_kernel_dSYM
154 do_build_install_non_primary:: do_install_machine_specific_kernel
155 ifeq ($(BUILD_DSYM),1)
156 do_build_install_non_primary:: do_install_machine_specific_kernel_dSYM
159 ifeq ($(BUILD_DSYM),1)
160 ifeq ($(INSTALL_KERNEL_SYM_TO_KDK),1)
161 do_build_install_primary:: do_install_machine_specific_KDK_dSYM
162 do_build_install_non_primary:: do_install_machine_specific_KDK_dSYM
166 ifeq ($(INSTALL_XNU_DEBUG_FILES),1)
167 do_build_install_primary:: do_install_xnu_debug_files
170 .PHONY: do_install_xnu_debug_files
172 do_install_xnu_debug_files: $(DSTROOT)/$(DEVELOPER_EXTRAS_DIR)/README.DEBUG-kernel.txt
176 # If the timestamp indicates the DSTROOT kernel is out of
177 # date, start over. Normal dependencies don't work because we can have
178 # ( BUILDA, BUILDB, INSTALLB, INSTALLA ) in which case at INSTALLA time
179 # the timestamps would $(DSTROOT)/$(KERNEL_FILE_NAME) is not out of date compared
180 # to BUILDA. So we maintain a separate file at the time make(1)
181 # was run and use it to determine what actions to take
184 $(DSTROOT)/$(INSTALL_KERNEL_DIR)/$(KERNEL_FILE_NAME): $(TARGET)/$(KERNEL_FILE_NAME) ALWAYS
185 $(_v)$(MKDIR) $(dir $@)
186 $(_v)if [ $(OBJROOT)/.mach_kernel.timestamp -nt $@ ]; then \
187 echo INSTALL $(@F) "($(CURRENT_ARCH_CONFIG_LC) $(CURRENT_MACHINE_CONFIG_LC))"; \
188 $(INSTALL) $(EXEC_INSTALL_FLAGS) $< $@; \
191 echo INSTALL $(@F) "($(CURRENT_ARCH_CONFIG_LC) $(CURRENT_MACHINE_CONFIG_LC))"; \
192 $(LIPO) -create $@ $< -output $@; \
197 $(SYMROOT)/$(KERNEL_FILE_NAME): $(TARGET)/$(KERNEL_FILE_NAME).unstripped ALWAYS
198 $(_v)$(MKDIR) $(dir $@)
199 $(_v)if [ $(OBJROOT)/.mach_kernel.timestamp -nt $@ ]; then \
200 echo INSTALLSYM $(@F) "($(CURRENT_ARCH_CONFIG_LC))"; \
201 $(INSTALL) $(EXEC_INSTALL_FLAGS) $< $@; \
204 echo INSTALLSYM $(@F) "($(CURRENT_ARCH_CONFIG_LC))"; \
205 $(LIPO) -create $@ $< -output $@; \
210 $(SYMROOT)/$(KERNEL_FILE_NAME).dSYM/$(DSYMLLDBMACROSDIR)/lldbmacros $(DSTROOT)/$(INSTALL_KERNEL_SYM_DIR)/$(KERNEL_FILE_NAME).dSYM/$(DSYMLLDBMACROSDIR)/lldbmacros: $(TARGET)/$(KERNEL_FILE_NAME).dSYM/$(DSYMLLDBMACROSDIR)/lldbmacros
211 $(_v)$(MKDIR) $(dir $@)
212 @echo INSTALLMACROS $(@F) "($(CURRENT_ARCH_CONFIG_LC))"
213 $(_v)$(CP) -r $< $(dir $@)
216 $(SYMROOT)/$(KERNEL_FILE_NAME).dSYM/$(DSYMLLDBMACROSDIR)/$(KERNEL_LLDBBOOTSTRAP_NAME) $(DSTROOT)/$(INSTALL_KERNEL_SYM_DIR)/$(KERNEL_FILE_NAME).dSYM/$(DSYMLLDBMACROSDIR)/$(KERNEL_LLDBBOOTSTRAP_NAME): $(TARGET)/$(KERNEL_FILE_NAME).dSYM/$(DSYMLLDBMACROSDIR)/$(KERNEL_LLDBBOOTSTRAP_NAME)
217 $(_v)$(MKDIR) $(dir $@)
218 @echo INSTALLMACROS $(@F) "($(CURRENT_ARCH_CONFIG_LC))"
219 $(_v)$(INSTALL) $(INSTALL_FLAGS) $< $@
221 $(DSTROOT)/$(DEVELOPER_EXTRAS_DIR)/README.DEBUG-kernel.txt: $(SRCROOT)/config/README.DEBUG-kernel.txt
222 $(_v)$(MKDIR) $(dir $@)
224 $(_v)$(INSTALL) $(INSTALL_FLAGS) $< $@
226 $(SYMROOT)/$(KERNEL_FILE_NAME).dSYM/$(DSYMINFODIR)/Info.plist $(DSTROOT)/$(INSTALL_KERNEL_SYM_DIR)/$(KERNEL_FILE_NAME).dSYM/$(DSYMINFODIR)/Info.plist: $(TARGET)/$(KERNEL_FILE_NAME).dSYM/$(DSYMINFODIR)/Info.plist
227 $(_v)$(MKDIR) $(dir $@)
228 @echo INSTALLSYM dSYM $(@F) "($(CURRENT_ARCH_CONFIG_LC))"
229 $(_v)$(INSTALL) $(INSTALL_FLAGS) $< $@
231 $(SYMROOT)/$(KERNEL_FILE_NAME).dSYM/$(DSYMDWARFDIR)/$(KERNEL_FILE_NAME) $(DSTROOT)/$(INSTALL_KERNEL_SYM_DIR)/$(KERNEL_FILE_NAME).dSYM/$(DSYMDWARFDIR)/$(KERNEL_FILE_NAME): $(TARGET)/$(KERNEL_FILE_NAME).dSYM/$(DSYMDWARFDIR)/$(KERNEL_FILE_NAME) ALWAYS
232 $(_v)$(MKDIR) $(dir $@)
233 $(_v)if [ $(OBJROOT)/.mach_kernel.timestamp -nt $@ ]; then \
234 echo INSTALLSYM dSYM $(@F).dSYM "($(CURRENT_ARCH_CONFIG_LC))"; \
235 $(INSTALL) $(EXEC_INSTALL_FLAGS) $< $@; \
238 echo INSTALLSYM dSYM $(@F).dSYM "($(CURRENT_ARCH_CONFIG_LC))"; \
239 $(LIPO) -create $@ $< -output $@; \
244 .PHONY: do_install_machine_specific_kernel do_install_machine_specific_kernel_dSYM
246 do_install_machine_specific_kernel: $(DSTROOT)/$(INSTALL_KERNEL_DIR)/$(KERNEL_FILE_NAME) \
247 $(SYMROOT)/$(KERNEL_FILE_NAME)
250 do_install_machine_specific_kernel_dSYM: \
251 $(SYMROOT)/$(KERNEL_FILE_NAME).dSYM/$(DSYMINFODIR)/Info.plist \
252 $(SYMROOT)/$(KERNEL_FILE_NAME).dSYM/$(DSYMLLDBMACROSDIR)/lldbmacros \
253 $(SYMROOT)/$(KERNEL_FILE_NAME).dSYM/$(DSYMLLDBMACROSDIR)/$(KERNEL_LLDBBOOTSTRAP_NAME) \
254 $(SYMROOT)/$(KERNEL_FILE_NAME).dSYM/$(DSYMDWARFDIR)/$(KERNEL_FILE_NAME)
257 .PHONY: do_install_machine_specific_KDK_dSYM
259 do_install_machine_specific_KDK_dSYM: \
260 $(DSTROOT)/$(INSTALL_KERNEL_SYM_DIR)/$(KERNEL_FILE_NAME).dSYM/$(DSYMINFODIR)/Info.plist \
261 $(DSTROOT)/$(INSTALL_KERNEL_SYM_DIR)/$(KERNEL_FILE_NAME).dSYM/$(DSYMLLDBMACROSDIR)/lldbmacros \
262 $(DSTROOT)/$(INSTALL_KERNEL_SYM_DIR)/$(KERNEL_FILE_NAME).dSYM/$(DSYMLLDBMACROSDIR)/$(KERNEL_LLDBBOOTSTRAP_NAME) \
263 $(DSTROOT)/$(INSTALL_KERNEL_SYM_DIR)/$(KERNEL_FILE_NAME).dSYM/$(DSYMDWARFDIR)/$(KERNEL_FILE_NAME)
266 # The $(RM) is needed so that the $(LN) doesn't dereference an existing
267 # symlink during incremental builds and create a new symlink inside
268 # the target of the existing symlink
269 do_installhdrs_mi:: $(DSTROOT)/$(KRESDIR)/Info.plist
270 $(_v)$(MKDIR) $(DSTROOT)/$(KINCFRAME)
271 $(_v)$(MKDIR) $(DSTROOT)/$(KPINCDIR)
272 $(_v)$(MKDIR) $(DSTROOT)/$(KRESDIR)
273 $(_v)$(RM) $(DSTROOT)/$(KINCFRAME)/Versions/Current
274 $(_v)$(LN) $(KINCVERS) $(DSTROOT)/$(KINCFRAME)/Versions/Current
275 $(_v)$(RM) $(DSTROOT)/$(KINCFRAME)/Headers
276 $(_v)$(LN) Versions/Current/Headers \
277 $(DSTROOT)/$(KINCFRAME)/Headers
278 $(_v)$(RM) $(DSTROOT)/$(KINCFRAME)/PrivateHeaders
279 $(_v)$(LN) Versions/Current/PrivateHeaders \
280 $(DSTROOT)/$(KINCFRAME)/PrivateHeaders
281 $(_v)$(RM) $(DSTROOT)/$(KINCFRAME)/Resources
282 $(_v)$(LN) Versions/Current/Resources \
283 $(DSTROOT)/$(KINCFRAME)/Resources
285 $(DSTROOT)/$(KRESDIR)/Info.plist: $(SOURCE)/EXTERNAL_HEADERS/Info.plist
286 $(_v)$(MKDIR) $(DSTROOT)/$(KRESDIR)
287 $(_v)$(INSTALL) $(DATA_INSTALL_FLAGS) $< $@
288 $(_v)$(NEWVERS) $@ $(_vstdout)
289 ifeq ($(USE_BINARY_PLIST),1)
290 $(_v)$(PLUTIL) -convert binary1 -o $@ $@