1 # -*- mode: makefile;-*-
3 # Copyright (C) 1999-2020 Apple Inc. All rights reserved.
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.
11 # Commands for the build environment
15 # Build Logging and Verbosity
26 ERR = $(ECHO) > /dev/stderr
31 PRINTF = printf > /dev/null
37 # Helper functions for logging operations.
39 LOG_PFX_LEN_ADJ = $(LOG_PFX_LEN)
40 LOG = $(PRINTF) "$2%$4s$(Color0) $3%s$(Color0)\n" "$1"
44 # Concise logging puts all logs on the same line (CSI K to clear and
46 LOG = $(PRINTF) "$2%$4s$(Color0) $3%s$(Color0)\033[K\r" "$1"
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))
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))
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)
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)
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)
98 XCRUN = /usr/bin/xcrun -verbose
101 _vstdout = > /dev/null
102 _vstderr = 2&> /dev/null
103 XCRUN = /usr/bin/xcrun
106 VERBOSE_GENERATED_MAKE_FRAGMENTS = NO
113 HOST_SDKROOT ?= macosx
115 # SDKROOT may be passed as a shorthand like "iphoneos.internal". We
116 # must resolve these to a full path and override SDKROOT.
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 := /
124 override SDKROOT = $(SDKROOT_RESOLVED)
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 := /
132 override HOST_SDKROOT = $(HOST_SDKROOT_RESOLVED)
135 export PLATFORMPATH := $(shell $(XCRUN) -sdk $(SDKROOT) -show-sdk-platform-path)
136 export PLATFORM := $(shell echo $(PLATFORMPATH) | sed 's,^.*/\([^/]*\)\.platform$$,\1,')
138 export PLATFORM := MacOSX
139 else ifeq ($(shell echo $(PLATFORM) | tr A-Z a-z),watchos)
140 export PLATFORM := WatchOS
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
153 ifeq ($(SDKVERSION),)
154 export SDKVERSION := $(shell $(XCRUN) -sdk $(SDKROOT) -show-sdk-version)
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)
162 ifeq ($(origin CXX),default)
163 export CXX := $(shell $(XCRUN) -sdk $(SDKROOT) -find clang++)
166 export MIG := $(shell $(XCRUN) -sdk $(SDKROOT) -find mig)
169 export MIGCOM := $(shell $(XCRUN) -sdk $(SDKROOT) -find migcom)
172 export MIGCC := $(CC)
175 export IIG := $(shell $(XCRUN) -sdk $(SDKROOT) -find iig)
178 export STRIP := $(shell $(XCRUN) -sdk $(SDKROOT) -find strip)
181 export LIPO := $(shell $(XCRUN) -sdk $(SDKROOT) -find lipo)
184 export LIBTOOL := $(shell $(XCRUN) -sdk $(SDKROOT) -find libtool)
187 export NM := $(shell $(XCRUN) -sdk $(SDKROOT) -find nm)
190 export UNIFDEF := $(shell $(XCRUN) -sdk $(SDKROOT) -find unifdef)
193 export DSYMUTIL := $(shell $(XCRUN) -sdk $(SDKROOT) -find dsymutil)
195 ifeq ($(CTFCONVERT),)
196 export CTFCONVERT := $(shell $(XCRUN) -sdk $(SDKROOT) -find ctfconvert)
199 export CTFMERGE := $(shell $(XCRUN) -sdk $(SDKROOT) -find ctfmerge)
202 export CTFINSERT := $(shell $(XCRUN) -sdk $(SDKROOT) -find ctf_insert)
205 export NMEDIT := $(shell $(XCRUN) -sdk $(SDKROOT) -find nmedit)
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)
215 # Platform-specific tools
216 EDM_DBPATH ?= $(PLATFORMPATH)/usr/local/standalone/firmware/device_map.db
218 # Scripts or tools we build ourselves
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
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
243 MKDIR = /bin/mkdir -p
246 XARGS = /usr/bin/xargs
248 BASENAME = /usr/bin/basename
249 DIRNAME = /usr/bin/dirname
251 TOUCH = /usr/bin/touch
255 PLUTIL = /usr/bin/plutil
258 # Command to generate host binaries. Intentionally not
259 # $(CC), which controls the target compiler
261 ifeq ($(HOST_OS_VERSION),)
262 export HOST_OS_VERSION := $(shell sw_vers -productVersion)
265 export HOST_CC := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find clang)
268 export HOST_FLEX := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find flex)
270 ifeq ($(HOST_BISON),)
271 export HOST_BISON := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find bison)
274 export HOST_GM4 := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find gm4)
276 ifeq ($(HOST_CODESIGN),)
277 export HOST_CODESIGN := /usr/bin/codesign
279 ifeq ($(HOST_CODESIGN_ALLOCATE),)
280 export HOST_CODESIGN_ALLOCATE := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find codesign_allocate)
284 # The following variables are functions invoked with "call", and thus
285 # behave similarly to externally compiled commands
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))
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), \
301 $(if $(filter DEFAULT,$(2)), \
302 $(DEFAULT_ARCH_CONFIG), \
305 $(if $(filter DEFAULT,$(3)), \
306 $(if $(filter DEFAULT,$(2)), \
307 $(DEFAULT_$(DEFAULT_ARCH_CONFIG)_MACHINE_CONFIG), \
308 $(DEFAULT_$(strip $(2))_MACHINE_CONFIG) \
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 \
318 $(call _function_create_build_configs_do_expand, \
323 $(if $(word 4,$(1)), \
324 $(call function_create_build_configs, \
325 $(wordlist 4,$(words $(1)),$(1)) \
331 # Similar to build configs, but alias configs are a 4-tuple
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))
340 _function_create_alias_configs_do_expand = $(call _function_create_alias_configs_join, \
341 $(if $(filter DEFAULT,$(1)), \
342 $(DEFAULT_KERNEL_CONFIG), \
345 $(if $(filter DEFAULT,$(2)), \
346 $(DEFAULT_ARCH_CONFIG), \
353 function_create_alias_configs = $(sort \
355 $(call _function_create_alias_configs_do_expand, \
361 $(if $(word 5,$(1)), \
362 $(call function_create_alias_configs, \
363 $(wordlist 5,$(words $(1)),$(1)) \
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)))
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))) \
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)))
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))), \
397 # You can't assign a variable to an empty space without these
400 space := $(empty) $(empty)
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)))
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),)
412 # Reverse a list of words in $(1)
413 reverse = $(if $(word 2,$(1)),$(call reverse,$(wordlist 2,$(words $(1)),$(1)))) $(word 1,$(1))