1 # -*- mode: makefile;-*-
3 # Copyright (C) 1999-2016 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
28 ERR = $(ECHO) > /dev/stderr
42 XCRUN = /usr/bin/xcrun -verbose
45 _vstdout = > /dev/null
46 XCRUN = /usr/bin/xcrun
49 VERBOSE_GENERATED_MAKE_FRAGMENTS = NO
52 HOST_SDKROOT ?= macosx
54 # SDKROOT may be passed as a shorthand like "iphoneos.internal". We
55 # must resolve these to a full path and override SDKROOT.
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 := /
63 override SDKROOT = $(SDKROOT_RESOLVED)
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 := /
71 override HOST_SDKROOT = $(HOST_SDKROOT_RESOLVED)
74 export PLATFORMPATH := $(shell $(XCRUN) -sdk $(SDKROOT) -show-sdk-platform-path)
75 export PLATFORM := $(shell echo $(PLATFORMPATH) | sed 's,^.*/\([^/]*\)\.platform$$,\1,')
77 export PLATFORM := MacOSX
78 else ifeq ($(shell echo $(PLATFORM) | tr A-Z a-z),watchos)
79 export PLATFORM := WatchOS
83 ifeq ($(PLATFORM),MacOSX)
84 ifeq (DriverKit,$(shell echo $(SDKROOT_RESOLVED) | sed 's,^.*/\([^/1-9]*\)[1-9][^/]*\.sdk$$,\1,'))
85 export PLATFORM := DriverKit
87 export DRIVERKITROOT ?= /System/DriverKit
88 export DRIVERKITRUNTIMEROOT = $(DRIVERKITROOT)/Runtime
93 export SDKVERSION := $(shell $(XCRUN) -sdk $(SDKROOT) -show-sdk-version)
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)
101 ifeq ($(origin CXX),default)
102 export CXX := $(shell $(XCRUN) -sdk $(SDKROOT) -find clang++)
105 export MIG := $(shell $(XCRUN) -sdk $(SDKROOT) -find mig)
108 export MIGCOM := $(shell $(XCRUN) -sdk $(SDKROOT) -find migcom)
111 export MIGCC := $(CC)
114 export IIG := $(shell $(XCRUN) -sdk $(SDKROOT) -find iig)
117 export STRIP := $(shell $(XCRUN) -sdk $(SDKROOT) -find strip)
120 export LIPO := $(shell $(XCRUN) -sdk $(SDKROOT) -find lipo)
123 export LIBTOOL := $(shell $(XCRUN) -sdk $(SDKROOT) -find libtool)
126 export NM := $(shell $(XCRUN) -sdk $(SDKROOT) -find nm)
129 export UNIFDEF := $(shell $(XCRUN) -sdk $(SDKROOT) -find unifdef)
132 export DSYMUTIL := $(shell $(XCRUN) -sdk $(SDKROOT) -find dsymutil)
134 ifeq ($(CTFCONVERT),)
135 export CTFCONVERT := $(shell $(XCRUN) -sdk $(SDKROOT) -find ctfconvert)
138 export CTFMERGE := $(shell $(XCRUN) -sdk $(SDKROOT) -find ctfmerge)
141 export CTFINSERT := $(shell $(XCRUN) -sdk $(SDKROOT) -find ctf_insert)
144 export NMEDIT := $(shell $(XCRUN) -sdk $(SDKROOT) -find nmedit)
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)
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)
159 EDM_DBPATH ?= $(PLATFORMPATH)/usr/local/standalone/firmware/device_map.db
162 # Scripts or tools we build ourselves
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
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
187 MKDIR = /bin/mkdir -p
190 XARGS = /usr/bin/xargs
192 BASENAME = /usr/bin/basename
193 DIRNAME = /usr/bin/dirname
195 TOUCH = /usr/bin/touch
199 PLUTIL = /usr/bin/plutil
202 # Command to generate host binaries. Intentionally not
203 # $(CC), which controls the target compiler
205 ifeq ($(HOST_OS_VERSION),)
206 export HOST_OS_VERSION := $(shell sw_vers -productVersion)
209 export HOST_CC := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find clang)
212 export HOST_FLEX := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find flex)
214 ifeq ($(HOST_BISON),)
215 export HOST_BISON := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find bison)
218 export HOST_GM4 := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find gm4)
220 ifeq ($(HOST_CODESIGN),)
221 export HOST_CODESIGN := /usr/bin/codesign
223 ifeq ($(HOST_CODESIGN_ALLOCATE),)
224 export HOST_CODESIGN_ALLOCATE := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find codesign_allocate)
228 # The following variables are functions invoked with "call", and thus
229 # behave similarly to externally compiled commands
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))
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), \
245 $(if $(filter DEFAULT,$(2)), \
246 $(DEFAULT_ARCH_CONFIG), \
249 $(if $(filter DEFAULT,$(3)), \
250 $(if $(filter DEFAULT,$(2)), \
251 $(DEFAULT_$(DEFAULT_ARCH_CONFIG)_MACHINE_CONFIG), \
252 $(DEFAULT_$(strip $(2))_MACHINE_CONFIG) \
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 \
262 $(call _function_create_build_configs_do_expand, \
267 $(if $(word 4,$(1)), \
268 $(call function_create_build_configs, \
269 $(wordlist 4,$(words $(1)),$(1)) \
275 # Similar to build configs, but alias configs are a 4-tuple
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))
284 _function_create_alias_configs_do_expand = $(call _function_create_alias_configs_join, \
285 $(if $(filter DEFAULT,$(1)), \
286 $(DEFAULT_KERNEL_CONFIG), \
289 $(if $(filter DEFAULT,$(2)), \
290 $(DEFAULT_ARCH_CONFIG), \
297 function_create_alias_configs = $(sort \
299 $(call _function_create_alias_configs_do_expand, \
305 $(if $(word 5,$(1)), \
306 $(call function_create_alias_configs, \
307 $(wordlist 5,$(words $(1)),$(1)) \
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)))
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))) \
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)))
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))), \
341 # You can't assign a variable to an empty space without these
344 space := $(empty) $(empty)
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)))
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),)
356 # Reverse a list of words in $(1)
357 reverse = $(if $(word 2,$(1)),$(call reverse,$(wordlist 2,$(words $(1)),$(1)))) $(word 1,$(1))