]> git.saurik.com Git - apple/xnu.git/blob - makedefs/MakeInc.kernel
xnu-3247.1.106.tar.gz
[apple/xnu.git] / makedefs / MakeInc.kernel
1 # -*- mode: makefile;-*-
2 #
3 # Copyright (C) 1999-2012 Apple Inc. All rights reserved.
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 #
13 ifeq ($(filter $(CURRENT_ARCH_CONFIG),$(SUPPORTED_ARCH_CONFIGS)),)
14 $(error Unsupported CURRENT_ARCH_CONFIG $(CURRENT_ARCH_CONFIG))
15 endif
16
17 ifeq ($(filter $(CURRENT_KERNEL_CONFIG),$(SUPPORTED_KERNEL_CONFIGS)),)
18 $(error Unsupported CURRENT_KERNEL_CONFIG $(CURRENT_KERNEL_CONFIG))
19 endif
20
21 ifeq ($(filter $(CURRENT_MACHINE_CONFIG),$(SUPPORTED_$(CURRENT_ARCH_CONFIG)_MACHINE_CONFIGS)),)
22 $(error Unsupported CURRENT_MACHINE_CONFIG $(CURRENT_MACHINE_CONFIG))
23 endif
24
25 ifeq ($(filter $(PLATFORM),$(SUPPORTED_PLATFORMS)),)
26 $(error Unsupported PLATFORM $(PLATFORM))
27 endif
28
29 STATIC_KMODS = $(SRCROOT)/kmods.a
30
31 ifeq ($(BUILD_JSON_COMPILATION_DATABASE),1)
32 do_build_setup::
33 $(_v)$(CAT) > $(OBJPATH)/compile_commands.json < /dev/null
34 endif
35
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 #
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 #
45
46 do_build_all:: do_build_kernel
47
48 .PHONY: do_build_kernel
49
50 do_build_kernel: $(TARGET)/$(KERNEL_FILE_NAME) $(TARGET)/$(KERNEL_FILE_NAME).unstripped
51 @:
52
53 ifeq ($(BUILD_DSYM),1)
54 do_build_all:: do_build_kernel_dSYM
55 endif
56
57 .PHONY: do_build_kernel_dSYM
58
59 do_build_kernel_dSYM: $(TARGET)/$(KERNEL_FILE_NAME).dSYM
60 @:
61
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
68 @echo STRIP $(@F)
69 $(_v)$(STRIP) $(STRIP_FLAGS) $< -o $@
70 $(_v)$(RM) $@.ctfdata
71 ifeq ($(DO_CTFMERGE),1)
72 @echo CTFMERGE $(@F)
73 $(_v)$(FIND) $(TARGET)/ -name \*.ctf -size +0 | \
74 $(XARGS) $(CTFMERGE) -l xnu -o $@ -Z $@.ctfdata || true
75 endif
76 $(_v)if [ -s $@.ctfdata ]; then \
77 echo CTFINSERT $(@F); \
78 $(CTFINSERT) $@ $(ARCH_FLAGS_$(CURRENT_ARCH_CONFIG)) \
79 $@.ctfdata -o $@; \
80 fi;
81 $(_v)$(LN) $(call function_convert_build_config_to_objdir,$(CURRENT_BUILD_CONFIG))/$(KERNEL_FILE_NAME) $(OBJROOT)/$(KERNEL_FILE_NAME)
82
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)
87 $(_v)$(TOUCH) $@
88
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
91 @echo LD $(@F)
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)
94
95 -include version.d
96 version.o: .CFLAGS $(filter %/MakeInc.kernel,$(MAKEFILE_LIST))
97 version.o: $(OBJPATH)/version.c
98 ${C_RULE_0}
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
108 -include lastkerneldataconst.d
109 lastkerneldataconst.o: .CFLAGS $(filter %/MakeInc.kernel,$(MAKEFILE_LIST))
110 lastkerneldataconst.o: $(SRCROOT)/libsa/lastkerneldataconst.c
111 ${C_RULE_0}
112 ${C_RULE_1A}$<
113 ${C_RULE_2}
114
115
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
120 # disabling them.
121
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
126 ${C_RULE_0}
127 ${C_RULE_1A}$< $(CFLAGS_NOLTO_FLAG)
128 ${C_RULE_2}
129 ${C_RULE_3}
130 ${C_RULE_4}
131 $(_v)for last_file in ${LAST_FILES}; \
132 do \
133 $(SEG_HACK) -s __DATA -n __LAST -o $${last_file}__ $${last_file} || exit 1; \
134 mv $${last_file}__ $${last_file} || exit 1; \
135 done
136
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
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)
147 #
148
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
152 endif
153
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
157 endif
158
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
163 endif
164 endif
165
166 ifeq ($(INSTALL_XNU_DEBUG_FILES),1)
167 do_build_install_primary:: do_install_xnu_debug_files
168 endif
169
170 .PHONY: do_install_xnu_debug_files
171
172 do_install_xnu_debug_files: $(DSTROOT)/$(DEVELOPER_EXTRAS_DIR)/README.DEBUG-kernel.txt
173 @:
174
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
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
182 #
183
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) $< $@; \
189 cmdstatus=$$?; \
190 else \
191 echo INSTALL $(@F) "($(CURRENT_ARCH_CONFIG_LC) $(CURRENT_MACHINE_CONFIG_LC))"; \
192 $(LIPO) -create $@ $< -output $@; \
193 cmdstatus=$$?; \
194 fi; \
195 exit $$cmdstatus
196
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) $< $@; \
202 cmdstatus=$$?; \
203 else \
204 echo INSTALLSYM $(@F) "($(CURRENT_ARCH_CONFIG_LC))"; \
205 $(LIPO) -create $@ $< -output $@; \
206 cmdstatus=$$?; \
207 fi; \
208 exit $$cmdstatus
209
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 $@)
214 $(_v)$(TOUCH) $@
215
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) $< $@
220
221 $(DSTROOT)/$(DEVELOPER_EXTRAS_DIR)/README.DEBUG-kernel.txt: $(SRCROOT)/config/README.DEBUG-kernel.txt
222 $(_v)$(MKDIR) $(dir $@)
223 @echo INSTALL $(@F)
224 $(_v)$(INSTALL) $(INSTALL_FLAGS) $< $@
225
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) $< $@
230
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) $< $@; \
236 cmdstatus=$$?; \
237 else \
238 echo INSTALLSYM dSYM $(@F).dSYM "($(CURRENT_ARCH_CONFIG_LC))"; \
239 $(LIPO) -create $@ $< -output $@; \
240 cmdstatus=$$?; \
241 fi; \
242 exit $$cmdstatus
243
244 .PHONY: do_install_machine_specific_kernel do_install_machine_specific_kernel_dSYM
245
246 do_install_machine_specific_kernel: $(DSTROOT)/$(INSTALL_KERNEL_DIR)/$(KERNEL_FILE_NAME) \
247 $(SYMROOT)/$(KERNEL_FILE_NAME)
248 @:
249
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)
255 @:
256
257 .PHONY: do_install_machine_specific_KDK_dSYM
258
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)
264 @:
265
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
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)
289 ifeq ($(USE_BINARY_PLIST),1)
290 $(_v)$(PLUTIL) -convert binary1 -o $@ $@
291 endif
292
293 print_exports:
294 $(_v)printenv | sort