]> git.saurik.com Git - apple/xnu.git/blob - makedefs/MakeInc.cmd
xnu-6153.81.5.tar.gz
[apple/xnu.git] / makedefs / MakeInc.cmd
1 # -*- mode: makefile;-*-
2 #
3 # Copyright (C) 1999-2016 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
10 #
11 # Commands for the build environment
12 #
13
14 ##
15 # Verbosity
16 ##
17
18 ifeq ($(RC_XBS),YES)
19 VERBOSE = YES
20 else
21 VERBOSE = NO
22 endif
23
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
38
39 ifeq ($(VERBOSE),YES)
40 _v =
41 _vstdout =
42 XCRUN = /usr/bin/xcrun -verbose
43 else
44 _v = @
45 _vstdout = > /dev/null
46 XCRUN = /usr/bin/xcrun
47 endif
48
49 VERBOSE_GENERATED_MAKE_FRAGMENTS = NO
50
51 SDKROOT ?= macosx
52 HOST_SDKROOT ?= macosx
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),)
58 export SDKROOT_RESOLVED := $(shell $(XCRUN) -sdk $(SDKROOT) -show-sdk-path)
59 ifeq ($(strip $(SDKROOT)_$(SDKROOT_RESOLVED)),/_)
60 export SDKROOT_RESOLVED := /
61 endif
62 endif
63 override SDKROOT = $(SDKROOT_RESOLVED)
64
65 ifeq ($(HOST_SDKROOT_RESOLVED),)
66 export HOST_SDKROOT_RESOLVED := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -show-sdk-path)
67 ifeq ($(strip $(HOST_SDKROOT_RESOLVED)),)
68 export HOST_SDKROOT_RESOLVED := /
69 endif
70 endif
71 override HOST_SDKROOT = $(HOST_SDKROOT_RESOLVED)
72
73 ifeq ($(PLATFORM),)
74 export PLATFORMPATH := $(shell $(XCRUN) -sdk $(SDKROOT) -show-sdk-platform-path)
75 export PLATFORM := $(shell echo $(PLATFORMPATH) | sed 's,^.*/\([^/]*\)\.platform$$,\1,')
76 ifeq ($(PLATFORM),)
77 export PLATFORM := MacOSX
78 else ifeq ($(shell echo $(PLATFORM) | tr A-Z a-z),watchos)
79 export PLATFORM := WatchOS
80 endif
81 endif
82
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
92 ifeq ($(SDKVERSION),)
93 export SDKVERSION := $(shell $(XCRUN) -sdk $(SDKROOT) -show-sdk-version)
94 endif
95
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)
99 export CC := $(shell $(XCRUN) -sdk $(SDKROOT) -find clang)
100 endif
101 ifeq ($(origin CXX),default)
102 export CXX := $(shell $(XCRUN) -sdk $(SDKROOT) -find clang++)
103 endif
104 ifeq ($(MIG),)
105 export MIG := $(shell $(XCRUN) -sdk $(SDKROOT) -find mig)
106 endif
107 ifeq ($(MIGCOM),)
108 export MIGCOM := $(shell $(XCRUN) -sdk $(SDKROOT) -find migcom)
109 endif
110 ifeq ($(MIGCC),)
111 export MIGCC := $(CC)
112 endif
113 ifeq ($(IIG),)
114 export IIG := $(shell $(XCRUN) -sdk $(SDKROOT) -find iig)
115 endif
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
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
140 ifeq ($(CTFINSERT),)
141 export CTFINSERT := $(shell $(XCRUN) -sdk $(SDKROOT) -find ctf_insert)
142 endif
143 ifeq ($(NMEDIT),)
144 export NMEDIT := $(shell $(XCRUN) -sdk $(SDKROOT) -find nmedit)
145 endif
146
147 #
148 # Platform options
149 #
150 SUPPORTED_EMBEDDED_PLATFORMS := iPhoneOS iPhoneOSNano tvOS AppleTVOS WatchOS BridgeOS
151 SUPPORTED_SIMULATOR_PLATFORMS := iPhoneSimulator iPhoneNanoSimulator tvSimulator AppleTVSimulator WatchSimulator
152 SUPPORTED_PLATFORMS := MacOSX DriverKit $(SUPPORTED_SIMULATOR_PLATFORMS) $(SUPPORTED_EMBEDDED_PLATFORMS)
153
154 # Platform-specific tools
155 ifneq ($(filter $(SUPPORTED_EMBEDDED_PLATFORMS),$(PLATFORM)),)
156 ifeq ($(EMBEDDED_DEVICE_MAP),)
157 export EMBEDDED_DEVICE_MAP := $(shell $(XCRUN) -sdk $(SDKROOT) -find embedded_device_map)
158 endif
159 EDM_DBPATH ?= $(PLATFORMPATH)/usr/local/standalone/firmware/device_map.db
160 endif
161
162 # Scripts or tools we build ourselves
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 #
172 SEG_HACK = $(OBJROOT)/SETUP/setsegname/setsegname
173 KEXT_CREATE_SYMBOL_SET = $(OBJROOT)/SETUP/kextsymboltool/kextsymboltool
174 DECOMMENT = $(OBJROOT)/SETUP/decomment/decomment
175 NEWVERS = $(SRCROOT)/config/newvers.pl
176 INSTALL = $(OBJROOT)/SETUP/installfile/installfile
177 REPLACECONTENTS = $(OBJROOT)/SETUP/replacecontents/replacecontents
178 JSONCOMPILATIONDB = $(OBJROOT)/SETUP/json_compilation_db/json_compilation_db
179
180 # Standard BSD tools
181 RM = /bin/rm -f
182 RMDIR = /bin/rmdir
183 CP = /bin/cp
184 MV = /bin/mv
185 LN = /bin/ln -fs
186 CAT = /bin/cat
187 MKDIR = /bin/mkdir -p
188 CHMOD = /bin/chmod
189 FIND = /usr/bin/find
190 XARGS = /usr/bin/xargs
191 PAX = /bin/pax
192 BASENAME = /usr/bin/basename
193 DIRNAME = /usr/bin/dirname
194 TR = /usr/bin/tr
195 TOUCH = /usr/bin/touch
196 SLEEP = /bin/sleep
197 AWK = /usr/bin/awk
198 SED = /usr/bin/sed
199 PLUTIL = /usr/bin/plutil
200
201 #
202 # Command to generate host binaries. Intentionally not
203 # $(CC), which controls the target compiler
204 #
205 ifeq ($(HOST_OS_VERSION),)
206 export HOST_OS_VERSION := $(shell sw_vers -productVersion)
207 endif
208 ifeq ($(HOST_CC),)
209 export HOST_CC := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find clang)
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
217 ifeq ($(HOST_GM4),)
218 export HOST_GM4 := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find gm4)
219 endif
220 ifeq ($(HOST_CODESIGN),)
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)
225 endif
226
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)), \
242 $(DEFAULT_KERNEL_CONFIG), \
243 $(1) \
244 ), \
245 $(if $(filter DEFAULT,$(2)), \
246 $(DEFAULT_ARCH_CONFIG), \
247 $(2) \
248 ), \
249 $(if $(filter DEFAULT,$(3)), \
250 $(if $(filter DEFAULT,$(2)), \
251 $(DEFAULT_$(DEFAULT_ARCH_CONFIG)_MACHINE_CONFIG), \
252 $(DEFAULT_$(strip $(2))_MACHINE_CONFIG) \
253 ), \
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 \
262 $(call _function_create_build_configs_do_expand, \
263 $(word 1,$(1)), \
264 $(word 2,$(1)), \
265 $(word 3,$(1)), \
266 ) \
267 $(if $(word 4,$(1)), \
268 $(call function_create_build_configs, \
269 $(wordlist 4,$(words $(1)),$(1)) \
270 ), \
271 ) \
272 ) \
273 )
274
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
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, \
320 $(word 1,$(subst ^, ,$(1))), \
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
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
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))
358
359 # vim: set ft=make: