]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | export SOURCE=$(shell /bin/pwd) |
316670eb | 2 | export RELATIVE_SOURCE_PATH ?= . |
1c79356b A |
3 | |
4 | # | |
5 | # gnumake 3.77 support | |
6 | # | |
7 | export USE_APPLE_PB_SUPPORT = all | |
8 | ||
9 | # | |
10 | # Incremental Build option | |
11 | # | |
12 | ifndef INCR_EXPORTHDRS | |
13 | ifeq ($(shell test -d $$OBJROOT/EXPORT_HDRS;echo $$?),0) | |
14 | export INCR_EXPORTHDRS = TRUE | |
15 | else | |
16 | export INCR_EXPORTHDRS = FALSE | |
17 | endif | |
18 | endif | |
19 | ||
b0d623f7 | 20 | |
1c79356b A |
21 | # |
22 | # Component List | |
23 | # | |
0b4e3aa0 | 24 | ifndef COMPONENT_LIST |
2d21ac55 | 25 | export COMPONENT_LIST = osfmk bsd libkern iokit pexpert libsa security |
0c530ab8 | 26 | export COMPONENT_LIST_UC := $(shell printf "%s" "$(COMPONENT_LIST)" | $(TR) a-z A-Z) |
0b4e3aa0 A |
27 | endif |
28 | ifndef COMPONENT | |
316670eb | 29 | export COMPONENT := $(firstword $(subst /, ,$(RELATIVE_SOURCE_PATH))) |
0b4e3aa0 A |
30 | export COMPONENT_IMPORT_LIST := $(filter-out $(COMPONENT),$(COMPONENT_LIST)) |
31 | else | |
32 | ifeq ($(COMPONENT), .) | |
316670eb | 33 | export COMPONENT := $(if $(word 2,$(subst /, ,$(RELATIVE_SOURCE_PATH))),$(word 2,$(subst /, ,$(RELATIVE_SOURCE_PATH))),$(firstword $(subst /, ,$(RELATIVE_SOURCE_PATH)))) |
0b4e3aa0 A |
34 | export COMPONENT_IMPORT_LIST := $(filter-out $(COMPONENT),$(COMPONENT_LIST)) |
35 | endif | |
36 | endif | |
1c79356b A |
37 | |
38 | # Architecture options | |
39 | # | |
2d21ac55 | 40 | ifndef SUPPORTED_ARCH_CONFIGS |
6d2010ae | 41 | export SUPPORTED_ARCH_CONFIGS = I386 X86_64 |
2d21ac55 A |
42 | endif |
43 | ||
0b4e3aa0 | 44 | ifndef ARCH_CONFIGS |
1c79356b | 45 | ifdef RC_ARCHS |
316670eb | 46 | export ARCH_CONFIGS := $(shell printf "%s" "$(RC_ARCHS)" | $(TR) a-z A-Z | sed -E 's/ARMV[0-9][A-Z]?/ARM/g') |
1c79356b | 47 | else |
316670eb A |
48 | ifeq ($(PLATFORM),iPhoneOS) |
49 | export ARCH_CONFIGS := ARM | |
50 | else | |
51 | export ARCH_CONFIGS := $(shell arch | $(TR) a-z A-Z | sed -E 's/ARMV[0-9][A-Z]?/ARM/g') | |
52 | endif | |
0b4e3aa0 A |
53 | endif |
54 | endif | |
55 | ifdef ARCH_CONFIG | |
56 | ifndef ARCH_CONFIG_LC | |
0c530ab8 | 57 | export ARCH_CONFIG_LC := $(shell printf "%s" "$(ARCH_CONFIG)" | $(TR) A-Z a-z) |
1c79356b A |
58 | endif |
59 | endif | |
1c79356b | 60 | |
6d2010ae A |
61 | # |
62 | # Platform options | |
63 | # | |
64 | ifndef SUPPORTED_PLATFORMS | |
65 | export SUPPORTED_PLATFORMS = MacOSX iPhoneOS iPhoneSimulator | |
66 | endif | |
67 | ||
68 | # PLATFORM is set earlier in MakeInc.cmd, closer to where decisions about | |
69 | # platform tools are made | |
70 | ||
2d21ac55 | 71 | # |
1c79356b A |
72 | # Kernel Configuration options |
73 | # | |
2d21ac55 A |
74 | ifndef SUPPORTED_KERNEL_CONFIGS |
75 | export SUPPORTED_KERNEL_CONFIGS = RELEASE DEVELOPMENT DEBUG PROFILE | |
76 | endif | |
0c530ab8 | 77 | |
2d21ac55 | 78 | ifndef DEFAULT_KERNEL_CONFIG |
b0d623f7 A |
79 | ifeq ($(RC_ProjectName),xnu_debug) |
80 | export DEFAULT_KERNEL_CONFIG = DEBUG | |
81 | else | |
2d21ac55 | 82 | export DEFAULT_KERNEL_CONFIG = RELEASE |
1c79356b | 83 | endif |
b0d623f7 | 84 | endif |
2d21ac55 A |
85 | |
86 | # If KERNEL_CONFIGS is specified it should override KERNEL_CONFIG. | |
87 | # If KERNEL_CONFIG is specified it will override the default. Will quit with | |
88 | # error if more than one config is specified. | |
89 | # If DEFAULT_KERNEL_CONFIG is not specified then it will be built RELEASE. | |
90 | ifndef KERNEL_CONFIGS | |
91 | ifndef KERNEL_CONFIG | |
92 | export KERNEL_CONFIGS = $(DEFAULT_KERNEL_CONFIG) | |
93 | else | |
94 | export KERNEL_CONFIGS = $(KERNEL_CONFIG) | |
95 | endif | |
0c530ab8 A |
96 | endif |
97 | ||
0b4e3aa0 | 98 | ifndef KERNEL_CONFIG |
1c79356b | 99 | export KERNEL_CONFIG = $(firstword $(KERNEL_CONFIGS)) |
0b4e3aa0 | 100 | endif |
1c79356b | 101 | |
2d21ac55 A |
102 | ifneq ($(words $(KERNEL_CONFIG)), 1) |
103 | $(error There were $(words $(KERNEL_CONFIG)) parameters passed to KERNEL_CONFIG = $(KERNEL_CONFG). \ | |
104 | Are you sure? To specify multiple configurations please use KERNEL_CONFIGS) | |
105 | endif | |
106 | ||
2d21ac55 A |
107 | ifndef MACHINE_CONFIG |
108 | export MACHINE_CONFIG = DEFAULT | |
109 | endif | |
110 | ||
2d21ac55 | 111 | |
316670eb A |
112 | # |
113 | # Machine Configuration options | |
114 | # | |
115 | export SUPPORTED_I386_MACHINE_CONFIGS := DEFAULT | |
116 | export SUPPORTED_X86_64_MACHINE_CONFIGS := DEFAULT | |
6d2010ae | 117 | |
6d2010ae | 118 | |
2d21ac55 A |
119 | # |
120 | # Target configuration options. NOTE - target configurations will | |
121 | # override ARCH_CONFIGS and KERNEL_CONFIGS. | |
122 | # | |
123 | # Target configs come in groups of three parameters. The first is the | |
124 | # kernel configuration, the second is the architecture configuration, | |
125 | # and the third is the machine configuration. You may pass in as | |
126 | # many groups of configurations as you wish. Each item passed in is | |
316670eb | 127 | # separated by whitespace. |
2d21ac55 A |
128 | # |
129 | # Example: | |
316670eb | 130 | # TARGET_CONFIGS="release x86_64 default debug i386 default release arm S5l8920X" |
2d21ac55 A |
131 | # Parameters may be in upper or lower case (they are converted to upper). |
132 | # | |
133 | # "default" parameter is a special case. It means use the default value for | |
134 | # that parameter. Here are the default values for each configuration: | |
135 | # | |
136 | # default kernel configuration = DEFAULT_KERNEL_CONFIG | |
137 | # default architecture configuration = system architecture where you are running make. | |
2d21ac55 | 138 | # default machine configuration for i386 = none at this time. |
b0d623f7 | 139 | # default machine configuration for x86_64 = none at this time. |
6d2010ae | 140 | # default machine configuration for arm = "S5L8920X". |
2d21ac55 A |
141 | # |
142 | ifndef TARGET_CONFIGS_UC | |
143 | ifdef TARGET_CONFIGS | |
b0d623f7 | 144 | export TARGET_CONFIGS_UC := $(strip $(shell printf "%s" "$(TARGET_CONFIGS)" | $(TR) a-z A-Z)) |
2d21ac55 A |
145 | export MACHINE_CONFIG = $(word 3, $(TARGET_CONFIGS_UC)) |
146 | export DEFAULT_KERNEL_CONFIG = $(word 1, $(TARGET_CONFIGS_UC)) | |
1c79356b | 147 | else |
316670eb A |
148 | |
149 | ifneq ($(filter %_embedded,$(MAKECMDGOALS)),) | |
150 | # generate set of standard embedded configs | |
151 | export TARGET_CONFIGS = $(TARGET_CONFIGS_EMBEDDED) | |
152 | else ifneq ($(filter %_devicemap,$(MAKECMDGOALS)),) | |
153 | DEVICEMAP_PLATFORMS = $(shell $(EMBEDDED_DEVICE_MAP) -query SELECT DISTINCT Platform FROM Targets | $(TR) [:lower:] [:upper:]) | |
154 | export TARGET_CONFIGS = $(foreach my_kernel_config,$(KERNEL_CONFIGS_EMBEDDED),$(foreach my_arch,$(ARCH_CONFIGS),$(foreach my_machine_config,$(filter $(DEVICEMAP_PLATFORMS),$(SUPPORTED_$(my_arch)_MACHINE_CONFIGS)),$(my_kernel_config) $(my_arch) $(my_machine_config) ))) | |
155 | else | |
156 | # generate TARGET_CONFIGS using KERNEL_CONFIGS and ARCH_CONFIGS and MACHINE_CONFIG (which defaults to "DEFAULT") | |
157 | export TARGET_CONFIGS = $(strip $(foreach my_arch_config, $(ARCH_CONFIGS), $(foreach my_kern_config, $(KERNEL_CONFIGS), $(my_kern_config) $(my_arch_config) $(MACHINE_CONFIG)))) | |
158 | endif | |
2d21ac55 A |
159 | export TARGET_CONFIGS_UC := $(shell printf "%s" "$(TARGET_CONFIGS)" | $(TR) a-z A-Z) |
160 | export MACHINE_CONFIG = $(word 3, $(TARGET_CONFIGS_UC)) | |
161 | export DEFAULT_KERNEL_CONFIG = $(word 1, $(TARGET_CONFIGS_UC)) | |
1c79356b | 162 | endif |
2d21ac55 A |
163 | endif |
164 | ||
165 | export MACHINE_CONFIG_LC := $(shell printf "%s" "$(MACHINE_CONFIG)" | $(TR) A-Z a-z) | |
166 | export KERNEL_CONFIG_LC := $(shell printf "%s" "$(KERNEL_CONFIG)" | $(TR) A-Z a-z) | |
167 | ||
6d2010ae A |
168 | # |
169 | # Validate configuration options | |
170 | # | |
171 | ifneq ($(ARCH_CONFIG),) | |
172 | ifeq ($(filter $(ARCH_CONFIG),$(SUPPORTED_ARCH_CONFIGS)),) | |
173 | $(error Unsupported ARCH_CONFIG $(ARCH_CONFIG)) | |
174 | endif | |
175 | endif | |
176 | ||
177 | ifneq ($(KERNEL_CONFIG),) | |
178 | ifeq ($(filter $(KERNEL_CONFIG),$(SUPPORTED_KERNEL_CONFIGS)),) | |
179 | $(error Unsupported KERNEL_CONFIG $(KERNEL_CONFIG)) | |
180 | endif | |
181 | endif | |
182 | ||
183 | ifneq ($(MACHINE_CONFIG),) | |
316670eb A |
184 | ifneq ($(ARCH_CONFIG),) |
185 | ifeq ($(filter $(MACHINE_CONFIG),$(SUPPORTED_$(ARCH_CONFIG)_MACHINE_CONFIGS)),) | |
6d2010ae A |
186 | $(error Unsupported MACHINE_CONFIG $(MACHINE_CONFIG)) |
187 | endif | |
188 | endif | |
316670eb | 189 | endif |
6d2010ae A |
190 | |
191 | ifneq ($(PLATFORM),) | |
192 | ifeq ($(filter $(PLATFORM),$(SUPPORTED_PLATFORMS)),) | |
193 | $(error Unsupported PLATFORM $(PLATFORM)) | |
194 | endif | |
195 | endif | |
196 | ||
2d21ac55 A |
197 | # |
198 | # Kernel Configuration to install | |
199 | # | |
316670eb | 200 | # supported install architecture : I386 X86_64 |
2d21ac55 A |
201 | # |
202 | export INSTALL_TYPE = $(DEFAULT_KERNEL_CONFIG) | |
203 | ||
204 | ifndef INSTALL_ARCHS | |
6d2010ae | 205 | export INSTALL_ARCHS = $(strip $(foreach my_config, $(SUPPORTED_ARCH_CONFIGS), $(filter $(TARGET_CONFIGS_UC),$(my_config)))) |
2d21ac55 | 206 | export INSTALL_ARCHS_LC := $(shell printf "%s" "$(INSTALL_ARCHS)" | $(TR) A-Z a-z) |
0b4e3aa0 | 207 | endif |
1c79356b | 208 | |
b0d623f7 | 209 | export INSTALL_ARCH_DEFAULT = $(firstword $(INSTALL_ARCHS)) |
6d2010ae A |
210 | ifeq ($(INSTALL_ARCH_DEFAULT),) |
211 | $(error Could not determine INSTALL_ARCH_DEFAULT) | |
212 | endif | |
1c79356b | 213 | |
316670eb A |
214 | # |
215 | # Deployment target flag | |
216 | # | |
217 | ifndef DEPLOYMENT_TARGET_FLAGS | |
218 | SDKVERSION=$(shell xcodebuild -sdk $(SDKROOT) -version SDKVersion | head -1) | |
219 | ifeq ($(PLATFORM),MacOSX) | |
220 | export DEPLOYMENT_TARGET_FLAGS := -mmacosx-version-min=$(SDKVERSION) | |
221 | else ifeq ($(PLATFORM),iPhoneOS) | |
222 | export DEPLOYMENT_TARGET_FLAGS := -miphoneos-version-min=$(SDKVERSION) | |
223 | else ifeq ($(PLATFORM),iPhoneSimulator) | |
224 | export DEPLOYMENT_TARGET_FLAGS := | |
225 | else | |
226 | export DEPLOYMENT_TARGET_FLAGS := | |
227 | endif | |
228 | endif | |
229 | ||
1c79356b A |
230 | # |
231 | # Standard defines list | |
232 | # | |
6d2010ae A |
233 | export DEFINES = -DAPPLE -DKERNEL -DKERNEL_PRIVATE -DXNU_KERNEL_PRIVATE \ |
234 | -DPRIVATE -D__MACHO__=1 -Dvolatile=__volatile $(IDENT) | |
1c79356b A |
235 | |
236 | # | |
237 | # Compiler command | |
238 | # | |
0c530ab8 A |
239 | KCC := $(CC) |
240 | KC++ := $(CXX) | |
9bccf70c | 241 | |
91447636 A |
242 | # |
243 | # Compiler warning flags | |
244 | # | |
245 | ||
246 | CWARNFLAGS_STD = \ | |
6d2010ae A |
247 | -Wall -Werror -Wno-format-y2k -Wextra -Wstrict-prototypes \ |
248 | -Wmissing-prototypes -Wpointer-arith -Wreturn-type -Wcast-qual \ | |
249 | -Wwrite-strings -Wswitch -Wshadow -Wcast-align -Wchar-subscripts \ | |
250 | -Winline -Wnested-externs -Wredundant-decls -Wextra-tokens | |
251 | ||
252 | # Certain warnings are non-fatal (8474835) | |
253 | CWARNFLAGS_STD += -Wno-error=cast-align | |
91447636 | 254 | |
6d2010ae | 255 | # Can be overridden in Makefile.template or Makefile.$arch |
91447636 A |
256 | export CWARNFLAGS ?= $(CWARNFLAGS_STD) |
257 | ||
6d2010ae A |
258 | define add_perfile_cflags |
259 | $(1)_CWARNFLAGS_ADD += $2 | |
260 | endef | |
261 | ||
91447636 | 262 | CXXWARNFLAGS_STD = \ |
6d2010ae A |
263 | -Wall -Werror -Wno-format-y2k -Wextra -Wpointer-arith -Wreturn-type \ |
264 | -Wcast-qual -Wwrite-strings -Wswitch -Wcast-align -Wchar-subscripts \ | |
265 | -Wredundant-decls -Wextra-tokens | |
266 | ||
316670eb A |
267 | # Certain warnings are non-fatal (8474835, 9000888) |
268 | CXXWARNFLAGS_STD += -Wno-error=cast-align -Wno-error=overloaded-virtual | |
91447636 | 269 | |
6d2010ae | 270 | # Can be overridden in Makefile.template or Makefile.$arch |
91447636 A |
271 | export CXXWARNFLAGS ?= $(CXXWARNFLAGS_STD) |
272 | ||
6d2010ae A |
273 | define add_perfile_cxxflags |
274 | $(1)_CXXWARNFLAGS_ADD += $2 | |
275 | endef | |
9bccf70c A |
276 | |
277 | # | |
2d21ac55 | 278 | # Setup for parallel sub-makes based on 2 times number of logical CPUs |
9bccf70c A |
279 | # |
280 | ifndef MAKEJOBS | |
2d21ac55 | 281 | export MAKEJOBS = --jobs=$(shell expr `/usr/sbin//sysctl -n hw.logicalcpu` \* 2) |
9bccf70c | 282 | endif |
1c79356b | 283 | |
2d21ac55 A |
284 | # |
285 | # Default ARCH_FLAGS, for use with compiler/linker/assembler/mig drivers | |
286 | ||
2d21ac55 | 287 | ARCH_FLAGS_I386 = -arch i386 |
b0d623f7 | 288 | ARCH_FLAGS_X86_64 = -arch x86_64 |
c910b4d9 | 289 | |
2d21ac55 | 290 | |
1c79356b A |
291 | # |
292 | # Default CFLAGS | |
293 | # | |
294 | ifdef RC_CFLAGS | |
295 | export OTHER_CFLAGS = $(subst $(addprefix -arch ,$(RC_ARCHS)),,$(RC_CFLAGS)) | |
296 | endif | |
297 | ||
6d2010ae | 298 | export DSYMRESDIR = ./Contents/Resources/ |
2d21ac55 A |
299 | export DSYMBUILDDIR = ./Contents/Resources/DWARF/ |
300 | ||
301 | # | |
302 | # We must not use -fno-keep-inline-functions, or it will remove the dtrace | |
303 | # probes from the kernel. | |
304 | # | |
316670eb A |
305 | export CFLAGS_GEN = $(DEBUG_CFLAGS) -nostdinc \ |
306 | -freorder-blocks -fno-builtin -fno-common \ | |
307 | -fsigned-bitfields $(OTHER_CFLAGS) | |
1c79356b | 308 | |
c910b4d9 A |
309 | ifeq ($(BUILD_STABS),1) |
310 | export CFLAGS_GEN += -gstabs+ | |
311 | export BUILD_DWARF = 0 | |
312 | export BUILD_STABS = 1 | |
313 | else | |
314 | export CFLAGS_GEN += -gdwarf-2 | |
315 | export BUILD_DWARF = 1 | |
316 | export BUILD_STABS = 0 | |
317 | endif | |
318 | ||
1c79356b | 319 | export CFLAGS_RELEASE = |
2d21ac55 | 320 | export CFLAGS_DEVELOPMENT = |
316670eb A |
321 | export CFLAGS_DEBUG = -fstack-protector-all |
322 | export CFLAGS_PROFILE = -pg | |
1c79356b | 323 | |
316670eb A |
324 | export CFLAGS_I386 = -static -Di386 -DI386 -D__I386__ \ |
325 | -DPAGE_SIZE_FIXED -msoft-float \ | |
326 | -integrated-as | |
b0d623f7 | 327 | export CFLAGS_X86_64 = -Dx86_64 -DX86_64 -D__X86_64__ -DLP64 \ |
316670eb A |
328 | -DPAGE_SIZE_FIXED -mkernel -msoft-float \ |
329 | -integrated-as | |
c910b4d9 | 330 | |
6d2010ae | 331 | |
c910b4d9 A |
332 | ifeq (-arch armv7,$(ARCH_FLAGS_ARM)) |
333 | CFLAGS_ARM += -mthumb | |
2d21ac55 A |
334 | endif |
335 | ifeq (-arch armv6,$(ARCH_FLAGS_ARM)) | |
336 | CFLAGS_ARM += -mthumb | |
337 | endif | |
316670eb | 338 | |
2d21ac55 | 339 | |
6d2010ae A |
340 | export CFLAGS_RELEASEI386 = -O2 |
341 | export CFLAGS_DEVELOPMENTI386 = -O2 | |
342 | export CFLAGS_DEBUGI386 = -O0 | |
343 | export CFLAGS_PROFILEI386 = -O2 | |
1c79356b | 344 | |
6d2010ae A |
345 | export CFLAGS_RELEASEX86_64 = -O2 |
346 | export CFLAGS_DEVELOPMENTX86_64 = -O2 | |
b0d623f7 A |
347 | # No space optimization for the DEBUG kernel for the benefit of gdb: |
348 | export CFLAGS_DEBUGX86_64 = -O0 | |
6d2010ae | 349 | export CFLAGS_PROFILEX86_64 = -O2 |
b0d623f7 | 350 | |
2d21ac55 A |
351 | export CFLAGS_RELEASEARM = -O2 |
352 | export CFLAGS_DEVELOPMENTARM = -O2 | |
316670eb | 353 | export CFLAGS_DEBUGARM = -O0 |
2d21ac55 A |
354 | export CFLAGS_PROFILEARM = -O2 |
355 | ||
1c79356b | 356 | export CFLAGS = $(CFLAGS_GEN) \ |
2d21ac55 A |
357 | $($(addsuffix $(MACHINE_CONFIG),MACHINE_FLAGS_)) \ |
358 | $($(addsuffix $(ARCH_CONFIG),ARCH_FLAGS_)) \ | |
1c79356b A |
359 | $($(addsuffix $(ARCH_CONFIG),CFLAGS_)) \ |
360 | $($(addsuffix $(KERNEL_CONFIG),CFLAGS_)) \ | |
361 | $($(addsuffix $(ARCH_CONFIG), $(addsuffix $(KERNEL_CONFIG),CFLAGS_))) \ | |
316670eb | 362 | $(DEPLOYMENT_TARGET_FLAGS) \ |
1c79356b A |
363 | $(DEFINES) |
364 | ||
6d2010ae | 365 | # |
55e303ae | 366 | # Default C++ flags |
1c79356b | 367 | # |
6d2010ae A |
368 | |
369 | OTHER_CXXFLAGS = | |
316670eb A |
370 | |
371 | CXXFLAGS_GEN = -fapple-kext $(OTHER_CXXFLAGS) | |
1c79356b | 372 | |
55e303ae A |
373 | CXXFLAGS = $(CXXFLAGS_GEN) \ |
374 | $($(addsuffix $(ARCH_CONFIG),CXXFLAGS_)) \ | |
375 | $($(addsuffix $(KERNEL_CONFIG),CXXFLAGS_)) | |
1c79356b A |
376 | |
377 | # | |
378 | # Assembler command | |
379 | # | |
0c530ab8 A |
380 | AS = $(CC) |
381 | S_KCC = $(CC) | |
1c79356b A |
382 | |
383 | # | |
384 | # Default SFLAGS | |
385 | # | |
316670eb | 386 | export SFLAGS_GEN = -D__ASSEMBLER__ $(OTHER_CFLAGS) |
1c79356b A |
387 | |
388 | export SFLAGS_RELEASE = | |
2d21ac55 | 389 | export SFLAGS_DEVELOPMENT = |
1c79356b A |
390 | export SFLAGS_DEBUG = |
391 | export SFLAGS_PROFILE = | |
392 | ||
2d21ac55 | 393 | export SFLAGS_I386 = $(CFLAGS_I386) |
b0d623f7 | 394 | export SFLAGS_X86_64 = $(CFLAGS_X86_64) |
1c79356b | 395 | |
316670eb | 396 | |
1c79356b | 397 | export SFLAGS = $(SFLAGS_GEN) \ |
2d21ac55 A |
398 | $($(addsuffix $(MACHINE_CONFIG),MACHINE_FLAGS_)) \ |
399 | $($(addsuffix $(ARCH_CONFIG),ARCH_FLAGS_)) \ | |
1c79356b A |
400 | $($(addsuffix $(ARCH_CONFIG),SFLAGS_)) \ |
401 | $($(addsuffix $(KERNEL_CONFIG),SFLAGS_)) \ | |
316670eb | 402 | $(DEPLOYMENT_TARGET_FLAGS) \ |
1c79356b A |
403 | $(DEFINES) |
404 | ||
316670eb | 405 | |
1c79356b A |
406 | # |
407 | # Linker command | |
408 | # | |
0c530ab8 | 409 | LD = $(KC++) -nostdlib |
1c79356b A |
410 | |
411 | # | |
412 | # Default LDFLAGS | |
413 | # | |
91447636 | 414 | export LDFLAGS_KERNEL_GEN = \ |
6d2010ae | 415 | -nostdlib \ |
0c530ab8 | 416 | -fapple-kext \ |
0c530ab8 | 417 | -Wl,-e,__start \ |
0c530ab8 | 418 | -Wl,-sectalign,__TEXT,__text,0x1000 \ |
316670eb | 419 | -Wl,-sectalign,__TEXT,initcode,0x1000 \ |
0c530ab8 A |
420 | -Wl,-sectalign,__DATA,__common,0x1000 \ |
421 | -Wl,-sectalign,__DATA,__bss,0x1000 \ | |
b0d623f7 A |
422 | -Wl,-sectcreate,__PRELINK_TEXT,__text,/dev/null \ |
423 | -Wl,-sectcreate,__PRELINK_STATE,__kernel,/dev/null \ | |
424 | -Wl,-sectcreate,__PRELINK_STATE,__kexts,/dev/null \ | |
316670eb A |
425 | -Wl,-sectcreate,__PRELINK_INFO,__info,/dev/null \ |
426 | -Wl,-new_linker \ | |
427 | -Wl,-pagezero_size,0x0 \ | |
428 | -Wl,-version_load_command \ | |
429 | -Wl,-function_starts | |
b0d623f7 | 430 | |
6d2010ae A |
431 | # Availability of DWARF allows DTrace CTF (compressed type format) to be constructed. |
432 | # ctf_insert creates the CTF section. It needs reserved padding in the | |
433 | # headers for the load command segment and the CTF section structures. | |
b0d623f7 A |
434 | ifeq ($(BUILD_DWARF),1) |
435 | export LDFLAGS_KERNEL_GEN += \ | |
6d2010ae | 436 | -Wl,-headerpad,152 |
b0d623f7 | 437 | endif |
1c79356b A |
438 | |
439 | export LDFLAGS_KERNEL_RELEASE = | |
2d21ac55 | 440 | export LDFLAGS_KERNEL_DEVELOPMENT = |
1c79356b A |
441 | export LDFLAGS_KERNEL_DEBUG = |
442 | export LDFLAGS_KERNEL_PROFILE = | |
443 | ||
b0d623f7 | 444 | export LDFLAGS_KERNEL_RELEASEI386 = \ |
b0d623f7 A |
445 | -Wl,-segaddr,__INITPT,0x00100000 \ |
446 | -Wl,-segaddr,__INITGDT,0x00106000 \ | |
447 | -Wl,-segaddr,__SLEEP,0x00107000 \ | |
448 | -Wl,-segaddr,__HIB,0x00108000 \ | |
449 | -Wl,-image_base,0x200000 \ | |
450 | -Wl,-seg_page_size,__TEXT,0x200000 | |
451 | ||
452 | export LDFLAGS_KERNEL_DEBUGI386 = $(LDFLAGS_KERNEL_RELEASEI386) | |
453 | export LDFLAGS_KERNEL_DEVELOPMENTI386 = $(LDFLAGS_KERNEL_RELEASEI386) | |
454 | export LDFLAGS_KERNEL_PROFILEI386 = $(LDFLAGS_KERNEL_RELEASEI386) | |
455 | ||
316670eb A |
456 | # KASLR static slide config: |
457 | ifndef SLIDE | |
458 | SLIDE=0x00 | |
459 | endif | |
460 | KERNEL_MIN_ADDRESS := 0xffffff8000000000 | |
461 | KERNEL_BASE_OFFSET := 0x100000 | |
462 | KERNEL_STATIC_SLIDE := $(shell printf "0x%016x" \ | |
463 | $$[ $(SLIDE) << 21 ]) | |
464 | KERNEL_STATIC_BASE := $(shell printf "0x%016x" \ | |
465 | $$[ $(KERNEL_MIN_ADDRESS) + $(KERNEL_BASE_OFFSET) ]) | |
466 | KERNEL_HIB_SECTION_BASE := $(shell printf "0x%016x" \ | |
467 | $$[ $(KERNEL_STATIC_BASE) + $(KERNEL_STATIC_SLIDE) ]) | |
468 | KERNEL_TEXT_BASE := $(shell printf "0x%016x" \ | |
469 | $$[ $(KERNEL_HIB_SECTION_BASE) + 0x100000 ]) | |
470 | ||
471 | export LDFLAGS_KERNEL_RELEASEX86_64 = \ | |
472 | -Wl,-pie \ | |
473 | -Wl,-segaddr,__HIB,$(KERNEL_HIB_SECTION_BASE) \ | |
474 | -Wl,-image_base,$(KERNEL_TEXT_BASE) \ | |
475 | -Wl,-seg_page_size,__TEXT,0x200000 \ | |
476 | -Wl,-sectalign,__DATA,__const,0x1000 \ | |
477 | -Wl,-sectalign,__DATA,__sysctl_set,0x1000 \ | |
478 | -Wl,-sectalign,__HIB,__bootPT,0x1000 \ | |
479 | -Wl,-sectalign,__HIB,__desc,0x1000 \ | |
480 | -Wl,-sectalign,__HIB,__data,0x1000 \ | |
481 | -Wl,-sectalign,__HIB,__text,0x1000 \ | |
482 | -Wl,-sectalign,__HIB,__const,0x1000 \ | |
483 | -Wl,-sectalign,__HIB,__bss,0x1000 \ | |
484 | -Wl,-sectalign,__HIB,__common,0x1000 \ | |
485 | ||
486 | # Define KERNEL_BASE_OFFSET so known at compile time: | |
487 | export CFLAGS_X86_64 += -DKERNEL_BASE_OFFSET=$(KERNEL_BASE_OFFSET) | |
b0d623f7 A |
488 | |
489 | export LDFLAGS_KERNEL_DEBUGX86_64 = $(LDFLAGS_KERNEL_RELEASEX86_64) | |
490 | export LDFLAGS_KERNEL_DEVELOPMENTX86_64 = $(LDFLAGS_KERNEL_RELEASEX86_64) | |
491 | export LDFLAGS_KERNEL_PROFILEX86_64 = $(LDFLAGS_KERNEL_RELEASEX86_64) | |
2d21ac55 | 492 | |
d1ecb069 | 493 | export LDFLAGS_KERNEL_RELEASEARM = \ |
316670eb A |
494 | -Wl,-pie \ |
495 | -Wl,-static \ | |
6d2010ae | 496 | -Wl,-image_base,0x80001000 \ |
b7266188 | 497 | -Wl,-exported_symbols_list,$(TARGET)/kernel-kpi.exp |
b0d623f7 | 498 | |
d1ecb069 | 499 | export LDFLAGS_KERNEL_DEVELOPMENTARM = \ |
316670eb A |
500 | -Wl,-pie \ |
501 | -Wl,-static \ | |
6d2010ae | 502 | -Wl,-image_base,0x80001000 |
d1ecb069 A |
503 | |
504 | export LDFLAGS_KERNEL_DEBUGARM = $(LDFLAGS_KERNEL_DEVELOPMENTARM) | |
505 | ||
316670eb A |
506 | # Offset image base by page to have iBoot load kernel TEXT correctly. |
507 | # First page is used for various purposes : sleep token, reset vector. | |
1c79356b A |
508 | |
509 | export LDFLAGS_KERNEL = $(LDFLAGS_KERNEL_GEN) \ | |
2d21ac55 A |
510 | $($(addsuffix $(MACHINE_CONFIG),MACHINE_FLAGS_)) \ |
511 | $($(addsuffix $(ARCH_CONFIG),ARCH_FLAGS_)) \ | |
1c79356b | 512 | $($(addsuffix $(ARCH_CONFIG),LDFLAGS_KERNEL_)) \ |
b0d623f7 A |
513 | $($(addsuffix $(KERNEL_CONFIG),LDFLAGS_KERNEL_)) \ |
514 | $($(addsuffix $(ARCH_CONFIG), $(addsuffix $(KERNEL_CONFIG),LDFLAGS_KERNEL_))) \ | |
316670eb | 515 | $(DEPLOYMENT_TARGET_FLAGS) |
1c79356b A |
516 | |
517 | # | |
518 | # Default runtime libraries to be linked with the kernel | |
519 | # | |
520 | export LD_KERNEL_LIBS = -lcc_kext | |
521 | ||
b0d623f7 | 522 | |
1c79356b A |
523 | # |
524 | # Default INCFLAGS | |
525 | # | |
526 | export INCFLAGS_IMPORT = $(patsubst %, -I$(OBJROOT)/EXPORT_HDRS/%, $(COMPONENT_IMPORT_LIST)) | |
527 | export INCFLAGS_EXTERN = -I$(OBJROOT)/EXTERN_HDRS -I$(SRCROOT)/EXTERNAL_HEADERS -I$(SRCROOT)/EXTERNAL_HEADERS/bsd | |
91447636 | 528 | export INCFLAGS_GEN = -I$(SRCROOT)/$(COMPONENT) -I$(OBJROOT)/EXPORT_HDRS/$(COMPONENT) |
1c79356b A |
529 | export INCFLAGS_POSIX = -I$(OBJROOT)/EXPORT_HDRS/bsd |
530 | export INCFLAGS_LOCAL = -I. | |
531 | ||
9bccf70c | 532 | export INCFLAGS = $(INCFLAGS_LOCAL) $(INCFLAGS_GEN) $(INCFLAGS_IMPORT) $(INCFLAGS_EXTERN) $(INCFLAGS_MAKEFILE) |
1c79356b A |
533 | |
534 | # | |
535 | # Default MIGFLAGS | |
536 | # | |
316670eb A |
537 | export MIGFLAGS = $(DEFINES) $(INCFLAGS) $($(addsuffix $(ARCH_CONFIG),CFLAGS_)) \ |
538 | $($(addsuffix $(ARCH_CONFIG),ARCH_FLAGS_)) \ | |
539 | $(DEPLOYMENT_TARGET_FLAGS) | |
540 | ||
541 | # | |
542 | # Support for LLVM Link Time Optimization (LTO) | |
543 | # | |
544 | ||
545 | ifeq ($(BUILD_LTO),1) | |
546 | export CFLAGS_GEN += -flto | |
547 | export CXXFLAGS_GEN += -flto | |
548 | export LDFLAGS_KERNEL_GEN += -Wl,-object_path_lto,$(TARGET)/lto.o | |
549 | export CFLAGS_NOLTO_FLAG = -fno-lto | |
550 | export BUILD_MACHO_OBJ = 0 | |
551 | export BUILD_LTO = 1 | |
552 | else | |
553 | export CFLAGS_NOLTO_FLAG = | |
554 | export BUILD_MACHO_OBJ = 1 | |
555 | export BUILD_LTO = 0 | |
556 | endif | |
557 | ||
558 | # | |
559 | # Support for LLVM Integrated Assembler with clang driver | |
560 | # | |
561 | ifeq ($(BUILD_INTEGRATED_ASSEMBLER),1) | |
562 | export SFLAGS_GEN += -integrated-as | |
563 | export CFLAGS_GEN += -integrated-as | |
564 | export CXXFLAGS_GEN += -integrated-as | |
565 | export SFLAGS_NOINTEGRATEDAS_FLAGS = -no-integrated-as | |
566 | export CFLAGS_NOINTEGRATEDAS_FLAGS = -no-integrated-as | |
567 | else | |
568 | export SFLAGS_NOINTEGRATEDAS_FLAGS = | |
569 | export CFLAGS_NOINTEGRATEDAS_FLAGS = | |
570 | endif | |
1c79356b A |
571 | |
572 | # | |
573 | # Default VPATH | |
574 | # | |
575 | empty:= | |
576 | space:= $(empty) $(empty) | |
577 | export VPATH_IMPORT = $(subst $(space),:,$(patsubst %,$(OBJROOT)/EXPORT_HDRS/%,$(strip $(COMPONENT_IMPORT_LIST)))): | |
578 | export VPATH_EXTERN = $(OBJROOT)/EXTERN_HDRS: | |
579 | export VPATH_GEN = .:$(SOURCE): | |
580 | ||
581 | export VPATH = $(VPATH_GEN)$(VPATH_IMPORT)$(VPATH_EXTERN)$(VPATH_MAKEFILE) | |
582 | ||
583 | # | |
2d21ac55 | 584 | # Macros that control installation of kernel and its header files |
1c79356b A |
585 | # |
586 | # install flags for header files | |
587 | # | |
588 | INSTALL_FLAGS = -c -m 0444 | |
d7e50217 A |
589 | FILE_INSTALL_FLAGS = -c -m 0644 |
590 | DATA_INSTALL_FLAGS = -c -m 0644 | |
1c79356b A |
591 | |
592 | # | |
593 | # Header file destinations | |
594 | # | |
6d2010ae A |
595 | ifeq ($(RC_ProjectName),xnu_headers_Sim) |
596 | HEADER_INSTALL_PREFIX = $(SDKROOT) | |
597 | else | |
598 | HEADER_INSTALL_PREFIX = | |
599 | endif | |
600 | ||
601 | FRAMEDIR = $(HEADER_INSTALL_PREFIX)/System/Library/Frameworks | |
602 | ||
603 | SINCVERS = B | |
604 | SINCFRAME = $(FRAMEDIR)/System.framework | |
605 | SINCDIR = $(SINCFRAME)/Versions/$(SINCVERS)/Headers | |
606 | SPINCDIR = $(SINCFRAME)/Versions/$(SINCVERS)/PrivateHeaders | |
607 | SRESDIR = $(SINCFRAME)/Versions/$(SINCVERS)/Resources | |
608 | ||
1c79356b | 609 | ifndef INCDIR |
6d2010ae | 610 | INCDIR = $(HEADER_INSTALL_PREFIX)/usr/include |
1c79356b A |
611 | endif |
612 | ifndef LCLDIR | |
6d2010ae | 613 | LCLDIR = $(SPINCDIR) |
1c79356b A |
614 | endif |
615 | ||
616 | KINCVERS = A | |
617 | KINCFRAME = $(FRAMEDIR)/Kernel.framework | |
618 | KINCDIR = $(KINCFRAME)/Versions/$(KINCVERS)/Headers | |
0b4e3aa0 | 619 | KPINCDIR = $(KINCFRAME)/Versions/$(KINCVERS)/PrivateHeaders |
91447636 A |
620 | KRESDIR = $(KINCFRAME)/Versions/$(KINCVERS)/Resources |
621 | ||
622 | XNU_PRIVATE_UNIFDEF = -UMACH_KERNEL_PRIVATE -UBSD_KERNEL_PRIVATE -UIOKIT_KERNEL_PRIVATE -ULIBKERN_KERNEL_PRIVATE -ULIBSA_KERNEL_PRIVATE -UPEXPERT_KERNEL_PRIVATE -UXNU_KERNEL_PRIVATE | |
623 | ||
6d2010ae A |
624 | PLATFORM_UNIFDEF = $(foreach x,$(SUPPORTED_PLATFORMS),$(if $(filter $(PLATFORM),$(x)),-DPLATFORM_$(x),-UPLATFORM_$(x))) |
625 | ||
626 | SPINCFRAME_UNIFDEF = $(PLATFORM_UNIFDEF) $(XNU_PRIVATE_UNIFDEF) -UKERNEL_PRIVATE -UKERNEL -DPRIVATE -U_OPEN_SOURCE_ | |
627 | SINCFRAME_UNIFDEF = $(PLATFORM_UNIFDEF) $(XNU_PRIVATE_UNIFDEF) -UKERNEL_PRIVATE -UKERNEL -UPRIVATE -D_OPEN_SOURCE_ | |
628 | KPINCFRAME_UNIFDEF = $(PLATFORM_UNIFDEF) $(XNU_PRIVATE_UNIFDEF) -DKERNEL_PRIVATE -DPRIVATE -DKERNEL -U_OPEN_SOURCE_ | |
629 | KINCFRAME_UNIFDEF = $(PLATFORM_UNIFDEF) $(XNU_PRIVATE_UNIFDEF) -UKERNEL_PRIVATE -UPRIVATE -DKERNEL -D_OPEN_SOURCE_ | |
1c79356b | 630 | |
b0d623f7 | 631 | |
1c79356b | 632 | # |
316670eb | 633 | # Component Header file destinations |
1c79356b A |
634 | # |
635 | EXPDIR = EXPORT_HDRS/$(COMPONENT) | |
636 | ||
637 | # | |
638 | # Strip Flags | |
639 | # | |
55e303ae | 640 | export STRIP_FLAGS_RELEASE = -S -x |
2d21ac55 | 641 | export STRIP_FLAGS_DEVELOPMENT = -S -x |
1c79356b | 642 | export STRIP_FLAGS_DEBUG = -S |
55e303ae | 643 | export STRIP_FLAGS_PROFILE = -S -x |
1c79356b A |
644 | |
645 | export STRIP_FLAGS = $($(addsuffix $(KERNEL_CONFIG),STRIP_FLAGS_)) | |
646 | ||
2d21ac55 A |
647 | # |
648 | # dsymutil flags | |
649 | # | |
650 | export DSYMUTIL_FLAGS_I386 = --arch=i386 | |
b0d623f7 | 651 | export DSYMUTIL_FLAGS_X86_64 = --arch=x86_64 |
2d21ac55 A |
652 | |
653 | export DSYMUTIL_FLAGS = $($(addsuffix $(ARCH_CONFIG),DSYMUTIL_FLAGS_)) | |
654 | ||
9bccf70c A |
655 | # |
656 | # Man Page destination | |
657 | # | |
658 | MANDIR = usr/share/man | |
659 | ||
b0d623f7 A |
660 | # |
661 | # DEBUG alias location | |
662 | # | |
663 | DEVELOPER_EXTRAS_DIR = AppleInternal/Developer/Extras | |
2d21ac55 | 664 | |
1c79356b A |
665 | # |
666 | # This must be here before any rules are possibly defined by the | |
667 | # machine dependent makefile fragment so that a plain "make" command | |
668 | # always works. The config program will emit an appropriate rule to | |
669 | # cause "all" to depend on every kernel configuration it generates. | |
670 | # | |
671 | ||
672 | default: all | |
673 | ||
2d21ac55 | 674 | # vim: set ft=make: |