]> git.saurik.com Git - apple/xnu.git/blame - makedefs/MakeInc.kernel
xnu-3789.41.3.tar.gz
[apple/xnu.git] / makedefs / MakeInc.kernel
CommitLineData
39236c6e
A
1# -*- mode: makefile;-*-
2#
39037602 3# Copyright (C) 1999-2016 Apple Inc. All rights reserved.
39236c6e
A
4#
5# MakeInc.kernel augments the single-architecture
6# recursive build system with rules specific
7# to assembling and linking a kernel.
8#
9
10#
11# Validate configuration options
12#
13ifeq ($(filter $(CURRENT_ARCH_CONFIG),$(SUPPORTED_ARCH_CONFIGS)),)
14$(error Unsupported CURRENT_ARCH_CONFIG $(CURRENT_ARCH_CONFIG))
15endif
16
17ifeq ($(filter $(CURRENT_KERNEL_CONFIG),$(SUPPORTED_KERNEL_CONFIGS)),)
18$(error Unsupported CURRENT_KERNEL_CONFIG $(CURRENT_KERNEL_CONFIG))
19endif
20
21ifeq ($(filter $(CURRENT_MACHINE_CONFIG),$(SUPPORTED_$(CURRENT_ARCH_CONFIG)_MACHINE_CONFIGS)),)
22$(error Unsupported CURRENT_MACHINE_CONFIG $(CURRENT_MACHINE_CONFIG))
23endif
24
25ifeq ($(filter $(PLATFORM),$(SUPPORTED_PLATFORMS)),)
26$(error Unsupported PLATFORM $(PLATFORM))
27endif
28
29STATIC_KMODS = $(SRCROOT)/kmods.a
30
3e170ce0
A
31ifeq ($(BUILD_JSON_COMPILATION_DATABASE),1)
32do_build_setup::
33 $(_v)$(CAT) > $(OBJPATH)/compile_commands.json < /dev/null
34endif
35
39236c6e
A
36#
37# Rules for the highly parallel "build" phase, where each build configuration
38# writes into their own $(TARGET) independent of other build configs
39#
fe8ab488
A
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)
44#
39236c6e 45
fe8ab488 46do_build_all:: do_build_kernel
39236c6e 47
fe8ab488 48.PHONY: do_build_kernel
39236c6e 49
fe8ab488
A
50do_build_kernel: $(TARGET)/$(KERNEL_FILE_NAME) $(TARGET)/$(KERNEL_FILE_NAME).unstripped
51 @:
39236c6e
A
52
53ifeq ($(BUILD_DSYM),1)
fe8ab488 54do_build_all:: do_build_kernel_dSYM
39236c6e
A
55endif
56
fe8ab488 57.PHONY: do_build_kernel_dSYM
39236c6e 58
39037602 59do_build_kernel_dSYM: $(TARGET)/$(KERNEL_FILE_NAME).dSYM
39236c6e
A
60 @:
61
fe8ab488
A
62.LDFLAGS: ALWAYS
63 $(_v)$(REPLACECONTENTS) $@ $(LD) $(LDFLAGS_KERNEL) $(LD_KERNEL_LIBS)
64.CFLAGS: ALWAYS
65 $(_v)$(REPLACECONTENTS) $@ $(KCC) $(CFLAGS) $(INCFLAGS)
66
67$(TARGET)/$(KERNEL_FILE_NAME): $(TARGET)/$(KERNEL_FILE_NAME).unstripped
39037602 68 @echo "$(ColorH)STRIP$(Color0) $(ColorLF)$(@F)$(Color0)"
39236c6e
A
69 $(_v)$(STRIP) $(STRIP_FLAGS) $< -o $@
70 $(_v)$(RM) $@.ctfdata
71ifeq ($(DO_CTFMERGE),1)
39037602
A
72 @echo "$(ColorH)CTFMERGE$(Color0) $(ColorLF)$(@F)$(Color0)"
73 $(_v)$(FIND) $(TARGET)/ -name \*.ctf -size +0 | \
39236c6e
A
74 $(XARGS) $(CTFMERGE) -l xnu -o $@ -Z $@.ctfdata || true
75endif
76 $(_v)if [ -s $@.ctfdata ]; then \
39037602
A
77 echo "$(ColorH)CTFINSERT$(Color0) $(ColorLF)$(@F)$(Color0)"; \
78 $(CTFINSERT) $@ $(ARCH_FLAGS_$(CURRENT_ARCH_CONFIG)) \
39236c6e
A
79 $@.ctfdata -o $@; \
80 fi;
fe8ab488 81 $(_v)$(LN) $(call function_convert_build_config_to_objdir,$(CURRENT_BUILD_CONFIG))/$(KERNEL_FILE_NAME) $(OBJROOT)/$(KERNEL_FILE_NAME)
39236c6e 82
fe8ab488 83$(TARGET)/$(KERNEL_FILE_NAME).dSYM: $(TARGET)/$(KERNEL_FILE_NAME).unstripped
39037602 84 $(_v)echo "$(ColorH)DSYMUTIL$(Color0) $(ColorLF)$(@F)$(Color0)"
39236c6e 85 $(_v)$(DSYMUTIL) $(DSYMUTIL_FLAGS) $< -o $@
fe8ab488 86 $(_v)$(MV) $@/$(DSYMDWARFDIR)/$(KERNEL_FILE_NAME).unstripped $@/$(DSYMDWARFDIR)/$(KERNEL_FILE_NAME)
39236c6e
A
87 $(_v)$(TOUCH) $@
88
3e170ce0 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))
39236c6e 90 $(_v)${MAKE} -f $(firstword $(MAKEFILE_LIST)) version.o
39037602 91 @echo "$(ColorL)LD$(Color0) $(ColorLF)$(@F)$(Color0)"
39236c6e 92 $(_v)$(CAT) $(filter %.filelist,$+) < /dev/null > link.filelist
fe8ab488 93 $(_v)$(LD) $(LDFLAGS_KERNEL) -filelist link.filelist version.o $(filter %.o,$+) -o $@ $(LD_KERNEL_LIBS)
39236c6e 94
fe8ab488
A
95-include version.d
96version.o: .CFLAGS $(filter %/MakeInc.kernel,$(MAKEFILE_LIST))
39236c6e 97version.o: $(OBJPATH)/version.c
fe8ab488 98 ${C_RULE_0}
39236c6e
A
99 ${C_RULE_1A}$<
100 ${C_RULE_2}
101 ${C_RULE_4}
102
103# Always recreate version.sh
104$(OBJPATH)/version.c: $(SRCROOT)/config/version.c $(NEWVERS) $(SRCROOT)/config/MasterVersion ALWAYS
105 $(_v)$(CP) $< $@
106 $(_v)$(NEWVERS) $(OBJPATH)/version.c > /dev/null;
107
3e170ce0
A
108-include lastkerneldataconst.d
109lastkerneldataconst.o: .CFLAGS $(filter %/MakeInc.kernel,$(MAKEFILE_LIST))
110lastkerneldataconst.o: $(SRCROOT)/libsa/lastkerneldataconst.c
111 ${C_RULE_0}
112 ${C_RULE_1A}$<
113 ${C_RULE_2}
114
115
116lastkernelconstructor.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
120# disabling them.
121
122LAST_FILES=lastkernelconstructor.o
fe8ab488
A
123-include lastkernelconstructor.d
124lastkernelconstructor.o: .CFLAGS $(filter %/MakeInc.kernel,$(MAKEFILE_LIST))
39236c6e 125lastkernelconstructor.o: $(SRCROOT)/libsa/lastkernelconstructor.c
fe8ab488 126 ${C_RULE_0}
39236c6e
A
127 ${C_RULE_1A}$< $(CFLAGS_NOLTO_FLAG)
128 ${C_RULE_2}
129 ${C_RULE_3}
130 ${C_RULE_4}
3e170ce0 131 $(_v)for last_file in ${LAST_FILES}; \
39037602 132 do \
3e170ce0
A
133 $(SEG_HACK) -s __DATA -n __LAST -o $${last_file}__ $${last_file} || exit 1; \
134 mv $${last_file}__ $${last_file} || exit 1; \
135 done
39236c6e 136
39236c6e
A
137#
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
fe8ab488 142# $(DSTROOT)/$(KERNEL_FILE_NAME), and consequently each primary build config
39236c6e
A
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)
147#
148
39236c6e
A
149do_build_install_primary:: do_install_machine_specific_kernel
150ifeq ($(BUILD_DSYM),1)
151do_build_install_primary:: do_install_machine_specific_kernel_dSYM
152endif
39236c6e
A
153
154do_build_install_non_primary:: do_install_machine_specific_kernel
155ifeq ($(BUILD_DSYM),1)
156do_build_install_non_primary:: do_install_machine_specific_kernel_dSYM
157endif
158
159ifeq ($(BUILD_DSYM),1)
160ifeq ($(INSTALL_KERNEL_SYM_TO_KDK),1)
161do_build_install_primary:: do_install_machine_specific_KDK_dSYM
162do_build_install_non_primary:: do_install_machine_specific_KDK_dSYM
163endif
164endif
165
166ifeq ($(INSTALL_XNU_DEBUG_FILES),1)
167do_build_install_primary:: do_install_xnu_debug_files
39236c6e
A
168endif
169
fe8ab488 170.PHONY: do_install_xnu_debug_files
39236c6e
A
171
172do_install_xnu_debug_files: $(DSTROOT)/$(DEVELOPER_EXTRAS_DIR)/README.DEBUG-kernel.txt
173 @:
174
39236c6e
A
175#
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
fe8ab488 179# the timestamps would $(DSTROOT)/$(KERNEL_FILE_NAME) is not out of date compared
39236c6e
A
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
182#
183
fe8ab488 184$(DSTROOT)/$(INSTALL_KERNEL_DIR)/$(KERNEL_FILE_NAME): $(TARGET)/$(KERNEL_FILE_NAME) ALWAYS
39236c6e 185 $(_v)$(MKDIR) $(dir $@)
fe8ab488 186 $(_v)if [ $(OBJROOT)/.mach_kernel.timestamp -nt $@ ]; then \
39037602 187 echo "$(ColorH)INSTALL$(Color0) $(ColorF)$(@F)$(Color0) \"($(ColorLF)$(CURRENT_ARCH_CONFIG_LC)$(Color0) $(ColorLF)$(CURRENT_MACHINE_CONFIG_LC)$(Color0))\""; \
fe8ab488
A
188 $(INSTALL) $(EXEC_INSTALL_FLAGS) $< $@; \
189 cmdstatus=$$?; \
190 else \
39037602 191 echo "$(ColorH)INSTALL$(Color0) $(ColorF)$(@F)$(Color0) \"($(ColorLF)$(CURRENT_ARCH_CONFIG_LC)$(Color0) $(ColorLF)$(CURRENT_MACHINE_CONFIG_LC)$(Color0))\""; \
fe8ab488
A
192 $(LIPO) -create $@ $< -output $@; \
193 cmdstatus=$$?; \
194 fi; \
39236c6e
A
195 exit $$cmdstatus
196
fe8ab488 197$(SYMROOT)/$(KERNEL_FILE_NAME): $(TARGET)/$(KERNEL_FILE_NAME).unstripped ALWAYS
39236c6e
A
198 $(_v)$(MKDIR) $(dir $@)
199 $(_v)if [ $(OBJROOT)/.mach_kernel.timestamp -nt $@ ]; then \
39037602 200 echo "$(ColorH)INSTALLSYM$(Color0) $(ColorF)$(@F)$(Color0) \"($(ColorLF)$(CURRENT_ARCH_CONFIG_LC)$(Color0))\""; \
39236c6e
A
201 $(INSTALL) $(EXEC_INSTALL_FLAGS) $< $@; \
202 cmdstatus=$$?; \
203 else \
39037602 204 echo "$(ColorH)INSTALLSYM$(Color0) $(ColorF)$(@F)$(Color0) \"($(ColorLF)$(CURRENT_ARCH_CONFIG_LC)$(Color0))\""; \
39236c6e
A
205 $(LIPO) -create $@ $< -output $@; \
206 cmdstatus=$$?; \
207 fi; \
208 exit $$cmdstatus
209
fe8ab488 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
39236c6e 211 $(_v)$(MKDIR) $(dir $@)
39037602 212 @echo "$(ColorH)INSTALLMACROS$(Color0) $(ColorF)$(@F)$(Color0) \"($(ColorLF)$(CURRENT_ARCH_CONFIG_LC)$(Color0))\""
39236c6e
A
213 $(_v)$(CP) -r $< $(dir $@)
214 $(_v)$(TOUCH) $@
215
fe8ab488 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)
39236c6e 217 $(_v)$(MKDIR) $(dir $@)
39037602 218 @echo "$(ColorH)INSTALLMACROS$(Color0) $(ColorF)$(@F)$(Color0) \"($(ColorLF)$(CURRENT_ARCH_CONFIG_LC)$(Color0))\""
39236c6e
A
219 $(_v)$(INSTALL) $(INSTALL_FLAGS) $< $@
220
221$(DSTROOT)/$(DEVELOPER_EXTRAS_DIR)/README.DEBUG-kernel.txt: $(SRCROOT)/config/README.DEBUG-kernel.txt
222 $(_v)$(MKDIR) $(dir $@)
39037602 223 @echo "$(ColorH)INSTALL$(Color0) $(ColorF)$(@F)$(Color0)"
39236c6e
A
224 $(_v)$(INSTALL) $(INSTALL_FLAGS) $< $@
225
fe8ab488 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
39236c6e 227 $(_v)$(MKDIR) $(dir $@)
39037602 228 @echo "$(ColorH)INSTALLSYM$(Color0) $(ColorL)dSYM$(Color0) $(ColorF)$(@F)$(Color0) \"($(ColorLF)$(CURRENT_ARCH_CONFIG_LC)$(Color0))\""
39236c6e
A
229 $(_v)$(INSTALL) $(INSTALL_FLAGS) $< $@
230
fe8ab488 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
39236c6e
A
232 $(_v)$(MKDIR) $(dir $@)
233 $(_v)if [ $(OBJROOT)/.mach_kernel.timestamp -nt $@ ]; then \
39037602
A
234 echo "$(ColorH)INSTALLSYM$(Color0) $(ColorL)dSYM$(Color0) $(ColorF)$(@F).dSYM$(ColorF) \"($(ColorLF)$(CURRENT_ARCH_CONFIG_LC)$(Color0))\""; \
235 $(INSTALL) $(EXEC_INSTALL_FLAGS) $< $@; \
236 cmdstatus=$$?; \
39236c6e 237 else \
39037602
A
238 echo "$(ColorH)INSTALLSYM$(Color0) $(ColorL)dSYM$(Color0) $(ColorF)$(@F).dSYM$(ColorF) \"($(ColorLF)$(CURRENT_ARCH_CONFIG_LC)$(Color0))\""; \
239 $(LIPO) -create $@ $< -output $@; \
240 cmdstatus=$$?; \
39236c6e
A
241 fi; \
242 exit $$cmdstatus
243
244.PHONY: do_install_machine_specific_kernel do_install_machine_specific_kernel_dSYM
245
fe8ab488
A
246do_install_machine_specific_kernel: $(DSTROOT)/$(INSTALL_KERNEL_DIR)/$(KERNEL_FILE_NAME) \
247 $(SYMROOT)/$(KERNEL_FILE_NAME)
39236c6e
A
248 @:
249
250do_install_machine_specific_kernel_dSYM: \
fe8ab488
A
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)
39236c6e
A
255 @:
256
257.PHONY: do_install_machine_specific_KDK_dSYM
258
259do_install_machine_specific_KDK_dSYM: \
fe8ab488
A
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)
39236c6e
A
264 @:
265
39236c6e
A
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
fe8ab488 269do_installhdrs_mi:: $(DSTROOT)/$(KRESDIR)/Info.plist
39236c6e
A
270 $(_v)$(MKDIR) $(DSTROOT)/$(KINCFRAME)
271 $(_v)$(MKDIR) $(DSTROOT)/$(KPINCDIR)
fe8ab488 272 $(_v)$(MKDIR) $(DSTROOT)/$(KRESDIR)
39236c6e
A
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
fe8ab488
A
281 $(_v)$(RM) $(DSTROOT)/$(KINCFRAME)/Resources
282 $(_v)$(LN) Versions/Current/Resources \
283 $(DSTROOT)/$(KINCFRAME)/Resources
39236c6e
A
284
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)
289ifeq ($(USE_BINARY_PLIST),1)
290 $(_v)$(PLUTIL) -convert binary1 -o $@ $@
291endif
292
39037602
A
293$(DSTROOT)/$(INSTALL_KERNEL_DIR)/$(ALIAS_FILE_NAME): ALWAYS
294 $(_v)echo "$(ColorH)ALIAS$(Color0) $(ColorF)$(@F)$(Color0) \"($(ColorLF)$(CURRENT_ARCH_CONFIG_LC)$(Color0) $(ColorLF)$(CURRENT_MACHINE_CONFIG_LC)$(Color0) $(ColorLF)$(CURRENT_ALIAS_MACHINE_CONFIG_LC)$(Color0))\""
295 $(_v)$(INSTALL) $(EXEC_INSTALL_FLAGS) $(DSTROOT)/$(INSTALL_KERNEL_DIR)/$(KERNEL_FILE_NAME) $@
296
297install_alias: $(DSTROOT)/$(INSTALL_KERNEL_DIR)/$(ALIAS_FILE_NAME)
298
39236c6e
A
299print_exports:
300 $(_v)printenv | sort