]> git.saurik.com Git - apple/xnu.git/blame_incremental - makedefs/MakeInc.cmd
xnu-7195.101.1.tar.gz
[apple/xnu.git] / makedefs / MakeInc.cmd
... / ...
CommitLineData
1# -*- mode: makefile;-*-
2#
3# Copyright (C) 1999-2020 Apple Inc. All rights reserved.
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
10#
11# Commands for the build environment
12#
13
14#
15# Build Logging and Verbosity
16#
17
18ifeq ($(RC_XBS),YES)
19 VERBOSE = YES
20else
21 VERBOSE = NO
22endif
23
24ECHO = echo
25
26ERR = $(ECHO) > /dev/stderr
27PRINTF = printf
28
29QUIET ?= 0
30ifneq ($(QUIET),0)
31 PRINTF = printf > /dev/null
32 ifeq ($(VERBOSE),YES)
33 override VERBOSE = NO
34 endif
35endif
36
37# Helper functions for logging operations.
38LOG_PFX_LEN = 15
39LOG_PFX_LEN_ADJ = $(LOG_PFX_LEN)
40LOG = $(PRINTF) "$2%$4s$(Color0) $3%s$(Color0)\n" "$1"
41
42CONCISE ?= 0
43ifneq ($(CONCISE),0)
44 # Concise logging puts all logs on the same line (CSI K to clear and
45 # carriage return).
46 LOG = $(PRINTF) "$2%$4s$(Color0) $3%s$(Color0)\033[K\r" "$1"
47endif
48
49_LOG_COMP = $(call LOG,$1,$(ColorC),$(ColorF),$(LOG_PFX_LEN_ADJ))
50_LOG_HOST = $(call LOG,$1,$(ColorH),$(ColorF),$(LOG_PFX_LEN))
51_LOG_HOST_LINK = $(call LOG,$1,$(ColorH),$(ColorLF),$(LOG_PFX_LEN))
52
53# Special operations.
54LOG_LDFILELIST = $(call LOG,LDFILELIST,$(ColorL),$(ColorLF),$(LOG_PFX_LEN_ADJ))
55LOG_MIG = $(call LOG,MIG,$(ColorM),$(ColorF),$(LOG_PFX_LEN_ADJ))
56LOG_LD = $(call LOG,LD,$(ColorL),$(ColorF),$(LOG_PFX_LEN_ADJ))
57LOG_ALIGN = $(call LOG,--------->,$(Color0),$(Color0),$(LOG_PFX_LEN))
58
59# Compiling/machine-specific operations.
60LOG_CC = $(call _LOG_COMP,CC)
61LOG_CXX = $(call _LOG_COMP,C++)
62LOG_AS = $(call _LOG_COMP,AS)
63LOG_LTO = $(call _LOG_COMP,LTO)
64LOG_SYMBOLSET = $(call _LOG_COMP,SYMSET)
65LOG_SYMBOLSETPLIST = $(call _LOG_COMP,SYMSETPLIST)
66
67# Host-side operations.
68LOG_IIG = $(call _LOG_HOST,IIG)
69LOG_HOST_CC = $(call _LOG_HOST,CC)
70LOG_HOST_LD = $(call _LOG_HOST,LD)
71LOG_HOST_CODESIGN = $(call _LOG_HOST,CODESIGN)
72LOG_HOST_BISON = $(call _LOG_HOST,BISON)
73LOG_HOST_FLEX = $(call _LOG_HOST,FLEX)
74LOG_INSTALL = $(call _LOG_HOST,INSTALL)
75LOG_INSTALLSYM = $(call _LOG_HOST,INSTALLSYM)
76LOG_INSTALLHDR = $(call _LOG_HOST,INSTALLHDR)
77LOG_INSTALLMACROS = $(call _LOG_HOST,INSTALLMACROS)
78LOG_INSTALLPY = $(call _LOG_HOST,INSTALLPY)
79LOG_MAN = $(call _LOG_HOST,MAN)
80LOG_MANLINK = $(call _LOG_HOST,MANLINK)
81LOG_ALIAS = $(call _LOG_HOST,ALIAS)
82LOG_STRIP = $(call _LOG_HOST,STRIP)
83LOG_DSYMUTIL = $(call _LOG_HOST,DSYMUTIL)
84LOG_LIBTOOL = $(call _LOG_HOST,LIBTOOL)
85LOG_FILEPREP = $(call _LOG_HOST,FILEPREP)
86
87# Host-side linking operations.
88LOG_GENASSYM = $(call _LOG_HOST_LINK,GENASSYM)
89LOG_GENERATE= $(call _LOG_HOST_LINK,GENERATE)
90LOG_CTFCONVERT = $(call _LOG_HOST_LINK,CTFCONVERT)
91LOG_CTFMERGE = $(call _LOG_HOST_LINK,CTFMERGE)
92LOG_CTFINSERT = $(call _LOG_HOST_LINK,CTFINSERT)
93LOG_DSYMUTIL = $(call _LOG_HOST_LINK,DSYMUTIL)
94LOG_SUPPORTED_KPI = $(call _LOG_HOST_LINK,SUPPORTED_KPI)
95
96ifeq ($(VERBOSE),YES)
97 _v =
98 _vstdout =
99 _vstderr =
100 XCRUN = /usr/bin/xcrun -verbose
101else
102 _v = @
103 _vstdout = > /dev/null
104 _vstderr = 2&> /dev/null
105 XCRUN = /usr/bin/xcrun
106endif
107
108VERBOSE_GENERATED_MAKE_FRAGMENTS = NO
109
110#
111# Defaults
112#
113
114SDKROOT ?= macosx
115HOST_SDKROOT ?= macosx
116
117# SDKROOT may be passed as a shorthand like "iphoneos.internal". We
118# must resolve these to a full path and override SDKROOT.
119
120ifeq ($(SDKROOT_RESOLVED),)
121export SDKROOT_RESOLVED := $(shell $(XCRUN) -sdk $(SDKROOT) -show-sdk-path)
122ifeq ($(strip $(SDKROOT)_$(SDKROOT_RESOLVED)),/_)
123export SDKROOT_RESOLVED := /
124endif
125endif
126override SDKROOT = $(SDKROOT_RESOLVED)
127
128ifeq ($(HOST_SDKROOT_RESOLVED),)
129export HOST_SDKROOT_RESOLVED := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -show-sdk-path)
130ifeq ($(strip $(HOST_SDKROOT_RESOLVED)),)
131export HOST_SDKROOT_RESOLVED := /
132endif
133endif
134override HOST_SDKROOT = $(HOST_SDKROOT_RESOLVED)
135
136ifeq ($(PLATFORM),)
137 export PLATFORMPATH := $(shell $(XCRUN) -sdk $(SDKROOT) -show-sdk-platform-path)
138 export PLATFORM := $(shell echo $(PLATFORMPATH) | sed 's,^.*/\([^/]*\)\.platform$$,\1,')
139 ifeq ($(PLATFORM),)
140 export PLATFORM := MacOSX
141 else ifeq ($(shell echo $(PLATFORM) | tr A-Z a-z),watchos)
142 export PLATFORM := WatchOS
143 endif
144endif
145
146ifeq ($(PLATFORM),MacOSX)
147 ifeq (DriverKit,$(shell echo $(SDKROOT_RESOLVED) | sed 's,^.*/\([^/1-9]*\)[1-9][^/]*\.sdk$$,\1,'))
148 export PLATFORM := DriverKit
149 export DRIVERKIT ?= 1
150 export DRIVERKITROOT ?= /System/DriverKit
151 export DRIVERKITRUNTIMEROOT = $(DRIVERKITROOT)/Runtime
152 endif
153endif
154
155ifeq ($(SDKVERSION),)
156 export SDKVERSION := $(shell $(XCRUN) -sdk $(SDKROOT) -show-sdk-version)
157endif
158
159# CC/CXX get defined by make(1) by default, so we can't check them
160# against the empty string to see if they haven't been set
161ifeq ($(origin CC),default)
162 export CC := $(shell $(XCRUN) -sdk $(SDKROOT) -find clang)
163endif
164ifeq ($(origin CXX),default)
165 export CXX := $(shell $(XCRUN) -sdk $(SDKROOT) -find clang++)
166endif
167ifeq ($(MIG),)
168 export MIG := $(shell $(XCRUN) -sdk $(SDKROOT) -find mig)
169endif
170ifeq ($(MIGCOM),)
171 export MIGCOM := $(shell $(XCRUN) -sdk $(SDKROOT) -find migcom)
172endif
173ifeq ($(MIGCC),)
174 export MIGCC := $(CC)
175endif
176ifeq ($(IIG),)
177 export IIG := $(shell $(XCRUN) -sdk $(SDKROOT) -find iig)
178endif
179ifeq ($(STRIP),)
180 export STRIP := $(shell $(XCRUN) -sdk $(SDKROOT) -find strip)
181endif
182ifeq ($(LIPO),)
183 export LIPO := $(shell $(XCRUN) -sdk $(SDKROOT) -find lipo)
184endif
185ifeq ($(LIBTOOL),)
186 export LIBTOOL := $(shell $(XCRUN) -sdk $(SDKROOT) -find libtool)
187endif
188ifeq ($(OTOOL),)
189 export OTOOL := $(shell $(XCRUN) -sdk $(SDKROOT) -find otool)
190endif
191ifeq ($(NM),)
192 export NM := $(shell $(XCRUN) -sdk $(SDKROOT) -find nm)
193endif
194ifeq ($(UNIFDEF),)
195 export UNIFDEF := $(shell $(XCRUN) -sdk $(SDKROOT) -find unifdef)
196endif
197ifeq ($(DSYMUTIL),)
198 export DSYMUTIL := $(shell $(XCRUN) -sdk $(SDKROOT) -find dsymutil)
199endif
200ifeq ($(CTFCONVERT),)
201 export CTFCONVERT := $(shell $(XCRUN) -sdk $(SDKROOT) -find ctfconvert)
202endif
203ifeq ($(CTFMERGE),)
204 export CTFMERGE := $(shell $(XCRUN) -sdk $(SDKROOT) -find ctfmerge)
205endif
206ifeq ($(CTFINSERT),)
207 export CTFINSERT := $(shell $(XCRUN) -sdk $(SDKROOT) -find ctf_insert)
208endif
209ifeq ($(NMEDIT),)
210 export NMEDIT := $(shell $(XCRUN) -sdk $(SDKROOT) -find nmedit)
211endif
212ifeq ($(SCAN_BUILD),)
213 export SCAN_BUILD := $(shell $(XCRUN) -sdk $(SDKROOT) -find scan-build)
214endif
215
216#
217# Platform options
218#
219SUPPORTED_EMBEDDED_PLATFORMS := iPhoneOS iPhoneOSNano tvOS AppleTVOS WatchOS BridgeOS
220SUPPORTED_SIMULATOR_PLATFORMS := iPhoneSimulator iPhoneNanoSimulator tvSimulator AppleTVSimulator WatchSimulator
221SUPPORTED_PLATFORMS := MacOSX DriverKit $(SUPPORTED_SIMULATOR_PLATFORMS) $(SUPPORTED_EMBEDDED_PLATFORMS)
222
223# Platform-specific tools
224EDM_DBPATH ?= $(PLATFORMPATH)/usr/local/standalone/firmware/device_map.db
225
226# Scripts or tools we build ourselves
227#
228# setsegname - Rename segments in a Mach-O object file
229# kextsymboltool - Create kext pseudo-kext Mach-O kexts binaries
230# decomment - Strip out comments to detect whether a file is comments-only
231# installfile - Atomically copy files, esp. when multiple architectures
232# are trying to install the same target header
233# replacecontents - Write contents to a file and update modtime *only* if
234# contents differ
235#
236SEG_HACK = $(OBJROOT)/SETUP/setsegname/setsegname
237KEXT_CREATE_SYMBOL_SET = $(OBJROOT)/SETUP/kextsymboltool/kextsymboltool
238DECOMMENT = $(OBJROOT)/SETUP/decomment/decomment
239NEWVERS = $(SRCROOT)/config/newvers.pl
240INSTALL = $(OBJROOT)/SETUP/installfile/installfile
241REPLACECONTENTS = $(OBJROOT)/SETUP/replacecontents/replacecontents
242JSONCOMPILATIONDB = $(OBJROOT)/SETUP/json_compilation_db/json_compilation_db
243
244# Standard BSD tools
245RM = /bin/rm -f
246RMDIR = /bin/rmdir
247CP = /bin/cp
248MV = /bin/mv
249LN = /bin/ln -fs
250CAT = /bin/cat
251MKDIR = /bin/mkdir -p
252CHMOD = /bin/chmod
253FIND = /usr/bin/find
254XARGS = /usr/bin/xargs
255PAX = /bin/pax
256BASENAME = /usr/bin/basename
257DIRNAME = /usr/bin/dirname
258TR = /usr/bin/tr
259TOUCH = /usr/bin/touch
260SLEEP = /bin/sleep
261AWK = /usr/bin/awk
262SED = /usr/bin/sed
263PLUTIL = /usr/bin/plutil
264GREP = /usr/bin/grep
265
266#
267# Command to generate host binaries. Intentionally not
268# $(CC), which controls the target compiler
269#
270ifeq ($(HOST_OS_VERSION),)
271 export HOST_OS_VERSION := $(shell sw_vers -productVersion)
272endif
273ifeq ($(HOST_CC),)
274 export HOST_CC := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find clang)
275endif
276ifeq ($(HOST_FLEX),)
277 export HOST_FLEX := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find flex)
278endif
279ifeq ($(HOST_BISON),)
280 export HOST_BISON := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find bison)
281endif
282ifeq ($(HOST_GM4),)
283 export HOST_GM4 := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find gm4)
284endif
285ifeq ($(HOST_CODESIGN),)
286 export HOST_CODESIGN := /usr/bin/codesign
287endif
288ifeq ($(HOST_CODESIGN_ALLOCATE),)
289 export HOST_CODESIGN_ALLOCATE := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find codesign_allocate)
290endif
291
292#
293# The following variables are functions invoked with "call", and thus
294# behave similarly to externally compiled commands
295#
296
297# $(1) is an expanded kernel config from a TARGET_CONFIGS_UC tuple
298# $(2) is an expanded arch config from a TARGET_CONFIGS_UC tuple
299# $(3) is an expanded machine config from a TARGET_CONFIGS_UC tuple
300_function_create_build_configs_join = $(strip $(1))^$(strip $(2))^$(strip $(3))
301
302# $(1) is an un-expanded kernel config from a TARGET_CONFIGS_UC tuple
303# $(2) is an un-expanded arch config from a TARGET_CONFIGS_UC tuple
304# $(3) is an un-expanded machine config from a TARGET_CONFIGS_UC tuple
305_function_create_build_configs_do_expand = $(call _function_create_build_configs_join, \
306 $(if $(filter DEFAULT,$(1)), \
307 $(DEFAULT_KERNEL_CONFIG), \
308 $(1) \
309 ), \
310 $(if $(filter DEFAULT,$(2)), \
311 $(DEFAULT_ARCH_CONFIG), \
312 $(2) \
313 ), \
314 $(if $(filter DEFAULT,$(3)), \
315 $(if $(filter DEFAULT,$(2)), \
316 $(DEFAULT_$(DEFAULT_ARCH_CONFIG)_MACHINE_CONFIG), \
317 $(DEFAULT_$(strip $(2))_MACHINE_CONFIG) \
318 ), \
319 $(3) \
320 ) \
321 )
322
323# $(1) is an un-expanded TARGET_CONFIGS_UC list, which must be consumed
324# 3 elements at a time
325function_create_build_configs = $(sort \
326 $(strip \
327 $(call _function_create_build_configs_do_expand, \
328 $(word 1,$(1)), \
329 $(word 2,$(1)), \
330 $(word 3,$(1)), \
331 ) \
332 $(if $(word 4,$(1)), \
333 $(call function_create_build_configs, \
334 $(wordlist 4,$(words $(1)),$(1)) \
335 ), \
336 ) \
337 ) \
338 )
339
340# Similar to build configs, but alias configs are a 4-tuple
341
342# $(1) is an expanded kernel config from a TARGET_CONFIGS_ALIASES_UC tuple
343# $(2) is an expanded arch config from a TARGET_CONFIGS_ALIASES_UC tuple
344# $(3) is an expanded kernel machine config from a TARGET_CONFIGS_ALIASES_UC tuple
345# $(4) is an expanded SoC platform config from a TARGET_CONFIGS_ALIASES_UC tuple,
346# which should be an alias of $(3)
347_function_create_alias_configs_join = $(strip $(1))^$(strip $(2))^$(strip $(3))^$(strip $(4))
348
349_function_create_alias_configs_do_expand = $(call _function_create_alias_configs_join, \
350 $(if $(filter DEFAULT,$(1)), \
351 $(DEFAULT_KERNEL_CONFIG), \
352 $(1) \
353 ), \
354 $(if $(filter DEFAULT,$(2)), \
355 $(DEFAULT_ARCH_CONFIG), \
356 $(2) \
357 ), \
358 $(3), \
359 $(4) \
360 )
361
362function_create_alias_configs = $(sort \
363 $(strip \
364 $(call _function_create_alias_configs_do_expand, \
365 $(word 1,$(1)), \
366 $(word 2,$(1)), \
367 $(word 3,$(1)), \
368 $(word 4,$(1)), \
369 ) \
370 $(if $(word 5,$(1)), \
371 $(call function_create_alias_configs, \
372 $(wordlist 5,$(words $(1)),$(1)) \
373 ), \
374 ) \
375 ) \
376 )
377
378# $(1) is a fully-expanded kernel config
379# $(2) is a fully-expanded arch config
380# $(3) is a fully-expanded machine config. "NONE" is not represented in the objdir path
381function_convert_target_config_uc_to_objdir = $(if $(filter NONE,$(3)),$(strip $(1))_$(strip $(2)),$(strip $(1))_$(strip $(2))_$(strip $(3)))
382
383# $(1) is a fully-expanded build config (like "RELEASE^X86_64^NONE")
384function_convert_build_config_to_objdir = $(call function_convert_target_config_uc_to_objdir, \
385 $(word 1,$(subst ^, ,$(1))), \
386 $(word 2,$(subst ^, ,$(1))), \
387 $(word 3,$(subst ^, ,$(1))) \
388 )
389
390# $(1) is a fully-expanded build config (like "RELEASE^X86_64^NONE")
391function_extract_kernel_config_from_build_config = $(word 1,$(subst ^, ,$(1)))
392function_extract_arch_config_from_build_config = $(word 2,$(subst ^, ,$(1)))
393function_extract_machine_config_from_build_config = $(word 3,$(subst ^, ,$(1)))
394
395# $(1) is an input word
396# $(2) is a list of colon-separate potential substitutions like "FOO:BAR BAZ:QUX"
397# $(3) is a fallback if no substitutions were made
398function_substitute_word_with_replacement = $(strip $(if $(2), \
399 $(if $(filter $(word 1,$(subst :, ,$(word 1,$(2)))),$(1)), \
400 $(word 2,$(subst :, ,$(word 1,$(2)))), \
401 $(call function_substitute_word_with_replacement,$(1),$(wordlist 2,$(words $(2)),$(2)),$(3))), \
402 $(3) \
403 ) \
404 )
405
406# You can't assign a variable to an empty space without these
407# shenanigans
408empty :=
409space := $(empty) $(empty)
410
411# Arithmetic
412# $(1) is the number to increment
413NUM32 = 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
414increment = $(words x $(wordlist 1,$(1),$(NUM32)))
415decrement = $(words $(wordlist 2,$(1),$(NUM32)))
416
417# Create a sequence from 1 to $(1)
418# F(N) = if N > 0: return F(N-1) + "N" else: return ""
419sequence = $(if $(wordlist 1,$(1),$(NUM32)),$(call sequence,$(call decrement,$(1))) $(1),)
420
421# Reverse a list of words in $(1)
422reverse = $(if $(word 2,$(1)),$(call reverse,$(wordlist 2,$(words $(1)),$(1)))) $(word 1,$(1))
423
424# vim: set ft=make: