]> git.saurik.com Git - apple/xnu.git/blob - makedefs/MakeInc.cmd
2bbd75c3803ef04fe7c2f17b19d4ca36f3ddd902
[apple/xnu.git] / makedefs / MakeInc.cmd
1 # -*- mode: makefile;-*-
2 #
3 # Copyright (C) 1999-2020 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 # Build Logging and Verbosity
16 #
17
18 ifeq ($(RC_XBS),YES)
19 VERBOSE = YES
20 else
21 VERBOSE = NO
22 endif
23
24 ECHO = echo
25
26 ERR = $(ECHO) > /dev/stderr
27 PRINTF = printf
28
29 QUIET ?= 0
30 ifneq ($(QUIET),0)
31 PRINTF = printf > /dev/null
32 ifeq ($(VERBOSE),YES)
33 override VERBOSE = NO
34 endif
35 endif
36
37 # Helper functions for logging operations.
38 LOG_PFX_LEN = 15
39 LOG_PFX_LEN_ADJ = $(LOG_PFX_LEN)
40 LOG = $(PRINTF) "$2%$4s$(Color0) $3%s$(Color0)\n" "$1"
41
42 CONCISE ?= 0
43 ifneq ($(CONCISE),0)
44 # Concise logging puts all logs on the same line (CSI K to clear and
45 # carriage return).
46 LOG = $(PRINTF) "$2%$4s$(Color0) $3%s$(Color0)\033[K\r" "$1"
47 endif
48
49 _LOG_COMP = $(call LOG,$1,$(ColorC),$(ColorF),$(LOG_PFX_LEN_ADJ))
50 _LOG_HOST = $(call LOG,$1,$(ColorH),$(ColorF),$(LOG_PFX_LEN))
51 _LOG_HOST_LINK = $(call LOG,$1,$(ColorH),$(ColorLF),$(LOG_PFX_LEN))
52
53 # Special operations.
54 LOG_LDFILELIST = $(call LOG,LDFILELIST,$(ColorL),$(ColorLF),$(LOG_PFX_LEN_ADJ))
55 LOG_MIG = $(call LOG,MIG,$(ColorM),$(ColorF),$(LOG_PFX_LEN_ADJ))
56 LOG_LD = $(call LOG,LD,$(ColorL),$(ColorF),$(LOG_PFX_LEN_ADJ))
57
58 # Compiling/machine-specific operations.
59 LOG_CC = $(call _LOG_COMP,CC)
60 LOG_CXX = $(call _LOG_COMP,C++)
61 LOG_AS = $(call _LOG_COMP,AS)
62 LOG_LTO = $(call _LOG_COMP,LTO)
63 LOG_SYMBOLSET = $(call _LOG_COMP,SYMSET)
64 LOG_SYMBOLSETPLIST = $(call _LOG_COMP,SYMSETPLIST)
65
66 # Host-side operations.
67 LOG_IIG = $(call _LOG_HOST,IIG)
68 LOG_HOST_CC = $(call _LOG_HOST,CC)
69 LOG_HOST_LD = $(call _LOG_HOST,LD)
70 LOG_HOST_CODESIGN = $(call _LOG_HOST,CODESIGN)
71 LOG_HOST_BISON = $(call _LOG_HOST,BISON)
72 LOG_HOST_FLEX = $(call _LOG_HOST,FLEX)
73 LOG_INSTALL = $(call _LOG_HOST,INSTALL)
74 LOG_INSTALLSYM = $(call _LOG_HOST,INSTALLSYM)
75 LOG_INSTALLHDR = $(call _LOG_HOST,INSTALLHDR)
76 LOG_INSTALLMACROS = $(call _LOG_HOST,INSTALLMACROS)
77 LOG_INSTALLPY = $(call _LOG_HOST,INSTALLPY)
78 LOG_MAN = $(call _LOG_HOST,MAN)
79 LOG_MANLINK = $(call _LOG_HOST,MANLINK)
80 LOG_ALIAS = $(call _LOG_HOST,ALIAS)
81 LOG_STRIP = $(call _LOG_HOST,STRIP)
82 LOG_DSYMUTIL = $(call _LOG_HOST,DSYMUTIL)
83 LOG_LIBTOOL = $(call _LOG_HOST,LIBTOOL)
84
85 # Host-side linking operations.
86 LOG_GENASSYM = $(call _LOG_HOST_LINK,GENASSYM)
87 LOG_GENERATE= $(call _LOG_HOST_LINK,GENERATE)
88 LOG_CTFCONVERT = $(call _LOG_HOST_LINK,CTFCONVERT)
89 LOG_CTFMERGE = $(call _LOG_HOST_LINK,CTFMERGE)
90 LOG_CTFINSERT = $(call _LOG_HOST_LINK,CTFINSERT)
91 LOG_DSYMUTIL = $(call _LOG_HOST_LINK,DSYMUTIL)
92 LOG_SUPPORTED_KPI = $(call _LOG_HOST_LINK,SUPPORTED_KPI)
93
94 ifeq ($(VERBOSE),YES)
95 _v =
96 _vstdout =
97 _vstderr =
98 XCRUN = /usr/bin/xcrun -verbose
99 else
100 _v = @
101 _vstdout = > /dev/null
102 _vstderr = 2&> /dev/null
103 XCRUN = /usr/bin/xcrun
104 endif
105
106 VERBOSE_GENERATED_MAKE_FRAGMENTS = NO
107
108 #
109 # Defaults
110 #
111
112 SDKROOT ?= macosx
113 HOST_SDKROOT ?= macosx
114
115 # SDKROOT may be passed as a shorthand like "iphoneos.internal". We
116 # must resolve these to a full path and override SDKROOT.
117
118 ifeq ($(SDKROOT_RESOLVED),)
119 export SDKROOT_RESOLVED := $(shell $(XCRUN) -sdk $(SDKROOT) -show-sdk-path)
120 ifeq ($(strip $(SDKROOT)_$(SDKROOT_RESOLVED)),/_)
121 export SDKROOT_RESOLVED := /
122 endif
123 endif
124 override SDKROOT = $(SDKROOT_RESOLVED)
125
126 ifeq ($(HOST_SDKROOT_RESOLVED),)
127 export HOST_SDKROOT_RESOLVED := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -show-sdk-path)
128 ifeq ($(strip $(HOST_SDKROOT_RESOLVED)),)
129 export HOST_SDKROOT_RESOLVED := /
130 endif
131 endif
132 override HOST_SDKROOT = $(HOST_SDKROOT_RESOLVED)
133
134 ifeq ($(PLATFORM),)
135 export PLATFORMPATH := $(shell $(XCRUN) -sdk $(SDKROOT) -show-sdk-platform-path)
136 export PLATFORM := $(shell echo $(PLATFORMPATH) | sed 's,^.*/\([^/]*\)\.platform$$,\1,')
137 ifeq ($(PLATFORM),)
138 export PLATFORM := MacOSX
139 else ifeq ($(shell echo $(PLATFORM) | tr A-Z a-z),watchos)
140 export PLATFORM := WatchOS
141 endif
142 endif
143
144 ifeq ($(PLATFORM),MacOSX)
145 ifeq (DriverKit,$(shell echo $(SDKROOT_RESOLVED) | sed 's,^.*/\([^/1-9]*\)[1-9][^/]*\.sdk$$,\1,'))
146 export PLATFORM := DriverKit
147 export DRIVERKIT ?= 1
148 export DRIVERKITROOT ?= /System/DriverKit
149 export DRIVERKITRUNTIMEROOT = $(DRIVERKITROOT)/Runtime
150 endif
151 endif
152
153 ifeq ($(SDKVERSION),)
154 export SDKVERSION := $(shell $(XCRUN) -sdk $(SDKROOT) -show-sdk-version)
155 endif
156
157 # CC/CXX get defined by make(1) by default, so we can't check them
158 # against the empty string to see if they haven't been set
159 ifeq ($(origin CC),default)
160 export CC := $(shell $(XCRUN) -sdk $(SDKROOT) -find clang)
161 endif
162 ifeq ($(origin CXX),default)
163 export CXX := $(shell $(XCRUN) -sdk $(SDKROOT) -find clang++)
164 endif
165 ifeq ($(MIG),)
166 export MIG := $(shell $(XCRUN) -sdk $(SDKROOT) -find mig)
167 endif
168 ifeq ($(MIGCOM),)
169 export MIGCOM := $(shell $(XCRUN) -sdk $(SDKROOT) -find migcom)
170 endif
171 ifeq ($(MIGCC),)
172 export MIGCC := $(CC)
173 endif
174 ifeq ($(IIG),)
175 export IIG := $(shell $(XCRUN) -sdk $(SDKROOT) -find iig)
176 endif
177 ifeq ($(STRIP),)
178 export STRIP := $(shell $(XCRUN) -sdk $(SDKROOT) -find strip)
179 endif
180 ifeq ($(LIPO),)
181 export LIPO := $(shell $(XCRUN) -sdk $(SDKROOT) -find lipo)
182 endif
183 ifeq ($(LIBTOOL),)
184 export LIBTOOL := $(shell $(XCRUN) -sdk $(SDKROOT) -find libtool)
185 endif
186 ifeq ($(NM),)
187 export NM := $(shell $(XCRUN) -sdk $(SDKROOT) -find nm)
188 endif
189 ifeq ($(UNIFDEF),)
190 export UNIFDEF := $(shell $(XCRUN) -sdk $(SDKROOT) -find unifdef)
191 endif
192 ifeq ($(DSYMUTIL),)
193 export DSYMUTIL := $(shell $(XCRUN) -sdk $(SDKROOT) -find dsymutil)
194 endif
195 ifeq ($(CTFCONVERT),)
196 export CTFCONVERT := $(shell $(XCRUN) -sdk $(SDKROOT) -find ctfconvert)
197 endif
198 ifeq ($(CTFMERGE),)
199 export CTFMERGE := $(shell $(XCRUN) -sdk $(SDKROOT) -find ctfmerge)
200 endif
201 ifeq ($(CTFINSERT),)
202 export CTFINSERT := $(shell $(XCRUN) -sdk $(SDKROOT) -find ctf_insert)
203 endif
204 ifeq ($(NMEDIT),)
205 export NMEDIT := $(shell $(XCRUN) -sdk $(SDKROOT) -find nmedit)
206 endif
207
208 #
209 # Platform options
210 #
211 SUPPORTED_EMBEDDED_PLATFORMS := iPhoneOS iPhoneOSNano tvOS AppleTVOS WatchOS BridgeOS
212 SUPPORTED_SIMULATOR_PLATFORMS := iPhoneSimulator iPhoneNanoSimulator tvSimulator AppleTVSimulator WatchSimulator
213 SUPPORTED_PLATFORMS := MacOSX DriverKit $(SUPPORTED_SIMULATOR_PLATFORMS) $(SUPPORTED_EMBEDDED_PLATFORMS)
214
215 # Platform-specific tools
216 EDM_DBPATH ?= $(PLATFORMPATH)/usr/local/standalone/firmware/device_map.db
217
218 # Scripts or tools we build ourselves
219 #
220 # setsegname - Rename segments in a Mach-O object file
221 # kextsymboltool - Create kext pseudo-kext Mach-O kexts binaries
222 # decomment - Strip out comments to detect whether a file is comments-only
223 # installfile - Atomically copy files, esp. when multiple architectures
224 # are trying to install the same target header
225 # replacecontents - Write contents to a file and update modtime *only* if
226 # contents differ
227 #
228 SEG_HACK = $(OBJROOT)/SETUP/setsegname/setsegname
229 KEXT_CREATE_SYMBOL_SET = $(OBJROOT)/SETUP/kextsymboltool/kextsymboltool
230 DECOMMENT = $(OBJROOT)/SETUP/decomment/decomment
231 NEWVERS = $(SRCROOT)/config/newvers.pl
232 INSTALL = $(OBJROOT)/SETUP/installfile/installfile
233 REPLACECONTENTS = $(OBJROOT)/SETUP/replacecontents/replacecontents
234 JSONCOMPILATIONDB = $(OBJROOT)/SETUP/json_compilation_db/json_compilation_db
235
236 # Standard BSD tools
237 RM = /bin/rm -f
238 RMDIR = /bin/rmdir
239 CP = /bin/cp
240 MV = /bin/mv
241 LN = /bin/ln -fs
242 CAT = /bin/cat
243 MKDIR = /bin/mkdir -p
244 CHMOD = /bin/chmod
245 FIND = /usr/bin/find
246 XARGS = /usr/bin/xargs
247 PAX = /bin/pax
248 BASENAME = /usr/bin/basename
249 DIRNAME = /usr/bin/dirname
250 TR = /usr/bin/tr
251 TOUCH = /usr/bin/touch
252 SLEEP = /bin/sleep
253 AWK = /usr/bin/awk
254 SED = /usr/bin/sed
255 PLUTIL = /usr/bin/plutil
256
257 #
258 # Command to generate host binaries. Intentionally not
259 # $(CC), which controls the target compiler
260 #
261 ifeq ($(HOST_OS_VERSION),)
262 export HOST_OS_VERSION := $(shell sw_vers -productVersion)
263 endif
264 ifeq ($(HOST_CC),)
265 export HOST_CC := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find clang)
266 endif
267 ifeq ($(HOST_FLEX),)
268 export HOST_FLEX := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find flex)
269 endif
270 ifeq ($(HOST_BISON),)
271 export HOST_BISON := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find bison)
272 endif
273 ifeq ($(HOST_GM4),)
274 export HOST_GM4 := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find gm4)
275 endif
276 ifeq ($(HOST_CODESIGN),)
277 export HOST_CODESIGN := /usr/bin/codesign
278 endif
279 ifeq ($(HOST_CODESIGN_ALLOCATE),)
280 export HOST_CODESIGN_ALLOCATE := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find codesign_allocate)
281 endif
282
283 #
284 # The following variables are functions invoked with "call", and thus
285 # behave similarly to externally compiled commands
286 #
287
288 # $(1) is an expanded kernel config from a TARGET_CONFIGS_UC tuple
289 # $(2) is an expanded arch config from a TARGET_CONFIGS_UC tuple
290 # $(3) is an expanded machine config from a TARGET_CONFIGS_UC tuple
291 _function_create_build_configs_join = $(strip $(1))^$(strip $(2))^$(strip $(3))
292
293 # $(1) is an un-expanded kernel config from a TARGET_CONFIGS_UC tuple
294 # $(2) is an un-expanded arch config from a TARGET_CONFIGS_UC tuple
295 # $(3) is an un-expanded machine config from a TARGET_CONFIGS_UC tuple
296 _function_create_build_configs_do_expand = $(call _function_create_build_configs_join, \
297 $(if $(filter DEFAULT,$(1)), \
298 $(DEFAULT_KERNEL_CONFIG), \
299 $(1) \
300 ), \
301 $(if $(filter DEFAULT,$(2)), \
302 $(DEFAULT_ARCH_CONFIG), \
303 $(2) \
304 ), \
305 $(if $(filter DEFAULT,$(3)), \
306 $(if $(filter DEFAULT,$(2)), \
307 $(DEFAULT_$(DEFAULT_ARCH_CONFIG)_MACHINE_CONFIG), \
308 $(DEFAULT_$(strip $(2))_MACHINE_CONFIG) \
309 ), \
310 $(3) \
311 ) \
312 )
313
314 # $(1) is an un-expanded TARGET_CONFIGS_UC list, which must be consumed
315 # 3 elements at a time
316 function_create_build_configs = $(sort \
317 $(strip \
318 $(call _function_create_build_configs_do_expand, \
319 $(word 1,$(1)), \
320 $(word 2,$(1)), \
321 $(word 3,$(1)), \
322 ) \
323 $(if $(word 4,$(1)), \
324 $(call function_create_build_configs, \
325 $(wordlist 4,$(words $(1)),$(1)) \
326 ), \
327 ) \
328 ) \
329 )
330
331 # Similar to build configs, but alias configs are a 4-tuple
332
333 # $(1) is an expanded kernel config from a TARGET_CONFIGS_ALIASES_UC tuple
334 # $(2) is an expanded arch config from a TARGET_CONFIGS_ALIASES_UC tuple
335 # $(3) is an expanded kernel machine config from a TARGET_CONFIGS_ALIASES_UC tuple
336 # $(4) is an expanded SoC platform config from a TARGET_CONFIGS_ALIASES_UC tuple,
337 # which should be an alias of $(3)
338 _function_create_alias_configs_join = $(strip $(1))^$(strip $(2))^$(strip $(3))^$(strip $(4))
339
340 _function_create_alias_configs_do_expand = $(call _function_create_alias_configs_join, \
341 $(if $(filter DEFAULT,$(1)), \
342 $(DEFAULT_KERNEL_CONFIG), \
343 $(1) \
344 ), \
345 $(if $(filter DEFAULT,$(2)), \
346 $(DEFAULT_ARCH_CONFIG), \
347 $(2) \
348 ), \
349 $(3), \
350 $(4) \
351 )
352
353 function_create_alias_configs = $(sort \
354 $(strip \
355 $(call _function_create_alias_configs_do_expand, \
356 $(word 1,$(1)), \
357 $(word 2,$(1)), \
358 $(word 3,$(1)), \
359 $(word 4,$(1)), \
360 ) \
361 $(if $(word 5,$(1)), \
362 $(call function_create_alias_configs, \
363 $(wordlist 5,$(words $(1)),$(1)) \
364 ), \
365 ) \
366 ) \
367 )
368
369 # $(1) is a fully-expanded kernel config
370 # $(2) is a fully-expanded arch config
371 # $(3) is a fully-expanded machine config. "NONE" is not represented in the objdir path
372 function_convert_target_config_uc_to_objdir = $(if $(filter NONE,$(3)),$(strip $(1))_$(strip $(2)),$(strip $(1))_$(strip $(2))_$(strip $(3)))
373
374 # $(1) is a fully-expanded build config (like "RELEASE^X86_64^NONE")
375 function_convert_build_config_to_objdir = $(call function_convert_target_config_uc_to_objdir, \
376 $(word 1,$(subst ^, ,$(1))), \
377 $(word 2,$(subst ^, ,$(1))), \
378 $(word 3,$(subst ^, ,$(1))) \
379 )
380
381 # $(1) is a fully-expanded build config (like "RELEASE^X86_64^NONE")
382 function_extract_kernel_config_from_build_config = $(word 1,$(subst ^, ,$(1)))
383 function_extract_arch_config_from_build_config = $(word 2,$(subst ^, ,$(1)))
384 function_extract_machine_config_from_build_config = $(word 3,$(subst ^, ,$(1)))
385
386 # $(1) is an input word
387 # $(2) is a list of colon-separate potential substitutions like "FOO:BAR BAZ:QUX"
388 # $(3) is a fallback if no substitutions were made
389 function_substitute_word_with_replacement = $(strip $(if $(2), \
390 $(if $(filter $(word 1,$(subst :, ,$(word 1,$(2)))),$(1)), \
391 $(word 2,$(subst :, ,$(word 1,$(2)))), \
392 $(call function_substitute_word_with_replacement,$(1),$(wordlist 2,$(words $(2)),$(2)),$(3))), \
393 $(3) \
394 ) \
395 )
396
397 # You can't assign a variable to an empty space without these
398 # shenanigans
399 empty :=
400 space := $(empty) $(empty)
401
402 # Arithmetic
403 # $(1) is the number to increment
404 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
405 increment = $(words x $(wordlist 1,$(1),$(NUM32)))
406 decrement = $(words $(wordlist 2,$(1),$(NUM32)))
407
408 # Create a sequence from 1 to $(1)
409 # F(N) = if N > 0: return F(N-1) + "N" else: return ""
410 sequence = $(if $(wordlist 1,$(1),$(NUM32)),$(call sequence,$(call decrement,$(1))) $(1),)
411
412 # Reverse a list of words in $(1)
413 reverse = $(if $(word 2,$(1)),$(call reverse,$(wordlist 2,$(words $(1)),$(1)))) $(word 1,$(1))
414
415 # vim: set ft=make: