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