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
26 _vstdout = > /dev/null
29 VERBOSE_GENERATED_MAKE_FRAGMENTS = NO
32 XCRUN = /usr/bin/xcrun -verbose
34 XCRUN = /usr/bin/xcrun
38 HOST_SDKROOT ?= macosx
40 # SDKROOT may be passed as a shorthand like "iphoneos.internal". We
41 # must resolve these to a full path and override SDKROOT.
43 ifeq ($(SDKROOT_RESOLVED),)
44 export SDKROOT_RESOLVED := $(shell $(XCRUN) -sdk $(SDKROOT) -show-sdk-path)
45 ifeq ($(strip $(SDKROOT)_$(SDKROOT_RESOLVED)),/_)
46 export SDKROOT_RESOLVED := /
49 override SDKROOT = $(SDKROOT_RESOLVED)
51 ifeq ($(HOST_SDKROOT_RESOLVED),)
52 export HOST_SDKROOT_RESOLVED := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -show-sdk-path)
53 ifeq ($(strip $(HOST_SDKROOT_RESOLVED)),)
54 export HOST_SDKROOT_RESOLVED := /
57 override HOST_SDKROOT = $(HOST_SDKROOT_RESOLVED)
60 export PLATFORMPATH := $(shell $(XCRUN) -sdk $(SDKROOT) -show-sdk-platform-path)
61 export PLATFORM := $(shell echo $(PLATFORMPATH) | sed 's,^.*/\([^/]*\)\.platform$$,\1,')
63 export PLATFORM := MacOSX
64 else ifeq ($(shell echo $(PLATFORM) | tr A-Z a-z),watchos)
65 export PLATFORM := WatchOS
70 export SDKVERSION := $(shell $(XCRUN) -sdk $(SDKROOT) -show-sdk-version)
73 # CC/CXX get defined by make(1) by default, so we can't check them
74 # against the empty string to see if they haven't been set
75 ifeq ($(origin CC),default)
76 export CC := $(shell $(XCRUN) -sdk $(SDKROOT) -find clang)
78 ifeq ($(origin CXX),default)
79 export CXX := $(shell $(XCRUN) -sdk $(SDKROOT) -find clang++)
82 export MIG := $(shell $(XCRUN) -sdk $(SDKROOT) -find mig)
85 export MIGCOM := $(shell $(XCRUN) -sdk $(SDKROOT) -find migcom)
91 export STRIP := $(shell $(XCRUN) -sdk $(SDKROOT) -find strip)
94 export LIPO := $(shell $(XCRUN) -sdk $(SDKROOT) -find lipo)
97 export LIBTOOL := $(shell $(XCRUN) -sdk $(SDKROOT) -find libtool)
100 export NM := $(shell $(XCRUN) -sdk $(SDKROOT) -find nm)
103 export UNIFDEF := $(shell $(XCRUN) -sdk $(SDKROOT) -find unifdef)
106 export DSYMUTIL := $(shell $(XCRUN) -sdk $(SDKROOT) -find dsymutil)
108 ifeq ($(CTFCONVERT),)
109 export CTFCONVERT := $(shell $(XCRUN) -sdk $(SDKROOT) -find ctfconvert)
112 export CTFMERGE := $(shell $(XCRUN) -sdk $(SDKROOT) -find ctfmerge)
115 export CTFINSERT := $(shell $(XCRUN) -sdk $(SDKROOT) -find ctf_insert)
118 export NMEDIT := $(shell $(XCRUN) -sdk $(SDKROOT) -find nmedit)
124 SUPPORTED_EMBEDDED_PLATFORMS := iPhoneOS iPhoneOSNano tvOS AppleTVOS WatchOS BridgeOS
125 SUPPORTED_SIMULATOR_PLATFORMS := iPhoneSimulator iPhoneNanoSimulator tvSimulator AppleTVSimulator WatchSimulator
126 SUPPORTED_PLATFORMS := MacOSX $(SUPPORTED_SIMULATOR_PLATFORMS) $(SUPPORTED_EMBEDDED_PLATFORMS)
128 # Platform-specific tools
129 ifneq ($(filter $(SUPPORTED_EMBEDDED_PLATFORMS),$(PLATFORM)),)
130 ifeq ($(EMBEDDED_DEVICE_MAP),)
131 export EMBEDDED_DEVICE_MAP := $(shell $(XCRUN) -sdk $(SDKROOT) -find embedded_device_map)
133 EDM_DBPATH ?= $(PLATFORMPATH)/usr/local/standalone/firmware/device_map.db
136 # Scripts or tools we build ourselves
138 # setsegname - Rename segments in a Mach-O object file
139 # kextsymboltool - Create kext pseudo-kext Mach-O kexts binaries
140 # decomment - Strip out comments to detect whether a file is comments-only
141 # installfile - Atomically copy files, esp. when multiple architectures
142 # are trying to install the same target header
143 # replacecontents - Write contents to a file and update modtime *only* if
146 SEG_HACK = $(OBJROOT)/SETUP/setsegname/setsegname
147 KEXT_CREATE_SYMBOL_SET = $(OBJROOT)/SETUP/kextsymboltool/kextsymboltool
148 DECOMMENT = $(OBJROOT)/SETUP/decomment/decomment
149 NEWVERS = $(SRCROOT)/config/newvers.pl
150 INSTALL = $(OBJROOT)/SETUP/installfile/installfile
151 REPLACECONTENTS = $(OBJROOT)/SETUP/replacecontents/replacecontents
152 JSONCOMPILATIONDB = $(OBJROOT)/SETUP/json_compilation_db/json_compilation_db
161 MKDIR = /bin/mkdir -p
164 XARGS = /usr/bin/xargs
166 BASENAME = /usr/bin/basename
167 DIRNAME = /usr/bin/dirname
169 TOUCH = /usr/bin/touch
174 PLUTIL = /usr/bin/plutil
177 # Command to generate host binaries. Intentionally not
178 # $(CC), which controls the target compiler
180 ifeq ($(HOST_OS_VERSION),)
181 export HOST_OS_VERSION := $(shell sw_vers -productVersion)
184 export HOST_CC := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find clang)
187 export HOST_FLEX := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find flex)
189 ifeq ($(HOST_BISON),)
190 export HOST_BISON := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find bison)
193 export HOST_GM4 := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find gm4)
195 ifeq ($(HOST_CODESIGN),)
196 export HOST_CODESIGN := /usr/bin/codesign
198 ifeq ($(HOST_CODESIGN_ALLOCATE),)
199 export HOST_CODESIGN_ALLOCATE := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find codesign_allocate)
203 # The following variables are functions invoked with "call", and thus
204 # behave similarly to externally compiled commands
207 # $(1) is an expanded kernel config from a TARGET_CONFIGS_UC tuple
208 # $(2) is an expanded arch config from a TARGET_CONFIGS_UC tuple
209 # $(3) is an expanded machine config from a TARGET_CONFIGS_UC tuple
210 _function_create_build_configs_join = $(strip $(1))^$(strip $(2))^$(strip $(3))
212 # $(1) is an un-expanded kernel config from a TARGET_CONFIGS_UC tuple
213 # $(2) is an un-expanded arch config from a TARGET_CONFIGS_UC tuple
214 # $(3) is an un-expanded machine config from a TARGET_CONFIGS_UC tuple
215 _function_create_build_configs_do_expand = $(call _function_create_build_configs_join, \
216 $(if $(filter DEFAULT,$(1)), \
217 $(DEFAULT_KERNEL_CONFIG), \
220 $(if $(filter DEFAULT,$(2)), \
221 $(DEFAULT_ARCH_CONFIG), \
224 $(if $(filter DEFAULT,$(3)), \
225 $(if $(filter DEFAULT,$(2)), \
226 $(DEFAULT_$(DEFAULT_ARCH_CONFIG)_MACHINE_CONFIG), \
227 $(DEFAULT_$(strip $(2))_MACHINE_CONFIG) \
233 # $(1) is an un-expanded TARGET_CONFIGS_UC list, which must be consumed
234 # 3 elements at a time
235 function_create_build_configs = $(sort \
237 $(call _function_create_build_configs_do_expand, \
242 $(if $(word 4,$(1)), \
243 $(call function_create_build_configs, \
244 $(wordlist 4,$(words $(1)),$(1)) \
250 # Similar to build configs, but alias configs are a 4-tuple
252 # $(1) is an expanded kernel config from a TARGET_CONFIGS_ALIASES_UC tuple
253 # $(2) is an expanded arch config from a TARGET_CONFIGS_ALIASES_UC tuple
254 # $(3) is an expanded kernel machine config from a TARGET_CONFIGS_ALIASES_UC tuple
255 # $(4) is an expanded SoC platform config from a TARGET_CONFIGS_ALIASES_UC tuple,
256 # which should be an alias of $(3)
257 _function_create_alias_configs_join = $(strip $(1))^$(strip $(2))^$(strip $(3))^$(strip $(4))
259 _function_create_alias_configs_do_expand = $(call _function_create_alias_configs_join, \
260 $(if $(filter DEFAULT,$(1)), \
261 $(DEFAULT_KERNEL_CONFIG), \
264 $(if $(filter DEFAULT,$(2)), \
265 $(DEFAULT_ARCH_CONFIG), \
272 function_create_alias_configs = $(sort \
274 $(call _function_create_alias_configs_do_expand, \
280 $(if $(word 5,$(1)), \
281 $(call function_create_alias_configs, \
282 $(wordlist 5,$(words $(1)),$(1)) \
288 # $(1) is a fully-expanded kernel config
289 # $(2) is a fully-expanded arch config
290 # $(3) is a fully-expanded machine config. "NONE" is not represented in the objdir path
291 function_convert_target_config_uc_to_objdir = $(if $(filter NONE,$(3)),$(strip $(1))_$(strip $(2)),$(strip $(1))_$(strip $(2))_$(strip $(3)))
293 # $(1) is a fully-expanded build config (like "RELEASE^X86_64^NONE")
294 function_convert_build_config_to_objdir = $(call function_convert_target_config_uc_to_objdir, \
295 $(word 1,$(subst ^, ,$(1))), \
296 $(word 2,$(subst ^, ,$(1))), \
297 $(word 3,$(subst ^, ,$(1))) \
300 # $(1) is a fully-expanded build config (like "RELEASE^X86_64^NONE")
301 function_extract_kernel_config_from_build_config = $(word 1,$(subst ^, ,$(1)))
302 function_extract_arch_config_from_build_config = $(word 2,$(subst ^, ,$(1)))
303 function_extract_machine_config_from_build_config = $(word 3,$(subst ^, ,$(1)))
305 # $(1) is an input word
306 # $(2) is a list of colon-separate potential substitutions like "FOO:BAR BAZ:QUX"
307 # $(3) is a fallback if no substitutions were made
308 function_substitute_word_with_replacement = $(strip $(if $(2), \
309 $(if $(filter $(word 1,$(subst :, ,$(word 1,$(2)))),$(1)), \
310 $(word 2,$(subst :, ,$(word 1,$(2)))), \
311 $(call function_substitute_word_with_replacement,$(1),$(wordlist 2,$(words $(2)),$(2)),$(3))), \
316 # You can't assign a variable to an empty space without these
319 space := $(empty) $(empty)
322 # $(1) is the number to increment
323 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
324 increment = $(words x $(wordlist 1,$(1),$(NUM32)))
325 decrement = $(words $(wordlist 2,$(1),$(NUM32)))
327 # Create a sequence from 1 to $(1)
328 # F(N) = if N > 0: return F(N-1) + "N" else: return ""
329 sequence = $(if $(wordlist 1,$(1),$(NUM32)),$(call sequence,$(call decrement,$(1))) $(1),)
331 # Reverse a list of words in $(1)
332 reverse = $(if $(word 2,$(1)),$(call reverse,$(wordlist 2,$(words $(1)),$(1)))) $(word 1,$(1))