]> git.saurik.com Git - apple/xnu.git/blame - makedefs/MakeInc.cmd
xnu-3789.21.4.tar.gz
[apple/xnu.git] / makedefs / MakeInc.cmd
CommitLineData
39236c6e
A
1# -*- mode: makefile;-*-
2#
39037602 3# Copyright (C) 1999-2016 Apple Inc. All rights reserved.
39236c6e
A
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
1c79356b
A
10#
11# Commands for the build environment
12#
b0d623f7
A
13##
14# Verbosity
15##
16ifeq ($(RC_XBS),YES)
17VERBOSE = YES
18else
19VERBOSE = NO
20endif
21ifeq ($(VERBOSE),YES)
22_v =
23_vstdout =
24else
25_v = @
26_vstdout = > /dev/null
27endif
1c79356b 28
fe8ab488
A
29VERBOSE_GENERATED_MAKE_FRAGMENTS = NO
30
b0d623f7 31ifeq ($(VERBOSE),YES)
39236c6e 32 XCRUN = /usr/bin/xcrun -verbose
b0d623f7
A
33else
34 XCRUN = /usr/bin/xcrun
35endif
36
fe8ab488 37SDKROOT ?= macosx.internal
39236c6e 38HOST_SDKROOT ?= macosx
316670eb
A
39
40# SDKROOT may be passed as a shorthand like "iphoneos.internal". We
41# must resolve these to a full path and override SDKROOT.
42
43ifeq ($(SDKROOT_RESOLVED),)
39236c6e
A
44export SDKROOT_RESOLVED := $(shell $(XCRUN) -sdk $(SDKROOT) -show-sdk-path)
45ifeq ($(strip $(SDKROOT)_$(SDKROOT_RESOLVED)),/_)
46export SDKROOT_RESOLVED := /
316670eb
A
47endif
48endif
49override SDKROOT = $(SDKROOT_RESOLVED)
b0d623f7 50
39236c6e
A
51ifeq ($(HOST_SDKROOT_RESOLVED),)
52export HOST_SDKROOT_RESOLVED := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -show-sdk-path)
53endif
54override HOST_SDKROOT = $(HOST_SDKROOT_RESOLVED)
55
6d2010ae 56ifeq ($(PLATFORM),)
39236c6e
A
57 export PLATFORMPATH := $(shell $(XCRUN) -sdk $(SDKROOT) -show-sdk-platform-path)
58 export PLATFORM := $(shell echo $(PLATFORMPATH) | sed 's,^.*/\([^/]*\)\.platform$$,\1,')
6d2010ae
A
59 ifeq ($(PLATFORM),)
60 export PLATFORM := MacOSX
3e170ce0
A
61 else ifeq ($(shell echo $(PLATFORM) | tr A-Z a-z),watchos)
62 export PLATFORM := WatchOS
6d2010ae
A
63 endif
64endif
65
39236c6e
A
66ifeq ($(SDKVERSION),)
67 export SDKVERSION := $(shell $(XCRUN) -sdk $(SDKROOT) -show-sdk-version)
68endif
69
6d2010ae
A
70# CC/CXX get defined by make(1) by default, so we can't check them
71# against the empty string to see if they haven't been set
72ifeq ($(origin CC),default)
316670eb 73 export CC := $(shell $(XCRUN) -sdk $(SDKROOT) -find clang)
6d2010ae
A
74endif
75ifeq ($(origin CXX),default)
316670eb 76 export CXX := $(shell $(XCRUN) -sdk $(SDKROOT) -find clang++)
6d2010ae
A
77endif
78ifeq ($(MIG),)
79 export MIG := $(shell $(XCRUN) -sdk $(SDKROOT) -find mig)
80endif
39236c6e
A
81ifeq ($(MIGCOM),)
82 export MIGCOM := $(shell $(XCRUN) -sdk $(SDKROOT) -find migcom)
83endif
b0d623f7 84ifeq ($(MIGCC),)
6d2010ae 85 export MIGCC := $(CC)
b0d623f7 86endif
6d2010ae
A
87ifeq ($(STRIP),)
88 export STRIP := $(shell $(XCRUN) -sdk $(SDKROOT) -find strip)
89endif
90ifeq ($(LIPO),)
91 export LIPO := $(shell $(XCRUN) -sdk $(SDKROOT) -find lipo)
92endif
93ifeq ($(LIBTOOL),)
94 export LIBTOOL := $(shell $(XCRUN) -sdk $(SDKROOT) -find libtool)
95endif
96ifeq ($(NM),)
97 export NM := $(shell $(XCRUN) -sdk $(SDKROOT) -find nm)
98endif
99ifeq ($(UNIFDEF),)
100 export UNIFDEF := $(shell $(XCRUN) -sdk $(SDKROOT) -find unifdef)
101endif
6d2010ae
A
102ifeq ($(DSYMUTIL),)
103 export DSYMUTIL := $(shell $(XCRUN) -sdk $(SDKROOT) -find dsymutil)
104endif
105ifeq ($(CTFCONVERT),)
106 export CTFCONVERT := $(shell $(XCRUN) -sdk $(SDKROOT) -find ctfconvert)
107endif
108ifeq ($(CTFMERGE),)
109 export CTFMERGE := $(shell $(XCRUN) -sdk $(SDKROOT) -find ctfmerge)
110endif
39236c6e
A
111ifeq ($(CTFINSERT),)
112 export CTFINSERT := $(shell $(XCRUN) -sdk $(SDKROOT) -find ctf_insert)
6d2010ae
A
113endif
114ifeq ($(NMEDIT),)
115 export NMEDIT := $(shell $(XCRUN) -sdk $(SDKROOT) -find nmedit)
116endif
b0d623f7 117
3e170ce0
A
118#
119# Platform options
120#
121SUPPORTED_EMBEDDED_PLATFORMS := iPhoneOS iPhoneOSNano tvOS AppleTVOS WatchOS
122SUPPORTED_SIMULATOR_PLATFORMS := iPhoneSimulator iPhoneNanoSimulator tvSimulator AppleTVSimulator WatchSimulator
123SUPPORTED_PLATFORMS := MacOSX $(SUPPORTED_SIMULATOR_PLATFORMS) $(SUPPORTED_EMBEDDED_PLATFORMS)
124
6d2010ae 125# Platform-specific tools
3e170ce0 126ifneq ($(filter $(SUPPORTED_EMBEDDED_PLATFORMS),$(PLATFORM)),)
316670eb
A
127ifeq ($(EMBEDDED_DEVICE_MAP),)
128 export EMBEDDED_DEVICE_MAP := $(shell $(XCRUN) -sdk $(SDKROOT) -find embedded_device_map)
129endif
39236c6e 130EDM_DBPATH = $(PLATFORMPATH)/usr/local/standalone/firmware/device_map.db
6d2010ae
A
131endif
132
133# Scripts or tools we build ourselves
fe8ab488
A
134#
135# setsegname - Rename segments in a Mach-O object file
136# kextsymboltool - Create kext pseudo-kext Mach-O kexts binaries
137# decomment - Strip out comments to detect whether a file is comments-only
138# installfile - Atomically copy files, esp. when multiple architectures
139# are trying to install the same target header
140# replacecontents - Write contents to a file and update modtime *only* if
141# contents differ
142#
39236c6e
A
143SEG_HACK = $(OBJROOT)/SETUP/setsegname/setsegname
144KEXT_CREATE_SYMBOL_SET = $(OBJROOT)/SETUP/kextsymboltool/kextsymboltool
145DECOMMENT = $(OBJROOT)/SETUP/decomment/decomment
6d2010ae 146NEWVERS = $(SRCROOT)/config/newvers.pl
39236c6e 147INSTALL = $(OBJROOT)/SETUP/installfile/installfile
fe8ab488 148REPLACECONTENTS = $(OBJROOT)/SETUP/replacecontents/replacecontents
3e170ce0 149JSONCOMPILATIONDB = $(OBJROOT)/SETUP/json_compilation_db/json_compilation_db
1c79356b 150
6d2010ae 151# Standard BSD tools
1c79356b 152RM = /bin/rm -f
39236c6e 153RMDIR = /bin/rmdir
1c79356b 154CP = /bin/cp
b0d623f7 155MV = /bin/mv
0c530ab8 156LN = /bin/ln -fs
1c79356b
A
157CAT = /bin/cat
158MKDIR = /bin/mkdir -p
fe8ab488 159CHMOD = /bin/chmod
2d21ac55 160FIND = /usr/bin/find
316670eb 161XARGS = /usr/bin/xargs
fe8ab488 162PAX = /bin/pax
1c79356b 163BASENAME = /usr/bin/basename
39236c6e 164DIRNAME = /usr/bin/dirname
0b4e3aa0 165TR = /usr/bin/tr
39236c6e 166TOUCH = /usr/bin/touch
fe8ab488 167SLEEP = /bin/sleep
39236c6e
A
168AWK = /usr/bin/awk
169SED = /usr/bin/sed
170ECHO = /bin/echo
171PLUTIL = /usr/bin/plutil
1c79356b 172
6d2010ae
A
173#
174# Command to generate host binaries. Intentionally not
175# $(CC), which controls the target compiler
176#
39236c6e
A
177ifeq ($(HOST_OS_VERSION),)
178 export HOST_OS_VERSION := $(shell sw_vers -productVersion)
179endif
6d2010ae 180ifeq ($(HOST_CC),)
39236c6e 181 export HOST_CC := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find clang)
6d2010ae
A
182endif
183ifeq ($(HOST_FLEX),)
184 export HOST_FLEX := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find flex)
185endif
186ifeq ($(HOST_BISON),)
187 export HOST_BISON := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find bison)
188endif
39236c6e
A
189ifeq ($(HOST_GM4),)
190 export HOST_GM4 := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find gm4)
191endif
6d2010ae 192ifeq ($(HOST_CODESIGN),)
39236c6e
A
193 export HOST_CODESIGN := /usr/bin/codesign
194endif
195ifeq ($(HOST_CODESIGN_ALLOCATE),)
196 export HOST_CODESIGN_ALLOCATE := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find codesign_allocate)
6d2010ae
A
197endif
198
39236c6e
A
199#
200# The following variables are functions invoked with "call", and thus
201# behave similarly to externally compiled commands
202#
203
204# $(1) is an expanded kernel config from a TARGET_CONFIGS_UC tuple
205# $(2) is an expanded arch config from a TARGET_CONFIGS_UC tuple
206# $(3) is an expanded machine config from a TARGET_CONFIGS_UC tuple
207_function_create_build_configs_join = $(strip $(1))^$(strip $(2))^$(strip $(3))
208
209# $(1) is an un-expanded kernel config from a TARGET_CONFIGS_UC tuple
210# $(2) is an un-expanded arch config from a TARGET_CONFIGS_UC tuple
211# $(3) is an un-expanded machine config from a TARGET_CONFIGS_UC tuple
212_function_create_build_configs_do_expand = $(call _function_create_build_configs_join, \
213 $(if $(filter DEFAULT,$(1)), \
39037602 214 $(DEFAULT_KERNEL_CONFIG), \
39236c6e
A
215 $(1) \
216 ), \
217 $(if $(filter DEFAULT,$(2)), \
39037602 218 $(DEFAULT_ARCH_CONFIG), \
39236c6e
A
219 $(2) \
220 ), \
221 $(if $(filter DEFAULT,$(3)), \
39037602
A
222 $(if $(filter DEFAULT,$(2)), \
223 $(DEFAULT_$(DEFAULT_ARCH_CONFIG)_MACHINE_CONFIG), \
39236c6e 224 $(DEFAULT_$(strip $(2))_MACHINE_CONFIG) \
39037602 225 ), \
39236c6e
A
226 $(3) \
227 ) \
228 )
229
230# $(1) is an un-expanded TARGET_CONFIGS_UC list, which must be consumed
231# 3 elements at a time
232function_create_build_configs = $(sort \
233 $(strip \
39037602
A
234 $(call _function_create_build_configs_do_expand, \
235 $(word 1,$(1)), \
236 $(word 2,$(1)), \
237 $(word 3,$(1)), \
39236c6e
A
238 ) \
239 $(if $(word 4,$(1)), \
240 $(call function_create_build_configs, \
241 $(wordlist 4,$(words $(1)),$(1)) \
242 ), \
39236c6e
A
243 ) \
244 ) \
245 )
246
39037602
A
247# Similar to build configs, but alias configs are a 4-tuple
248
249# $(1) is an expanded kernel config from a TARGET_CONFIGS_ALIASES_UC tuple
250# $(2) is an expanded arch config from a TARGET_CONFIGS_ALIASES_UC tuple
251# $(3) is an expanded kernel machine config from a TARGET_CONFIGS_ALIASES_UC tuple
252# $(4) is an expanded SoC platform config from a TARGET_CONFIGS_ALIASES_UC tuple,
253# which should be an alias of $(3)
254_function_create_alias_configs_join = $(strip $(1))^$(strip $(2))^$(strip $(3))^$(strip $(4))
255
256_function_create_alias_configs_do_expand = $(call _function_create_alias_configs_join, \
257 $(if $(filter DEFAULT,$(1)), \
258 $(DEFAULT_KERNEL_CONFIG), \
259 $(1) \
260 ), \
261 $(if $(filter DEFAULT,$(2)), \
262 $(DEFAULT_ARCH_CONFIG), \
263 $(2) \
264 ), \
265 $(3), \
266 $(4) \
267 )
268
269function_create_alias_configs = $(sort \
270 $(strip \
271 $(call _function_create_alias_configs_do_expand, \
272 $(word 1,$(1)), \
273 $(word 2,$(1)), \
274 $(word 3,$(1)), \
275 $(word 4,$(1)), \
276 ) \
277 $(if $(word 5,$(1)), \
278 $(call function_create_alias_configs, \
279 $(wordlist 5,$(words $(1)),$(1)) \
280 ), \
281 ) \
282 ) \
283 )
284
39236c6e
A
285# $(1) is a fully-expanded kernel config
286# $(2) is a fully-expanded arch config
287# $(3) is a fully-expanded machine config. "NONE" is not represented in the objdir path
288function_convert_target_config_uc_to_objdir = $(if $(filter NONE,$(3)),$(strip $(1))_$(strip $(2)),$(strip $(1))_$(strip $(2))_$(strip $(3)))
289
290# $(1) is a fully-expanded build config (like "RELEASE^X86_64^NONE")
291function_convert_build_config_to_objdir = $(call function_convert_target_config_uc_to_objdir, \
39037602 292 $(word 1,$(subst ^, ,$(1))), \
39236c6e
A
293 $(word 2,$(subst ^, ,$(1))), \
294 $(word 3,$(subst ^, ,$(1))) \
295 )
296
297# $(1) is a fully-expanded build config (like "RELEASE^X86_64^NONE")
298function_extract_kernel_config_from_build_config = $(word 1,$(subst ^, ,$(1)))
299function_extract_arch_config_from_build_config = $(word 2,$(subst ^, ,$(1)))
300function_extract_machine_config_from_build_config = $(word 3,$(subst ^, ,$(1)))
301
302# $(1) is an input word
303# $(2) is a list of colon-separate potential substitutions like "FOO:BAR BAZ:QUX"
304# $(3) is a fallback if no substitutions were made
305function_substitute_word_with_replacement = $(strip $(if $(2), \
306 $(if $(filter $(word 1,$(subst :, ,$(word 1,$(2)))),$(1)), \
307 $(word 2,$(subst :, ,$(word 1,$(2)))), \
308 $(call function_substitute_word_with_replacement,$(1),$(wordlist 2,$(words $(2)),$(2)),$(3))), \
309 $(3) \
310 ) \
311 )
312
313# You can't assign a variable to an empty space without these
314# shenanigans
315empty :=
316space := $(empty) $(empty)
317
318# Arithmetic
319# $(1) is the number to increment
39037602 320NUM32 = 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
fe8ab488
A
321increment = $(words x $(wordlist 1,$(1),$(NUM32)))
322decrement = $(words $(wordlist 2,$(1),$(NUM32)))
323
324# Create a sequence from 1 to $(1)
325# F(N) = if N > 0: return F(N-1) + "N" else: return ""
326sequence = $(if $(wordlist 1,$(1),$(NUM32)),$(call sequence,$(call decrement,$(1))) $(1),)
327
328# Reverse a list of words in $(1)
329reverse = $(if $(word 2,$(1)),$(call reverse,$(wordlist 2,$(words $(1)),$(1)))) $(word 1,$(1))
39236c6e 330
2d21ac55 331# vim: set ft=make: