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