]>
Commit | Line | Data |
---|---|---|
39236c6e A |
1 | # -*- mode: makefile;-*- |
2 | # | |
39037602 | 3 | # Copyright (C) 1999-2016 Apple Inc. All rights reserved. |
39236c6e A |
4 | # |
5 | # MakeInc.cmd contains command paths for use during | |
6 | # the build, as well as make fragments and text | |
7 | # strings that may be evaluated as utility functions. | |
8 | # | |
9 | ||
1c79356b A |
10 | # |
11 | # Commands for the build environment | |
12 | # | |
cb323159 | 13 | |
b0d623f7 A |
14 | ## |
15 | # Verbosity | |
16 | ## | |
cb323159 | 17 | |
b0d623f7 | 18 | ifeq ($(RC_XBS),YES) |
cb323159 | 19 | VERBOSE = YES |
b0d623f7 | 20 | else |
cb323159 | 21 | VERBOSE = NO |
b0d623f7 | 22 | endif |
1c79356b | 23 | |
cb323159 A |
24 | ECHO = echo |
25 | ||
26 | LOG = echo | |
27 | makelog = $(info $1) | |
28 | ERR = $(ECHO) > /dev/stderr | |
29 | ||
30 | QUIET ?= 0 | |
31 | ifneq ($(QUIET),0) | |
32 | LOG = : | |
33 | makelog = | |
34 | ifeq ($(VERBOSE),YES) | |
35 | override VERBOSE = NO | |
36 | endif | |
37 | endif | |
fe8ab488 | 38 | |
b0d623f7 | 39 | ifeq ($(VERBOSE),YES) |
cb323159 A |
40 | _v = |
41 | _vstdout = | |
39236c6e | 42 | XCRUN = /usr/bin/xcrun -verbose |
b0d623f7 | 43 | else |
cb323159 A |
44 | _v = @ |
45 | _vstdout = > /dev/null | |
b0d623f7 A |
46 | XCRUN = /usr/bin/xcrun |
47 | endif | |
48 | ||
cb323159 A |
49 | VERBOSE_GENERATED_MAKE_FRAGMENTS = NO |
50 | ||
d9a64523 | 51 | SDKROOT ?= macosx |
39236c6e | 52 | HOST_SDKROOT ?= macosx |
316670eb A |
53 | |
54 | # SDKROOT may be passed as a shorthand like "iphoneos.internal". We | |
55 | # must resolve these to a full path and override SDKROOT. | |
56 | ||
57 | ifeq ($(SDKROOT_RESOLVED),) | |
39236c6e A |
58 | export SDKROOT_RESOLVED := $(shell $(XCRUN) -sdk $(SDKROOT) -show-sdk-path) |
59 | ifeq ($(strip $(SDKROOT)_$(SDKROOT_RESOLVED)),/_) | |
60 | export SDKROOT_RESOLVED := / | |
316670eb A |
61 | endif |
62 | endif | |
63 | override SDKROOT = $(SDKROOT_RESOLVED) | |
b0d623f7 | 64 | |
39236c6e A |
65 | ifeq ($(HOST_SDKROOT_RESOLVED),) |
66 | export HOST_SDKROOT_RESOLVED := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -show-sdk-path) | |
d9a64523 A |
67 | ifeq ($(strip $(HOST_SDKROOT_RESOLVED)),) |
68 | export HOST_SDKROOT_RESOLVED := / | |
69 | endif | |
39236c6e A |
70 | endif |
71 | override HOST_SDKROOT = $(HOST_SDKROOT_RESOLVED) | |
72 | ||
6d2010ae | 73 | ifeq ($(PLATFORM),) |
39236c6e A |
74 | export PLATFORMPATH := $(shell $(XCRUN) -sdk $(SDKROOT) -show-sdk-platform-path) |
75 | export PLATFORM := $(shell echo $(PLATFORMPATH) | sed 's,^.*/\([^/]*\)\.platform$$,\1,') | |
6d2010ae A |
76 | ifeq ($(PLATFORM),) |
77 | export PLATFORM := MacOSX | |
3e170ce0 A |
78 | else ifeq ($(shell echo $(PLATFORM) | tr A-Z a-z),watchos) |
79 | export PLATFORM := WatchOS | |
6d2010ae A |
80 | endif |
81 | endif | |
82 | ||
cb323159 A |
83 | ifeq ($(PLATFORM),MacOSX) |
84 | ifeq (DriverKit,$(shell echo $(SDKROOT_RESOLVED) | sed 's,^.*/\([^/1-9]*\)[1-9][^/]*\.sdk$$,\1,')) | |
85 | export PLATFORM := DriverKit | |
86 | export DRIVERKIT ?= 1 | |
87 | export DRIVERKITROOT ?= /System/DriverKit | |
88 | export DRIVERKITRUNTIMEROOT = $(DRIVERKITROOT)/Runtime | |
89 | endif | |
90 | endif | |
91 | ||
39236c6e A |
92 | ifeq ($(SDKVERSION),) |
93 | export SDKVERSION := $(shell $(XCRUN) -sdk $(SDKROOT) -show-sdk-version) | |
94 | endif | |
95 | ||
6d2010ae A |
96 | # CC/CXX get defined by make(1) by default, so we can't check them |
97 | # against the empty string to see if they haven't been set | |
98 | ifeq ($(origin CC),default) | |
316670eb | 99 | export CC := $(shell $(XCRUN) -sdk $(SDKROOT) -find clang) |
6d2010ae A |
100 | endif |
101 | ifeq ($(origin CXX),default) | |
316670eb | 102 | export CXX := $(shell $(XCRUN) -sdk $(SDKROOT) -find clang++) |
6d2010ae A |
103 | endif |
104 | ifeq ($(MIG),) | |
105 | export MIG := $(shell $(XCRUN) -sdk $(SDKROOT) -find mig) | |
106 | endif | |
39236c6e A |
107 | ifeq ($(MIGCOM),) |
108 | export MIGCOM := $(shell $(XCRUN) -sdk $(SDKROOT) -find migcom) | |
109 | endif | |
b0d623f7 | 110 | ifeq ($(MIGCC),) |
6d2010ae | 111 | export MIGCC := $(CC) |
b0d623f7 | 112 | endif |
cb323159 A |
113 | ifeq ($(IIG),) |
114 | export IIG := $(shell $(XCRUN) -sdk $(SDKROOT) -find iig) | |
115 | endif | |
6d2010ae A |
116 | ifeq ($(STRIP),) |
117 | export STRIP := $(shell $(XCRUN) -sdk $(SDKROOT) -find strip) | |
118 | endif | |
119 | ifeq ($(LIPO),) | |
120 | export LIPO := $(shell $(XCRUN) -sdk $(SDKROOT) -find lipo) | |
121 | endif | |
122 | ifeq ($(LIBTOOL),) | |
123 | export LIBTOOL := $(shell $(XCRUN) -sdk $(SDKROOT) -find libtool) | |
124 | endif | |
125 | ifeq ($(NM),) | |
126 | export NM := $(shell $(XCRUN) -sdk $(SDKROOT) -find nm) | |
127 | endif | |
128 | ifeq ($(UNIFDEF),) | |
129 | export UNIFDEF := $(shell $(XCRUN) -sdk $(SDKROOT) -find unifdef) | |
130 | endif | |
6d2010ae A |
131 | ifeq ($(DSYMUTIL),) |
132 | export DSYMUTIL := $(shell $(XCRUN) -sdk $(SDKROOT) -find dsymutil) | |
133 | endif | |
134 | ifeq ($(CTFCONVERT),) | |
135 | export CTFCONVERT := $(shell $(XCRUN) -sdk $(SDKROOT) -find ctfconvert) | |
136 | endif | |
137 | ifeq ($(CTFMERGE),) | |
138 | export CTFMERGE := $(shell $(XCRUN) -sdk $(SDKROOT) -find ctfmerge) | |
139 | endif | |
39236c6e A |
140 | ifeq ($(CTFINSERT),) |
141 | export CTFINSERT := $(shell $(XCRUN) -sdk $(SDKROOT) -find ctf_insert) | |
6d2010ae A |
142 | endif |
143 | ifeq ($(NMEDIT),) | |
144 | export NMEDIT := $(shell $(XCRUN) -sdk $(SDKROOT) -find nmedit) | |
145 | endif | |
b0d623f7 | 146 | |
3e170ce0 A |
147 | # |
148 | # Platform options | |
149 | # | |
5ba3f43e | 150 | SUPPORTED_EMBEDDED_PLATFORMS := iPhoneOS iPhoneOSNano tvOS AppleTVOS WatchOS BridgeOS |
3e170ce0 | 151 | SUPPORTED_SIMULATOR_PLATFORMS := iPhoneSimulator iPhoneNanoSimulator tvSimulator AppleTVSimulator WatchSimulator |
cb323159 | 152 | SUPPORTED_PLATFORMS := MacOSX DriverKit $(SUPPORTED_SIMULATOR_PLATFORMS) $(SUPPORTED_EMBEDDED_PLATFORMS) |
3e170ce0 | 153 | |
6d2010ae | 154 | # Platform-specific tools |
3e170ce0 | 155 | ifneq ($(filter $(SUPPORTED_EMBEDDED_PLATFORMS),$(PLATFORM)),) |
316670eb A |
156 | ifeq ($(EMBEDDED_DEVICE_MAP),) |
157 | export EMBEDDED_DEVICE_MAP := $(shell $(XCRUN) -sdk $(SDKROOT) -find embedded_device_map) | |
158 | endif | |
5ba3f43e | 159 | EDM_DBPATH ?= $(PLATFORMPATH)/usr/local/standalone/firmware/device_map.db |
6d2010ae A |
160 | endif |
161 | ||
162 | # Scripts or tools we build ourselves | |
fe8ab488 A |
163 | # |
164 | # setsegname - Rename segments in a Mach-O object file | |
165 | # kextsymboltool - Create kext pseudo-kext Mach-O kexts binaries | |
166 | # decomment - Strip out comments to detect whether a file is comments-only | |
167 | # installfile - Atomically copy files, esp. when multiple architectures | |
168 | # are trying to install the same target header | |
169 | # replacecontents - Write contents to a file and update modtime *only* if | |
170 | # contents differ | |
171 | # | |
39236c6e A |
172 | SEG_HACK = $(OBJROOT)/SETUP/setsegname/setsegname |
173 | KEXT_CREATE_SYMBOL_SET = $(OBJROOT)/SETUP/kextsymboltool/kextsymboltool | |
174 | DECOMMENT = $(OBJROOT)/SETUP/decomment/decomment | |
6d2010ae | 175 | NEWVERS = $(SRCROOT)/config/newvers.pl |
39236c6e | 176 | INSTALL = $(OBJROOT)/SETUP/installfile/installfile |
fe8ab488 | 177 | REPLACECONTENTS = $(OBJROOT)/SETUP/replacecontents/replacecontents |
3e170ce0 | 178 | JSONCOMPILATIONDB = $(OBJROOT)/SETUP/json_compilation_db/json_compilation_db |
1c79356b | 179 | |
6d2010ae | 180 | # Standard BSD tools |
1c79356b | 181 | RM = /bin/rm -f |
39236c6e | 182 | RMDIR = /bin/rmdir |
1c79356b | 183 | CP = /bin/cp |
b0d623f7 | 184 | MV = /bin/mv |
0c530ab8 | 185 | LN = /bin/ln -fs |
1c79356b A |
186 | CAT = /bin/cat |
187 | MKDIR = /bin/mkdir -p | |
fe8ab488 | 188 | CHMOD = /bin/chmod |
2d21ac55 | 189 | FIND = /usr/bin/find |
316670eb | 190 | XARGS = /usr/bin/xargs |
fe8ab488 | 191 | PAX = /bin/pax |
1c79356b | 192 | BASENAME = /usr/bin/basename |
39236c6e | 193 | DIRNAME = /usr/bin/dirname |
0b4e3aa0 | 194 | TR = /usr/bin/tr |
39236c6e | 195 | TOUCH = /usr/bin/touch |
fe8ab488 | 196 | SLEEP = /bin/sleep |
39236c6e A |
197 | AWK = /usr/bin/awk |
198 | SED = /usr/bin/sed | |
39236c6e | 199 | PLUTIL = /usr/bin/plutil |
1c79356b | 200 | |
6d2010ae A |
201 | # |
202 | # Command to generate host binaries. Intentionally not | |
203 | # $(CC), which controls the target compiler | |
204 | # | |
39236c6e A |
205 | ifeq ($(HOST_OS_VERSION),) |
206 | export HOST_OS_VERSION := $(shell sw_vers -productVersion) | |
207 | endif | |
6d2010ae | 208 | ifeq ($(HOST_CC),) |
39236c6e | 209 | export HOST_CC := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find clang) |
6d2010ae A |
210 | endif |
211 | ifeq ($(HOST_FLEX),) | |
212 | export HOST_FLEX := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find flex) | |
213 | endif | |
214 | ifeq ($(HOST_BISON),) | |
215 | export HOST_BISON := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find bison) | |
216 | endif | |
39236c6e A |
217 | ifeq ($(HOST_GM4),) |
218 | export HOST_GM4 := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find gm4) | |
219 | endif | |
6d2010ae | 220 | ifeq ($(HOST_CODESIGN),) |
39236c6e A |
221 | export HOST_CODESIGN := /usr/bin/codesign |
222 | endif | |
223 | ifeq ($(HOST_CODESIGN_ALLOCATE),) | |
224 | export HOST_CODESIGN_ALLOCATE := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find codesign_allocate) | |
6d2010ae A |
225 | endif |
226 | ||
39236c6e A |
227 | # |
228 | # The following variables are functions invoked with "call", and thus | |
229 | # behave similarly to externally compiled commands | |
230 | # | |
231 | ||
232 | # $(1) is an expanded kernel config from a TARGET_CONFIGS_UC tuple | |
233 | # $(2) is an expanded arch config from a TARGET_CONFIGS_UC tuple | |
234 | # $(3) is an expanded machine config from a TARGET_CONFIGS_UC tuple | |
235 | _function_create_build_configs_join = $(strip $(1))^$(strip $(2))^$(strip $(3)) | |
236 | ||
237 | # $(1) is an un-expanded kernel config from a TARGET_CONFIGS_UC tuple | |
238 | # $(2) is an un-expanded arch config from a TARGET_CONFIGS_UC tuple | |
239 | # $(3) is an un-expanded machine config from a TARGET_CONFIGS_UC tuple | |
240 | _function_create_build_configs_do_expand = $(call _function_create_build_configs_join, \ | |
241 | $(if $(filter DEFAULT,$(1)), \ | |
39037602 | 242 | $(DEFAULT_KERNEL_CONFIG), \ |
39236c6e A |
243 | $(1) \ |
244 | ), \ | |
245 | $(if $(filter DEFAULT,$(2)), \ | |
39037602 | 246 | $(DEFAULT_ARCH_CONFIG), \ |
39236c6e A |
247 | $(2) \ |
248 | ), \ | |
249 | $(if $(filter DEFAULT,$(3)), \ | |
39037602 A |
250 | $(if $(filter DEFAULT,$(2)), \ |
251 | $(DEFAULT_$(DEFAULT_ARCH_CONFIG)_MACHINE_CONFIG), \ | |
39236c6e | 252 | $(DEFAULT_$(strip $(2))_MACHINE_CONFIG) \ |
39037602 | 253 | ), \ |
39236c6e A |
254 | $(3) \ |
255 | ) \ | |
256 | ) | |
257 | ||
258 | # $(1) is an un-expanded TARGET_CONFIGS_UC list, which must be consumed | |
259 | # 3 elements at a time | |
260 | function_create_build_configs = $(sort \ | |
261 | $(strip \ | |
39037602 A |
262 | $(call _function_create_build_configs_do_expand, \ |
263 | $(word 1,$(1)), \ | |
264 | $(word 2,$(1)), \ | |
265 | $(word 3,$(1)), \ | |
39236c6e A |
266 | ) \ |
267 | $(if $(word 4,$(1)), \ | |
268 | $(call function_create_build_configs, \ | |
269 | $(wordlist 4,$(words $(1)),$(1)) \ | |
270 | ), \ | |
39236c6e A |
271 | ) \ |
272 | ) \ | |
273 | ) | |
274 | ||
39037602 A |
275 | # Similar to build configs, but alias configs are a 4-tuple |
276 | ||
277 | # $(1) is an expanded kernel config from a TARGET_CONFIGS_ALIASES_UC tuple | |
278 | # $(2) is an expanded arch config from a TARGET_CONFIGS_ALIASES_UC tuple | |
279 | # $(3) is an expanded kernel machine config from a TARGET_CONFIGS_ALIASES_UC tuple | |
280 | # $(4) is an expanded SoC platform config from a TARGET_CONFIGS_ALIASES_UC tuple, | |
281 | # which should be an alias of $(3) | |
282 | _function_create_alias_configs_join = $(strip $(1))^$(strip $(2))^$(strip $(3))^$(strip $(4)) | |
283 | ||
284 | _function_create_alias_configs_do_expand = $(call _function_create_alias_configs_join, \ | |
285 | $(if $(filter DEFAULT,$(1)), \ | |
286 | $(DEFAULT_KERNEL_CONFIG), \ | |
287 | $(1) \ | |
288 | ), \ | |
289 | $(if $(filter DEFAULT,$(2)), \ | |
290 | $(DEFAULT_ARCH_CONFIG), \ | |
291 | $(2) \ | |
292 | ), \ | |
293 | $(3), \ | |
294 | $(4) \ | |
295 | ) | |
296 | ||
297 | function_create_alias_configs = $(sort \ | |
298 | $(strip \ | |
299 | $(call _function_create_alias_configs_do_expand, \ | |
300 | $(word 1,$(1)), \ | |
301 | $(word 2,$(1)), \ | |
302 | $(word 3,$(1)), \ | |
303 | $(word 4,$(1)), \ | |
304 | ) \ | |
305 | $(if $(word 5,$(1)), \ | |
306 | $(call function_create_alias_configs, \ | |
307 | $(wordlist 5,$(words $(1)),$(1)) \ | |
308 | ), \ | |
309 | ) \ | |
310 | ) \ | |
311 | ) | |
312 | ||
39236c6e A |
313 | # $(1) is a fully-expanded kernel config |
314 | # $(2) is a fully-expanded arch config | |
315 | # $(3) is a fully-expanded machine config. "NONE" is not represented in the objdir path | |
316 | function_convert_target_config_uc_to_objdir = $(if $(filter NONE,$(3)),$(strip $(1))_$(strip $(2)),$(strip $(1))_$(strip $(2))_$(strip $(3))) | |
317 | ||
318 | # $(1) is a fully-expanded build config (like "RELEASE^X86_64^NONE") | |
319 | function_convert_build_config_to_objdir = $(call function_convert_target_config_uc_to_objdir, \ | |
39037602 | 320 | $(word 1,$(subst ^, ,$(1))), \ |
39236c6e A |
321 | $(word 2,$(subst ^, ,$(1))), \ |
322 | $(word 3,$(subst ^, ,$(1))) \ | |
323 | ) | |
324 | ||
325 | # $(1) is a fully-expanded build config (like "RELEASE^X86_64^NONE") | |
326 | function_extract_kernel_config_from_build_config = $(word 1,$(subst ^, ,$(1))) | |
327 | function_extract_arch_config_from_build_config = $(word 2,$(subst ^, ,$(1))) | |
328 | function_extract_machine_config_from_build_config = $(word 3,$(subst ^, ,$(1))) | |
329 | ||
330 | # $(1) is an input word | |
331 | # $(2) is a list of colon-separate potential substitutions like "FOO:BAR BAZ:QUX" | |
332 | # $(3) is a fallback if no substitutions were made | |
333 | function_substitute_word_with_replacement = $(strip $(if $(2), \ | |
334 | $(if $(filter $(word 1,$(subst :, ,$(word 1,$(2)))),$(1)), \ | |
335 | $(word 2,$(subst :, ,$(word 1,$(2)))), \ | |
336 | $(call function_substitute_word_with_replacement,$(1),$(wordlist 2,$(words $(2)),$(2)),$(3))), \ | |
337 | $(3) \ | |
338 | ) \ | |
339 | ) | |
340 | ||
341 | # You can't assign a variable to an empty space without these | |
342 | # shenanigans | |
343 | empty := | |
344 | space := $(empty) $(empty) | |
345 | ||
346 | # Arithmetic | |
347 | # $(1) is the number to increment | |
39037602 | 348 | NUM32 = x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x |
fe8ab488 A |
349 | increment = $(words x $(wordlist 1,$(1),$(NUM32))) |
350 | decrement = $(words $(wordlist 2,$(1),$(NUM32))) | |
351 | ||
352 | # Create a sequence from 1 to $(1) | |
353 | # F(N) = if N > 0: return F(N-1) + "N" else: return "" | |
354 | sequence = $(if $(wordlist 1,$(1),$(NUM32)),$(call sequence,$(call decrement,$(1))) $(1),) | |
355 | ||
356 | # Reverse a list of words in $(1) | |
357 | reverse = $(if $(word 2,$(1)),$(call reverse,$(wordlist 2,$(words $(1)),$(1)))) $(word 1,$(1)) | |
39236c6e | 358 | |
2d21ac55 | 359 | # vim: set ft=make: |