]> git.saurik.com Git - apple/xnu.git/blame - makedefs/MakeInc.cmd
xnu-4903.221.2.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
d9a64523 37SDKROOT ?= macosx
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)
d9a64523
A
53ifeq ($(strip $(HOST_SDKROOT_RESOLVED)),)
54export HOST_SDKROOT_RESOLVED := /
55endif
39236c6e
A
56endif
57override HOST_SDKROOT = $(HOST_SDKROOT_RESOLVED)
58
6d2010ae 59ifeq ($(PLATFORM),)
39236c6e
A
60 export PLATFORMPATH := $(shell $(XCRUN) -sdk $(SDKROOT) -show-sdk-platform-path)
61 export PLATFORM := $(shell echo $(PLATFORMPATH) | sed 's,^.*/\([^/]*\)\.platform$$,\1,')
6d2010ae
A
62 ifeq ($(PLATFORM),)
63 export PLATFORM := MacOSX
3e170ce0
A
64 else ifeq ($(shell echo $(PLATFORM) | tr A-Z a-z),watchos)
65 export PLATFORM := WatchOS
6d2010ae
A
66 endif
67endif
68
39236c6e
A
69ifeq ($(SDKVERSION),)
70 export SDKVERSION := $(shell $(XCRUN) -sdk $(SDKROOT) -show-sdk-version)
71endif
72
6d2010ae
A
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
75ifeq ($(origin CC),default)
316670eb 76 export CC := $(shell $(XCRUN) -sdk $(SDKROOT) -find clang)
6d2010ae
A
77endif
78ifeq ($(origin CXX),default)
316670eb 79 export CXX := $(shell $(XCRUN) -sdk $(SDKROOT) -find clang++)
6d2010ae
A
80endif
81ifeq ($(MIG),)
82 export MIG := $(shell $(XCRUN) -sdk $(SDKROOT) -find mig)
83endif
39236c6e
A
84ifeq ($(MIGCOM),)
85 export MIGCOM := $(shell $(XCRUN) -sdk $(SDKROOT) -find migcom)
86endif
b0d623f7 87ifeq ($(MIGCC),)
6d2010ae 88 export MIGCC := $(CC)
b0d623f7 89endif
6d2010ae
A
90ifeq ($(STRIP),)
91 export STRIP := $(shell $(XCRUN) -sdk $(SDKROOT) -find strip)
92endif
93ifeq ($(LIPO),)
94 export LIPO := $(shell $(XCRUN) -sdk $(SDKROOT) -find lipo)
95endif
96ifeq ($(LIBTOOL),)
97 export LIBTOOL := $(shell $(XCRUN) -sdk $(SDKROOT) -find libtool)
98endif
99ifeq ($(NM),)
100 export NM := $(shell $(XCRUN) -sdk $(SDKROOT) -find nm)
101endif
102ifeq ($(UNIFDEF),)
103 export UNIFDEF := $(shell $(XCRUN) -sdk $(SDKROOT) -find unifdef)
104endif
6d2010ae
A
105ifeq ($(DSYMUTIL),)
106 export DSYMUTIL := $(shell $(XCRUN) -sdk $(SDKROOT) -find dsymutil)
107endif
108ifeq ($(CTFCONVERT),)
109 export CTFCONVERT := $(shell $(XCRUN) -sdk $(SDKROOT) -find ctfconvert)
110endif
111ifeq ($(CTFMERGE),)
112 export CTFMERGE := $(shell $(XCRUN) -sdk $(SDKROOT) -find ctfmerge)
113endif
39236c6e
A
114ifeq ($(CTFINSERT),)
115 export CTFINSERT := $(shell $(XCRUN) -sdk $(SDKROOT) -find ctf_insert)
6d2010ae
A
116endif
117ifeq ($(NMEDIT),)
118 export NMEDIT := $(shell $(XCRUN) -sdk $(SDKROOT) -find nmedit)
119endif
b0d623f7 120
3e170ce0
A
121#
122# Platform options
123#
5ba3f43e 124SUPPORTED_EMBEDDED_PLATFORMS := iPhoneOS iPhoneOSNano tvOS AppleTVOS WatchOS BridgeOS
3e170ce0
A
125SUPPORTED_SIMULATOR_PLATFORMS := iPhoneSimulator iPhoneNanoSimulator tvSimulator AppleTVSimulator WatchSimulator
126SUPPORTED_PLATFORMS := MacOSX $(SUPPORTED_SIMULATOR_PLATFORMS) $(SUPPORTED_EMBEDDED_PLATFORMS)
127
6d2010ae 128# Platform-specific tools
3e170ce0 129ifneq ($(filter $(SUPPORTED_EMBEDDED_PLATFORMS),$(PLATFORM)),)
316670eb
A
130ifeq ($(EMBEDDED_DEVICE_MAP),)
131 export EMBEDDED_DEVICE_MAP := $(shell $(XCRUN) -sdk $(SDKROOT) -find embedded_device_map)
132endif
5ba3f43e 133EDM_DBPATH ?= $(PLATFORMPATH)/usr/local/standalone/firmware/device_map.db
6d2010ae
A
134endif
135
136# Scripts or tools we build ourselves
fe8ab488
A
137#
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
144# contents differ
145#
39236c6e
A
146SEG_HACK = $(OBJROOT)/SETUP/setsegname/setsegname
147KEXT_CREATE_SYMBOL_SET = $(OBJROOT)/SETUP/kextsymboltool/kextsymboltool
148DECOMMENT = $(OBJROOT)/SETUP/decomment/decomment
6d2010ae 149NEWVERS = $(SRCROOT)/config/newvers.pl
39236c6e 150INSTALL = $(OBJROOT)/SETUP/installfile/installfile
fe8ab488 151REPLACECONTENTS = $(OBJROOT)/SETUP/replacecontents/replacecontents
3e170ce0 152JSONCOMPILATIONDB = $(OBJROOT)/SETUP/json_compilation_db/json_compilation_db
1c79356b 153
6d2010ae 154# Standard BSD tools
1c79356b 155RM = /bin/rm -f
39236c6e 156RMDIR = /bin/rmdir
1c79356b 157CP = /bin/cp
b0d623f7 158MV = /bin/mv
0c530ab8 159LN = /bin/ln -fs
1c79356b
A
160CAT = /bin/cat
161MKDIR = /bin/mkdir -p
fe8ab488 162CHMOD = /bin/chmod
2d21ac55 163FIND = /usr/bin/find
316670eb 164XARGS = /usr/bin/xargs
fe8ab488 165PAX = /bin/pax
1c79356b 166BASENAME = /usr/bin/basename
39236c6e 167DIRNAME = /usr/bin/dirname
0b4e3aa0 168TR = /usr/bin/tr
39236c6e 169TOUCH = /usr/bin/touch
fe8ab488 170SLEEP = /bin/sleep
39236c6e
A
171AWK = /usr/bin/awk
172SED = /usr/bin/sed
173ECHO = /bin/echo
174PLUTIL = /usr/bin/plutil
1c79356b 175
6d2010ae
A
176#
177# Command to generate host binaries. Intentionally not
178# $(CC), which controls the target compiler
179#
39236c6e
A
180ifeq ($(HOST_OS_VERSION),)
181 export HOST_OS_VERSION := $(shell sw_vers -productVersion)
182endif
6d2010ae 183ifeq ($(HOST_CC),)
39236c6e 184 export HOST_CC := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find clang)
6d2010ae
A
185endif
186ifeq ($(HOST_FLEX),)
187 export HOST_FLEX := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find flex)
188endif
189ifeq ($(HOST_BISON),)
190 export HOST_BISON := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find bison)
191endif
39236c6e
A
192ifeq ($(HOST_GM4),)
193 export HOST_GM4 := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find gm4)
194endif
6d2010ae 195ifeq ($(HOST_CODESIGN),)
39236c6e
A
196 export HOST_CODESIGN := /usr/bin/codesign
197endif
198ifeq ($(HOST_CODESIGN_ALLOCATE),)
199 export HOST_CODESIGN_ALLOCATE := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find codesign_allocate)
6d2010ae
A
200endif
201
39236c6e
A
202#
203# The following variables are functions invoked with "call", and thus
204# behave similarly to externally compiled commands
205#
206
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))
211
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)), \
39037602 217 $(DEFAULT_KERNEL_CONFIG), \
39236c6e
A
218 $(1) \
219 ), \
220 $(if $(filter DEFAULT,$(2)), \
39037602 221 $(DEFAULT_ARCH_CONFIG), \
39236c6e
A
222 $(2) \
223 ), \
224 $(if $(filter DEFAULT,$(3)), \
39037602
A
225 $(if $(filter DEFAULT,$(2)), \
226 $(DEFAULT_$(DEFAULT_ARCH_CONFIG)_MACHINE_CONFIG), \
39236c6e 227 $(DEFAULT_$(strip $(2))_MACHINE_CONFIG) \
39037602 228 ), \
39236c6e
A
229 $(3) \
230 ) \
231 )
232
233# $(1) is an un-expanded TARGET_CONFIGS_UC list, which must be consumed
234# 3 elements at a time
235function_create_build_configs = $(sort \
236 $(strip \
39037602
A
237 $(call _function_create_build_configs_do_expand, \
238 $(word 1,$(1)), \
239 $(word 2,$(1)), \
240 $(word 3,$(1)), \
39236c6e
A
241 ) \
242 $(if $(word 4,$(1)), \
243 $(call function_create_build_configs, \
244 $(wordlist 4,$(words $(1)),$(1)) \
245 ), \
39236c6e
A
246 ) \
247 ) \
248 )
249
39037602
A
250# Similar to build configs, but alias configs are a 4-tuple
251
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))
258
259_function_create_alias_configs_do_expand = $(call _function_create_alias_configs_join, \
260 $(if $(filter DEFAULT,$(1)), \
261 $(DEFAULT_KERNEL_CONFIG), \
262 $(1) \
263 ), \
264 $(if $(filter DEFAULT,$(2)), \
265 $(DEFAULT_ARCH_CONFIG), \
266 $(2) \
267 ), \
268 $(3), \
269 $(4) \
270 )
271
272function_create_alias_configs = $(sort \
273 $(strip \
274 $(call _function_create_alias_configs_do_expand, \
275 $(word 1,$(1)), \
276 $(word 2,$(1)), \
277 $(word 3,$(1)), \
278 $(word 4,$(1)), \
279 ) \
280 $(if $(word 5,$(1)), \
281 $(call function_create_alias_configs, \
282 $(wordlist 5,$(words $(1)),$(1)) \
283 ), \
284 ) \
285 ) \
286 )
287
39236c6e
A
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
291function_convert_target_config_uc_to_objdir = $(if $(filter NONE,$(3)),$(strip $(1))_$(strip $(2)),$(strip $(1))_$(strip $(2))_$(strip $(3)))
292
293# $(1) is a fully-expanded build config (like "RELEASE^X86_64^NONE")
294function_convert_build_config_to_objdir = $(call function_convert_target_config_uc_to_objdir, \
39037602 295 $(word 1,$(subst ^, ,$(1))), \
39236c6e
A
296 $(word 2,$(subst ^, ,$(1))), \
297 $(word 3,$(subst ^, ,$(1))) \
298 )
299
300# $(1) is a fully-expanded build config (like "RELEASE^X86_64^NONE")
301function_extract_kernel_config_from_build_config = $(word 1,$(subst ^, ,$(1)))
302function_extract_arch_config_from_build_config = $(word 2,$(subst ^, ,$(1)))
303function_extract_machine_config_from_build_config = $(word 3,$(subst ^, ,$(1)))
304
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
308function_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))), \
312 $(3) \
313 ) \
314 )
315
316# You can't assign a variable to an empty space without these
317# shenanigans
318empty :=
319space := $(empty) $(empty)
320
321# Arithmetic
322# $(1) is the number to increment
39037602 323NUM32 = 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
324increment = $(words x $(wordlist 1,$(1),$(NUM32)))
325decrement = $(words $(wordlist 2,$(1),$(NUM32)))
326
327# Create a sequence from 1 to $(1)
328# F(N) = if N > 0: return F(N-1) + "N" else: return ""
329sequence = $(if $(wordlist 1,$(1),$(NUM32)),$(call sequence,$(call decrement,$(1))) $(1),)
330
331# Reverse a list of words in $(1)
332reverse = $(if $(word 2,$(1)),$(call reverse,$(wordlist 2,$(words $(1)),$(1)))) $(word 1,$(1))
39236c6e 333
2d21ac55 334# vim: set ft=make: