1 # -*- mode: makefile;-*-
3 # Copyright (C) 1999-2012 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
30 XCRUN = /usr/bin/xcrun -verbose
32 XCRUN = /usr/bin/xcrun
36 HOST_SDKROOT ?= macosx
37 HOST_SPARSE_SDKROOT ?= /
39 # SDKROOT may be passed as a shorthand like "iphoneos.internal". We
40 # must resolve these to a full path and override SDKROOT.
42 ifeq ($(SDKROOT_RESOLVED),)
43 export SDKROOT_RESOLVED := $(shell $(XCRUN) -sdk $(SDKROOT) -show-sdk-path)
44 ifeq ($(strip $(SDKROOT)_$(SDKROOT_RESOLVED)),/_)
45 export SDKROOT_RESOLVED := /
48 override SDKROOT = $(SDKROOT_RESOLVED)
50 ifeq ($(HOST_SDKROOT_RESOLVED),)
51 export HOST_SDKROOT_RESOLVED := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -show-sdk-path)
53 override HOST_SDKROOT = $(HOST_SDKROOT_RESOLVED)
56 export PLATFORMPATH := $(shell $(XCRUN) -sdk $(SDKROOT) -show-sdk-platform-path)
57 export PLATFORM := $(shell echo $(PLATFORMPATH) | sed 's,^.*/\([^/]*\)\.platform$$,\1,')
59 export PLATFORM := MacOSX
64 export SDKVERSION := $(shell $(XCRUN) -sdk $(SDKROOT) -show-sdk-version)
67 ifeq ($(PLATFORM),iPhoneOS)
68 ifeq ($(HOST_SPARSE_SDKROOT),/)
69 export HOST_SPARSE_SDKROOT := $(shell $(XCRUN) -sdk iphonehost.internal -show-sdk-path)
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)
121 # Platform-specific tools
122 ifeq (iPhoneOS,$(PLATFORM))
123 ifeq ($(EMBEDDED_DEVICE_MAP),)
124 export EMBEDDED_DEVICE_MAP := $(shell $(XCRUN) -sdk $(SDKROOT) -find embedded_device_map)
126 EDM_DBPATH = $(PLATFORMPATH)/usr/local/standalone/firmware/device_map.db
129 # Scripts or tools we build ourselves
130 SEG_HACK = $(OBJROOT)/SETUP/setsegname/setsegname
131 KEXT_CREATE_SYMBOL_SET = $(OBJROOT)/SETUP/kextsymboltool/kextsymboltool
132 DECOMMENT = $(OBJROOT)/SETUP/decomment/decomment
133 NEWVERS = $(SRCROOT)/config/newvers.pl
134 INSTALL = $(OBJROOT)/SETUP/installfile/installfile
143 MKDIR = /bin/mkdir -p
145 XARGS = /usr/bin/xargs
146 TAR = /usr/bin/gnutar
147 BASENAME = /usr/bin/basename
148 DIRNAME = /usr/bin/dirname
150 TOUCH = /usr/bin/touch
154 PLUTIL = /usr/bin/plutil
157 # Command to generate host binaries. Intentionally not
158 # $(CC), which controls the target compiler
160 ifeq ($(HOST_OS_VERSION),)
161 export HOST_OS_VERSION := $(shell sw_vers -productVersion)
164 export HOST_CC := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find clang)
167 export HOST_FLEX := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find flex)
169 ifeq ($(HOST_BISON),)
170 export HOST_BISON := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find bison)
173 export HOST_GM4 := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find gm4)
175 ifeq ($(HOST_CODESIGN),)
176 export HOST_CODESIGN := /usr/bin/codesign
178 ifeq ($(HOST_CODESIGN_ALLOCATE),)
179 export HOST_CODESIGN_ALLOCATE := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find codesign_allocate)
183 # The following variables are functions invoked with "call", and thus
184 # behave similarly to externally compiled commands
187 # $(1) is an expanded kernel config from a TARGET_CONFIGS_UC tuple
188 # $(2) is an expanded arch config from a TARGET_CONFIGS_UC tuple
189 # $(3) is an expanded machine config from a TARGET_CONFIGS_UC tuple
190 _function_create_build_configs_join = $(strip $(1))^$(strip $(2))^$(strip $(3))
192 # $(1) is an un-expanded kernel config from a TARGET_CONFIGS_UC tuple
193 # $(2) is an un-expanded arch config from a TARGET_CONFIGS_UC tuple
194 # $(3) is an un-expanded machine config from a TARGET_CONFIGS_UC tuple
195 _function_create_build_configs_do_expand = $(call _function_create_build_configs_join, \
196 $(if $(filter DEFAULT,$(1)), \
197 $(DEFAULT_KERNEL_CONFIG), \
200 $(if $(filter DEFAULT,$(2)), \
201 $(DEFAULT_ARCH_CONFIG), \
204 $(if $(filter DEFAULT,$(3)), \
205 $(if $(filter DEFAULT,$(2)), \
206 $(DEFAULT_$(DEFAULT_ARCH_CONFIG)_MACHINE_CONFIG), \
207 $(DEFAULT_$(strip $(2))_MACHINE_CONFIG) \
213 # $(1) is an un-expanded TARGET_CONFIGS_UC list, which must be consumed
214 # 3 elements at a time
215 function_create_build_configs = $(sort \
217 $(call _function_create_build_configs_do_expand, \
222 $(if $(word 4,$(1)), \
223 $(call function_create_build_configs, \
224 $(wordlist 4,$(words $(1)),$(1)) \
231 # $(1) is a fully-expanded kernel config
232 # $(2) is a fully-expanded arch config
233 # $(3) is a fully-expanded machine config. "NONE" is not represented in the objdir path
234 function_convert_target_config_uc_to_objdir = $(if $(filter NONE,$(3)),$(strip $(1))_$(strip $(2)),$(strip $(1))_$(strip $(2))_$(strip $(3)))
236 # $(1) is a fully-expanded build config (like "RELEASE^X86_64^NONE")
237 function_convert_build_config_to_objdir = $(call function_convert_target_config_uc_to_objdir, \
238 $(word 1,$(subst ^, ,$(1))), \
239 $(word 2,$(subst ^, ,$(1))), \
240 $(word 3,$(subst ^, ,$(1))) \
243 # $(1) is a fully-expanded build config (like "RELEASE^X86_64^NONE")
244 function_extract_kernel_config_from_build_config = $(word 1,$(subst ^, ,$(1)))
245 function_extract_arch_config_from_build_config = $(word 2,$(subst ^, ,$(1)))
246 function_extract_machine_config_from_build_config = $(word 3,$(subst ^, ,$(1)))
248 # $(1) is an input word
249 # $(2) is a list of colon-separate potential substitutions like "FOO:BAR BAZ:QUX"
250 # $(3) is a fallback if no substitutions were made
251 function_substitute_word_with_replacement = $(strip $(if $(2), \
252 $(if $(filter $(word 1,$(subst :, ,$(word 1,$(2)))),$(1)), \
253 $(word 2,$(subst :, ,$(word 1,$(2)))), \
254 $(call function_substitute_word_with_replacement,$(1),$(wordlist 2,$(words $(2)),$(2)),$(3))), \
259 # You can't assign a variable to an empty space without these
262 space := $(empty) $(empty)
265 # $(1) is the number to increment
266 NUM16 = x x x x x x x x x x x x x x x x
267 increment = $(words x $(wordlist 1,$(1),$(NUM16)))