xref: /xnu-11215.81.4/makedefs/MakeInc.cmd (revision d4514f0bc1d3f944c22d92e68b646ac3fb40d452)
1*d4514f0bSApple OSS Distributions# -*- mode: makefile;-*-
2*d4514f0bSApple OSS Distributions#
3*d4514f0bSApple OSS Distributions# Copyright (C) 1999-2020 Apple Inc. All rights reserved.
4*d4514f0bSApple OSS Distributions#
5*d4514f0bSApple OSS Distributions# MakeInc.cmd contains command paths for use during
6*d4514f0bSApple OSS Distributions# the build, as well as make fragments and text
7*d4514f0bSApple OSS Distributions# strings that may be evaluated as utility functions.
8*d4514f0bSApple OSS Distributions#
9*d4514f0bSApple OSS Distributions
10*d4514f0bSApple OSS Distributions#
11*d4514f0bSApple OSS Distributions# Commands for the build environment
12*d4514f0bSApple OSS Distributions#
13*d4514f0bSApple OSS Distributions
14*d4514f0bSApple OSS Distributions#
15*d4514f0bSApple OSS Distributions# Build Logging and Verbosity
16*d4514f0bSApple OSS Distributions#
17*d4514f0bSApple OSS Distributions
18*d4514f0bSApple OSS Distributionsifeq ($(RC_XBS),YES)
19*d4514f0bSApple OSS Distributions	VERBOSE = YES
20*d4514f0bSApple OSS Distributionselse
21*d4514f0bSApple OSS Distributions	VERBOSE = NO
22*d4514f0bSApple OSS Distributionsendif
23*d4514f0bSApple OSS Distributions
24*d4514f0bSApple OSS DistributionsBASH = bash
25*d4514f0bSApple OSS Distributions
26*d4514f0bSApple OSS DistributionsECHO = echo
27*d4514f0bSApple OSS Distributions
28*d4514f0bSApple OSS DistributionsERR = $(ECHO) > /dev/stderr
29*d4514f0bSApple OSS DistributionsPRINTF = printf
30*d4514f0bSApple OSS Distributions
31*d4514f0bSApple OSS DistributionsQUIET ?= 0
32*d4514f0bSApple OSS Distributionsifneq ($(QUIET),0)
33*d4514f0bSApple OSS Distributions	PRINTF = printf > /dev/null
34*d4514f0bSApple OSS Distributions	ifeq ($(VERBOSE),YES)
35*d4514f0bSApple OSS Distributions		override VERBOSE = NO
36*d4514f0bSApple OSS Distributions	endif
37*d4514f0bSApple OSS Distributionsendif
38*d4514f0bSApple OSS Distributions
39*d4514f0bSApple OSS Distributions# Helper functions for logging operations.
40*d4514f0bSApple OSS DistributionsLOG_PFX_LEN = 15
41*d4514f0bSApple OSS DistributionsLOG_PFX_LEN_ADJ = $(LOG_PFX_LEN)
42*d4514f0bSApple OSS DistributionsLOG = $(PRINTF) "$2%$4s$(Color0) $3%s$(Color0)\n" "$1"
43*d4514f0bSApple OSS Distributions
44*d4514f0bSApple OSS DistributionsCONCISE ?= 0
45*d4514f0bSApple OSS Distributionsifneq ($(CONCISE),0)
46*d4514f0bSApple OSS Distributions	# Concise logging puts all logs on the same line (CSI K to clear and
47*d4514f0bSApple OSS Distributions	# carriage return).
48*d4514f0bSApple OSS Distributions	LOG = $(PRINTF) "$2%$4s$(Color0) $3%s$(Color0)\033[K\r" "$1"
49*d4514f0bSApple OSS Distributionsendif
50*d4514f0bSApple OSS Distributions
51*d4514f0bSApple OSS Distributions_LOG_COMP = $(call LOG,$1,$(ColorC),$(ColorF),$(LOG_PFX_LEN_ADJ))
52*d4514f0bSApple OSS Distributions_LOG_HOST = $(call LOG,$1,$(ColorH),$(ColorF),$(LOG_PFX_LEN))
53*d4514f0bSApple OSS Distributions_LOG_HOST_LINK = $(call LOG,$1,$(ColorH),$(ColorLF),$(LOG_PFX_LEN))
54*d4514f0bSApple OSS Distributions
55*d4514f0bSApple OSS Distributions# Special operations.
56*d4514f0bSApple OSS DistributionsLOG_LDFILELIST = $(call LOG,LDFILELIST,$(ColorL),$(ColorLF),$(LOG_PFX_LEN_ADJ))
57*d4514f0bSApple OSS DistributionsLOG_MIG = $(call LOG,MIG,$(ColorM),$(ColorF),$(LOG_PFX_LEN_ADJ))
58*d4514f0bSApple OSS DistributionsLOG_LD = $(call LOG,LD,$(ColorL),$(ColorF),$(LOG_PFX_LEN_ADJ))
59*d4514f0bSApple OSS DistributionsLOG_ALIGN = $(call LOG,--------->,$(Color0),$(Color0),$(LOG_PFX_LEN))
60*d4514f0bSApple OSS Distributions
61*d4514f0bSApple OSS Distributions# Compiling/machine-specific operations.
62*d4514f0bSApple OSS DistributionsLOG_CC = $(call _LOG_COMP,CC)
63*d4514f0bSApple OSS DistributionsLOG_CXX = $(call _LOG_COMP,C++)
64*d4514f0bSApple OSS DistributionsLOG_AS = $(call _LOG_COMP,AS)
65*d4514f0bSApple OSS DistributionsLOG_LTO = $(call _LOG_COMP,LTO)
66*d4514f0bSApple OSS DistributionsLOG_SYMBOLSET = $(call _LOG_COMP,SYMSET)
67*d4514f0bSApple OSS DistributionsLOG_SYMBOLSETPLIST = $(call _LOG_COMP,SYMSETPLIST)
68*d4514f0bSApple OSS DistributionsLOG_VERIFIER = $(call _LOG_COMP,VERIFIER)
69*d4514f0bSApple OSS Distributions
70*d4514f0bSApple OSS Distributions# Host-side operations.
71*d4514f0bSApple OSS DistributionsLOG_TIGHTBEAMC = $(call _LOG_HOST,TIGHTBEAMC)
72*d4514f0bSApple OSS DistributionsLOG_IIG = $(call _LOG_HOST,IIG)
73*d4514f0bSApple OSS DistributionsLOG_HOST_CC = $(call _LOG_HOST,CC)
74*d4514f0bSApple OSS DistributionsLOG_HOST_LD = $(call _LOG_HOST,LD)
75*d4514f0bSApple OSS DistributionsLOG_HOST_CODESIGN = $(call _LOG_HOST,CODESIGN)
76*d4514f0bSApple OSS DistributionsLOG_HOST_BISON = $(call _LOG_HOST,BISON)
77*d4514f0bSApple OSS DistributionsLOG_HOST_FLEX = $(call _LOG_HOST,FLEX)
78*d4514f0bSApple OSS DistributionsLOG_INSTALL = $(call _LOG_HOST,INSTALL)
79*d4514f0bSApple OSS DistributionsLOG_INSTALLVARIANT = $(call _LOG_HOST,INSTALLVARIANT)
80*d4514f0bSApple OSS DistributionsLOG_INSTALLSYM = $(call _LOG_HOST,INSTALLSYM)
81*d4514f0bSApple OSS DistributionsLOG_INSTALLHDR = $(call _LOG_HOST,INSTALLHDR)
82*d4514f0bSApple OSS DistributionsLOG_INSTALLMACROS = $(call _LOG_HOST,INSTALLMACROS)
83*d4514f0bSApple OSS DistributionsLOG_INSTALLPY = $(call _LOG_HOST,INSTALLPY)
84*d4514f0bSApple OSS DistributionsLOG_MAN = $(call _LOG_HOST,MAN)
85*d4514f0bSApple OSS DistributionsLOG_MANLINK = $(call _LOG_HOST,MANLINK)
86*d4514f0bSApple OSS DistributionsLOG_ALIAS = $(call _LOG_HOST,ALIAS)
87*d4514f0bSApple OSS DistributionsLOG_STRIP = $(call _LOG_HOST,STRIP)
88*d4514f0bSApple OSS DistributionsLOG_DSYMUTIL = $(call _LOG_HOST,DSYMUTIL)
89*d4514f0bSApple OSS DistributionsLOG_LIBTOOL = $(call _LOG_HOST,LIBTOOL)
90*d4514f0bSApple OSS DistributionsLOG_FILEPREP = $(call _LOG_HOST,FILEPREP)
91*d4514f0bSApple OSS Distributions
92*d4514f0bSApple OSS Distributions# Host-side linking operations.
93*d4514f0bSApple OSS DistributionsLOG_GENASSYM = $(call _LOG_HOST_LINK,GENASSYM)
94*d4514f0bSApple OSS DistributionsLOG_GENERATE= $(call _LOG_HOST_LINK,GENERATE)
95*d4514f0bSApple OSS DistributionsLOG_CTFCONVERT = $(call _LOG_HOST_LINK,CTFCONVERT)
96*d4514f0bSApple OSS DistributionsLOG_CTFMERGE = $(call _LOG_HOST_LINK,CTFMERGE)
97*d4514f0bSApple OSS DistributionsLOG_CTFINSERT = $(call _LOG_HOST_LINK,CTFINSERT)
98*d4514f0bSApple OSS DistributionsLOG_DSYMUTIL = $(call _LOG_HOST_LINK,DSYMUTIL)
99*d4514f0bSApple OSS DistributionsLOG_SUPPORTED_KPI = $(call _LOG_HOST_LINK,SUPPORTED_KPI)
100*d4514f0bSApple OSS Distributions
101*d4514f0bSApple OSS Distributions
102*d4514f0bSApple OSS Distributionsifeq ($(VERBOSE),YES)
103*d4514f0bSApple OSS Distributions	_v =
104*d4514f0bSApple OSS Distributions	_vstdout =
105*d4514f0bSApple OSS Distributions	_vstderr =
106*d4514f0bSApple OSS Distributions	XCRUN = /usr/bin/xcrun -verbose
107*d4514f0bSApple OSS Distributionselse
108*d4514f0bSApple OSS Distributions	_v = @
109*d4514f0bSApple OSS Distributions	_vstdout = > /dev/null
110*d4514f0bSApple OSS Distributions	_vstderr = 2> /dev/null
111*d4514f0bSApple OSS Distributions	XCRUN = /usr/bin/xcrun
112*d4514f0bSApple OSS Distributionsendif
113*d4514f0bSApple OSS Distributions
114*d4514f0bSApple OSS DistributionsVERBOSE_GENERATED_MAKE_FRAGMENTS = NO
115*d4514f0bSApple OSS Distributions
116*d4514f0bSApple OSS Distributions#
117*d4514f0bSApple OSS Distributions# Defaults
118*d4514f0bSApple OSS Distributions#
119*d4514f0bSApple OSS Distributions
120*d4514f0bSApple OSS DistributionsSDKROOT ?= macosx
121*d4514f0bSApple OSS DistributionsHOST_SDKROOT ?= macosx
122*d4514f0bSApple OSS Distributions
123*d4514f0bSApple OSS Distributions# SDKROOT may be passed as a shorthand like "iphoneos.internal". We
124*d4514f0bSApple OSS Distributions# must resolve these to a full path and override SDKROOT.
125*d4514f0bSApple OSS Distributions
126*d4514f0bSApple OSS Distributionsifeq ($(origin SDKROOT_RESOLVED),undefined)
127*d4514f0bSApple OSS Distributionsexport SDKROOT_RESOLVED := $(shell $(XCRUN) -sdk $(SDKROOT) -show-sdk-path)
128*d4514f0bSApple OSS Distributionsifeq ($(strip $(SDKROOT)_$(SDKROOT_RESOLVED)),/_)
129*d4514f0bSApple OSS Distributionsexport SDKROOT_RESOLVED := /
130*d4514f0bSApple OSS Distributionsendif
131*d4514f0bSApple OSS Distributionsendif
132*d4514f0bSApple OSS Distributionsoverride SDKROOT = $(SDKROOT_RESOLVED)
133*d4514f0bSApple OSS Distributions
134*d4514f0bSApple OSS Distributionsifeq ($(origin HOST_SDKROOT_RESOLVED),undefined)
135*d4514f0bSApple OSS Distributionsexport HOST_SDKROOT_RESOLVED := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -show-sdk-path)
136*d4514f0bSApple OSS Distributionsifeq ($(strip $(HOST_SDKROOT_RESOLVED)),)
137*d4514f0bSApple OSS Distributionsexport HOST_SDKROOT_RESOLVED := /
138*d4514f0bSApple OSS Distributionsendif
139*d4514f0bSApple OSS Distributionsendif
140*d4514f0bSApple OSS Distributionsoverride HOST_SDKROOT = $(HOST_SDKROOT_RESOLVED)
141*d4514f0bSApple OSS Distributions
142*d4514f0bSApple OSS Distributionsifeq ($(origin SDKVERSION),undefined)
143*d4514f0bSApple OSS Distributions     export SDKVERSION := $(shell $(XCRUN) -sdk $(SDKROOT) -show-sdk-version)
144*d4514f0bSApple OSS Distributionsendif
145*d4514f0bSApple OSS Distributions
146*d4514f0bSApple OSS Distributionsifeq ($(origin PLATFORM),undefined)
147*d4514f0bSApple OSS Distributions	export PLATFORMPATH := $(shell $(XCRUN) -sdk $(SDKROOT) -show-sdk-platform-path)
148*d4514f0bSApple OSS Distributions	export PLATFORM := $(shell echo $(PLATFORMPATH) | sed 's,^.*/\([^/]*\)\.platform$$,\1,' | sed 's,\.[^.]*$$,,')
149*d4514f0bSApple OSS Distributions	ifeq ($(PLATFORM),)
150*d4514f0bSApple OSS Distributions		export PLATFORM := MacOSX
151*d4514f0bSApple OSS Distributions	else ifeq ($(shell echo $(PLATFORM) | tr A-Z a-z),watchos)
152*d4514f0bSApple OSS Distributions		export PLATFORM := WatchOS
153*d4514f0bSApple OSS Distributions	endif
154*d4514f0bSApple OSS Distributionsendif
155*d4514f0bSApple OSS Distributions
156*d4514f0bSApple OSS Distributionsifeq ($(PLATFORM),DriverKit)
157*d4514f0bSApple OSS Distributions	ifeq ($(origin COHORT_SDKROOT_RESOLVED),undefined)
158*d4514f0bSApple OSS Distributions		SDK_NAME = $(notdir $(SDKROOT))
159*d4514f0bSApple OSS Distributions		export COHORT_NAME := $(shell echo $(SDK_NAME) | sed -e 's|DriverKit.\([a-zA-Z]*\)$(SDKVERSION)\([.Internal]*\).sdk|\1\2|g' | tr A-Z a-z)
160*d4514f0bSApple OSS Distributions		export COHORT_SDKROOT_RESOLVED := $(shell $(XCRUN) -sdk $(COHORT_NAME) -show-sdk-path)
161*d4514f0bSApple OSS Distributions		ifeq ($(strip $(COHORT_SDKROOT_RESOLVED)),)
162*d4514f0bSApple OSS Distributions		export COHORT_SDKROOT_RESOLVED := $(SDKROOT_RESOLVED)
163*d4514f0bSApple OSS Distributions		endif
164*d4514f0bSApple OSS Distributions	endif
165*d4514f0bSApple OSS Distributions	override COHORT_SDKROOT = $(COHORT_SDKROOT_RESOLVED)
166*d4514f0bSApple OSS Distributions	export PLATFORMPATH = $(shell $(XCRUN) -sdk $(COHORT_SDKROOT) -show-sdk-platform-path)
167*d4514f0bSApple OSS Distributions	export PLATFORM := DriverKit
168*d4514f0bSApple OSS Distributions	export DRIVERKIT ?= 1
169*d4514f0bSApple OSS Distributions	export DRIVERKITROOT ?= /System/DriverKit
170*d4514f0bSApple OSS Distributions	export DRIVERKITRUNTIMEROOT = $(DRIVERKITROOT)/Runtime
171*d4514f0bSApple OSS Distributionselse
172*d4514f0bSApple OSS Distributions	override COHORT_SDKROOT = $(SDKROOT)
173*d4514f0bSApple OSS Distributionsendif
174*d4514f0bSApple OSS Distributions
175*d4514f0bSApple OSS Distributionsifeq ($(PLATFORM),MacOSX)
176*d4514f0bSApple OSS Distributions	ifeq (DriverKit,$(shell echo $(SDKROOT_RESOLVED) | sed 's|^.*/\([^./1-9]*\)\(\.[^./1-9]*\)\{0,1\}[1-9][^/]*\.sdk$$|\1|'))
177*d4514f0bSApple OSS Distributions		export PLATFORM := DriverKit
178*d4514f0bSApple OSS Distributions		export DRIVERKIT ?= 1
179*d4514f0bSApple OSS Distributions		export DRIVERKITROOT ?= /System/DriverKit
180*d4514f0bSApple OSS Distributions		export DRIVERKITRUNTIMEROOT = $(DRIVERKITROOT)/Runtime
181*d4514f0bSApple OSS Distributions	endif
182*d4514f0bSApple OSS Distributionsendif
183*d4514f0bSApple OSS Distributions
184*d4514f0bSApple OSS Distributionsifeq ($(PLATFORM),ExclaveKit)
185*d4514f0bSApple OSS Distributions	ifeq ($(origin COHORT_SDKROOT_RESOLVED),undefined)
186*d4514f0bSApple OSS Distributions		SDK_NAME = $(notdir $(SDKROOT))
187*d4514f0bSApple OSS Distributions		export COHORT_NAME := $(shell echo $(SDK_NAME) | sed -e 's|ExclaveKit.\([a-zA-Z]*\)$(SDKVERSION)\([.Internal]*\).sdk|\1\2|g' | tr A-Z a-z)
188*d4514f0bSApple OSS Distributions		export COHORT_SDKROOT_RESOLVED := $(shell $(XCRUN) -sdk $(COHORT_NAME) -show-sdk-path)
189*d4514f0bSApple OSS Distributions		ifeq ($(strip $(COHORT_SDKROOT_RESOLVED)),)
190*d4514f0bSApple OSS Distributions		export COHORT_SDKROOT_RESOLVED := $(SDKROOT_RESOLVED)
191*d4514f0bSApple OSS Distributions		endif
192*d4514f0bSApple OSS Distributions	endif
193*d4514f0bSApple OSS Distributions	override COHORT_SDKROOT = $(COHORT_SDKROOT_RESOLVED)
194*d4514f0bSApple OSS Distributions	export PLATFORMPATH = $(shell $(XCRUN) -sdk $(COHORT_SDKROOT) -show-sdk-platform-path)
195*d4514f0bSApple OSS Distributions	export PLATFORM := ExclaveKit
196*d4514f0bSApple OSS Distributions	export EXCLAVEKIT ?= 1
197*d4514f0bSApple OSS Distributions	export EXCLAVEKITROOT ?= /System/ExclaveKit
198*d4514f0bSApple OSS Distributionsendif
199*d4514f0bSApple OSS Distributions
200*d4514f0bSApple OSS Distributionsifeq ($(PLATFORM),ExclaveCore)
201*d4514f0bSApple OSS Distributions	ifeq ($(origin COHORT_SDKROOT_RESOLVED),undefined)
202*d4514f0bSApple OSS Distributions		SDK_NAME = $(notdir $(SDKROOT))
203*d4514f0bSApple OSS Distributions		export COHORT_NAME := $(shell echo $(SDK_NAME) | sed -e 's|ExclaveCore.\([a-zA-Z]*\)$(SDKVERSION)\([.Internal]*\).sdk|\1\2|g' | tr A-Z a-z)
204*d4514f0bSApple OSS Distributions		export COHORT_SDKROOT_RESOLVED := $(shell $(XCRUN) -sdk $(COHORT_NAME) -show-sdk-path)
205*d4514f0bSApple OSS Distributions		ifeq ($(strip $(COHORT_SDKROOT_RESOLVED)),)
206*d4514f0bSApple OSS Distributions		export COHORT_SDKROOT_RESOLVED := $(SDKROOT_RESOLVED)
207*d4514f0bSApple OSS Distributions		endif
208*d4514f0bSApple OSS Distributions	endif
209*d4514f0bSApple OSS Distributions	override COHORT_SDKROOT = $(COHORT_SDKROOT_RESOLVED)
210*d4514f0bSApple OSS Distributions	export PLATFORMPATH = $(shell $(XCRUN) -sdk $(COHORT_SDKROOT) -show-sdk-platform-path)
211*d4514f0bSApple OSS Distributions	export PLATFORM := ExclaveCore
212*d4514f0bSApple OSS Distributions	export EXCLAVECORE ?= 1
213*d4514f0bSApple OSS Distributions	export EXCLAVECOREROOT ?= /System/ExclaveCore
214*d4514f0bSApple OSS Distributionsendif
215*d4514f0bSApple OSS Distributions
216*d4514f0bSApple OSS Distributions# CC/CXX get defined by make(1) by default, so we can't check them
217*d4514f0bSApple OSS Distributions# against the empty string to see if they haven't been set
218*d4514f0bSApple OSS Distributionsifeq ($(origin CC),default)
219*d4514f0bSApple OSS Distributions	export CC := $(shell $(XCRUN) -sdk $(SDKROOT) -find clang)
220*d4514f0bSApple OSS Distributionsendif
221*d4514f0bSApple OSS Distributionsifeq ($(origin CXX),default)
222*d4514f0bSApple OSS Distributions	export CXX := $(shell $(XCRUN) -sdk $(SDKROOT) -find clang++)
223*d4514f0bSApple OSS Distributionsendif
224*d4514f0bSApple OSS Distributionsifeq ($(origin MIG),undefined)
225*d4514f0bSApple OSS Distributions	export MIG := $(shell $(XCRUN) -sdk $(SDKROOT) -find mig)
226*d4514f0bSApple OSS Distributionsendif
227*d4514f0bSApple OSS Distributionsifeq ($(origin MIGCOM),undefined)
228*d4514f0bSApple OSS Distributions	export MIGCOM := $(shell $(XCRUN) -sdk $(SDKROOT) -find migcom)
229*d4514f0bSApple OSS Distributionsendif
230*d4514f0bSApple OSS Distributionsifeq ($(origin MIGCC),undefined)
231*d4514f0bSApple OSS Distributions	export MIGCC := $(CC)
232*d4514f0bSApple OSS Distributionsendif
233*d4514f0bSApple OSS Distributionsifeq ($(origin IIG),undefined)
234*d4514f0bSApple OSS Distributions	export IIG := $(shell $(XCRUN) -sdk $(SDKROOT) -find iig)
235*d4514f0bSApple OSS Distributionsendif
236*d4514f0bSApple OSS Distributionsifeq ($(origin STRIP),undefined)
237*d4514f0bSApple OSS Distributions	export STRIP := $(shell $(XCRUN) -sdk $(SDKROOT) -find strip)
238*d4514f0bSApple OSS Distributionsendif
239*d4514f0bSApple OSS Distributionsifeq ($(origin LIPO),undefined)
240*d4514f0bSApple OSS Distributions	export LIPO := $(shell $(XCRUN) -sdk $(SDKROOT) -find lipo)
241*d4514f0bSApple OSS Distributionsendif
242*d4514f0bSApple OSS Distributionsifeq ($(origin LIBTOOL),undefined)
243*d4514f0bSApple OSS Distributions	export LIBTOOL := $(shell $(XCRUN) -sdk $(SDKROOT) -find libtool)
244*d4514f0bSApple OSS Distributionsendif
245*d4514f0bSApple OSS Distributionsifeq ($(origin OTOOL),undefined)
246*d4514f0bSApple OSS Distributions	export OTOOL := $(shell $(XCRUN) -sdk $(SDKROOT) -find otool)
247*d4514f0bSApple OSS Distributionsendif
248*d4514f0bSApple OSS Distributionsifeq ($(origin NM),undefined)
249*d4514f0bSApple OSS Distributions	export NM := $(shell $(XCRUN) -sdk $(SDKROOT) -find nm)
250*d4514f0bSApple OSS Distributionsendif
251*d4514f0bSApple OSS Distributionsifeq ($(origin UNIFDEF),undefined)
252*d4514f0bSApple OSS Distributions	export UNIFDEF := $(shell $(XCRUN) -sdk $(SDKROOT) -find unifdef)
253*d4514f0bSApple OSS Distributionsendif
254*d4514f0bSApple OSS Distributionsifeq ($(origin DSYMUTIL),undefined)
255*d4514f0bSApple OSS Distributions	export DSYMUTIL := $(shell $(XCRUN) -sdk $(SDKROOT) -find dsymutil)
256*d4514f0bSApple OSS Distributionsendif
257*d4514f0bSApple OSS Distributionsifeq ($(origin NMEDIT),undefined)
258*d4514f0bSApple OSS Distributions	export NMEDIT := $(shell $(XCRUN) -sdk $(SDKROOT) -find nmedit)
259*d4514f0bSApple OSS Distributionsendif
260*d4514f0bSApple OSS Distributionsifeq ($(origin GIT),undefined)
261*d4514f0bSApple OSS Distributions	export GIT := $(shell $(XCRUN) -sdk $(SDKROOT) -find git)
262*d4514f0bSApple OSS Distributionsendif
263*d4514f0bSApple OSS Distributionsifeq ($(origin SCAN_BUILD),undefined)
264*d4514f0bSApple OSS Distributions	export SCAN_BUILD := $(shell $(XCRUN) -sdk $(SDKROOT) -find scan-build 2> /dev/null)
265*d4514f0bSApple OSS Distributionsendif
266*d4514f0bSApple OSS Distributionsifeq ($(origin CTFINSERT),undefined)
267*d4514f0bSApple OSS Distributions	export CTFINSERT := $(shell $(XCRUN) -sdk $(SDKROOT) -find ctf_insert 2> /dev/null)
268*d4514f0bSApple OSS Distributionsendif
269*d4514f0bSApple OSS Distributionsifeq ($(origin CTFCONVERT),undefined)
270*d4514f0bSApple OSS Distributions	export CTFCONVERT := $(shell $(XCRUN) -sdk $(SDKROOT) -find ctfconvert 2> /dev/null)
271*d4514f0bSApple OSS Distributionsendif
272*d4514f0bSApple OSS Distributionsifeq ($(origin CTFMERGE),undefined)
273*d4514f0bSApple OSS Distributions	export CTFMERGE := $(shell $(XCRUN) -sdk $(SDKROOT) -find ctfmerge 2> /dev/null)
274*d4514f0bSApple OSS Distributions	ifeq (,$(wildcard $(CTFMERGE)))
275*d4514f0bSApple OSS Distributions		export DO_CTFMERGE := 0
276*d4514f0bSApple OSS Distributions	endif
277*d4514f0bSApple OSS Distributionsendif
278*d4514f0bSApple OSS Distributionsifeq ($(origin CTFDUMP),undefined)
279*d4514f0bSApple OSS Distributions	export CTFDUMP := $(shell $(XCRUN) -sdk $(SDKROOT) -find ctfdump 2> /dev/null)
280*d4514f0bSApple OSS Distributionsendif
281*d4514f0bSApple OSS Distributionsifeq ($(origin DOCC),undefined)
282*d4514f0bSApple OSS Distributions	export DOCC := $(shell $(XCRUN) -sdk $(SDKROOT) -find docc 2> /dev/null)
283*d4514f0bSApple OSS Distributionsendif
284*d4514f0bSApple OSS Distributionsifeq ($(origin PYTHON),undefined)
285*d4514f0bSApple OSS Distributions	export PYTHON := $(shell $(XCRUN) -sdk $(SDKROOT) -find python3 2> /dev/null)
286*d4514f0bSApple OSS Distributionsendif
287*d4514f0bSApple OSS Distributionsifeq ($(origin OBJDUMP),undefined)
288*d4514f0bSApple OSS Distributions	export OBJDUMP := $(shell $(XCRUN) -sdk $(SDKROOT) -find objdump 2> /dev/null)
289*d4514f0bSApple OSS Distributionsendif
290*d4514f0bSApple OSS Distributions
291*d4514f0bSApple OSS Distributions#
292*d4514f0bSApple OSS Distributions# Platform options
293*d4514f0bSApple OSS Distributions#
294*d4514f0bSApple OSS DistributionsSUPPORTED_EMBEDDED_PLATFORMS := iPhoneOS iPhoneOSNano tvOS AppleTVOS WatchOS BridgeOS
295*d4514f0bSApple OSS DistributionsSUPPORTED_SIMULATOR_PLATFORMS := iPhoneSimulator iPhoneNanoSimulator tvSimulator AppleTVSimulator WatchSimulator
296*d4514f0bSApple OSS Distributions
297*d4514f0bSApple OSS Distributions
298*d4514f0bSApple OSS DistributionsSUPPORTED_PLATFORMS := MacOSX DriverKit ExclaveKit ExclaveCore $(SUPPORTED_SIMULATOR_PLATFORMS) $(SUPPORTED_EMBEDDED_PLATFORMS)
299*d4514f0bSApple OSS Distributions
300*d4514f0bSApple OSS Distributions# Platform-specific tools
301*d4514f0bSApple OSS DistributionsEDM_DBPATH ?= $(PLATFORMPATH)/usr/local/standalone/firmware/device_map.db
302*d4514f0bSApple OSS Distributions
303*d4514f0bSApple OSS Distributions# Scripts or tools we build ourselves
304*d4514f0bSApple OSS Distributions#
305*d4514f0bSApple OSS Distributions# setsegname - Rename segments in a Mach-O object file
306*d4514f0bSApple OSS Distributions# kextsymboltool - Create kext pseudo-kext Mach-O kexts binaries
307*d4514f0bSApple OSS Distributions# decomment - Strip out comments to detect whether a file is comments-only
308*d4514f0bSApple OSS Distributions# installfile - Atomically copy files, esp. when multiple architectures
309*d4514f0bSApple OSS Distributions#               are trying to install the same target header
310*d4514f0bSApple OSS Distributions# replacecontents - Write contents to a file and update modtime *only* if
311*d4514f0bSApple OSS Distributions#                   contents differ
312*d4514f0bSApple OSS Distributions# vm_sanitize_enforcement - Reject MIG files that use types that do not enforce
313*d4514f0bSApple OSS Distributions#                           sanitization for VM inputs
314*d4514f0bSApple OSS Distributions#
315*d4514f0bSApple OSS DistributionsSEG_HACK = $(OBJROOT)/SETUP/setsegname/setsegname
316*d4514f0bSApple OSS DistributionsKEXT_CREATE_SYMBOL_SET = $(OBJROOT)/SETUP/kextsymboltool/kextsymboltool
317*d4514f0bSApple OSS DistributionsDECOMMENT = $(OBJROOT)/SETUP/decomment/decomment
318*d4514f0bSApple OSS DistributionsNEWVERS = $(SRCROOT)/config/newvers.pl
319*d4514f0bSApple OSS DistributionsINSTALL = $(OBJROOT)/SETUP/installfile/installfile
320*d4514f0bSApple OSS DistributionsREPLACECONTENTS = $(OBJROOT)/SETUP/replacecontents/replacecontents
321*d4514f0bSApple OSS DistributionsVM_SANITIZE_ADOPTION_CHECK = $(SRCROOT)/tools/vm_sanitize_enforcement.py
322*d4514f0bSApple OSS Distributions
323*d4514f0bSApple OSS Distributions# Standard BSD tools
324*d4514f0bSApple OSS DistributionsRM = /bin/rm -f
325*d4514f0bSApple OSS DistributionsRMDIR = /bin/rmdir
326*d4514f0bSApple OSS DistributionsCP = /bin/cp
327*d4514f0bSApple OSS DistributionsMV = /bin/mv
328*d4514f0bSApple OSS DistributionsLN = /bin/ln -fs
329*d4514f0bSApple OSS DistributionsCAT = /bin/cat
330*d4514f0bSApple OSS DistributionsMKDIR = /bin/mkdir -p
331*d4514f0bSApple OSS DistributionsCHMOD = /bin/chmod
332*d4514f0bSApple OSS DistributionsFIND = /usr/bin/find
333*d4514f0bSApple OSS DistributionsXARGS = /usr/bin/xargs
334*d4514f0bSApple OSS DistributionsPAX = /bin/pax
335*d4514f0bSApple OSS DistributionsBASENAME = /usr/bin/basename
336*d4514f0bSApple OSS DistributionsDIRNAME = /usr/bin/dirname
337*d4514f0bSApple OSS DistributionsTR = /usr/bin/tr
338*d4514f0bSApple OSS DistributionsTOUCH = /usr/bin/touch
339*d4514f0bSApple OSS DistributionsSLEEP = /bin/sleep
340*d4514f0bSApple OSS DistributionsAWK = /usr/bin/awk
341*d4514f0bSApple OSS DistributionsSED = /usr/bin/sed
342*d4514f0bSApple OSS DistributionsPLUTIL = /usr/bin/plutil
343*d4514f0bSApple OSS DistributionsPATCH = /usr/bin/patch
344*d4514f0bSApple OSS DistributionsGREP = /usr/bin/grep
345*d4514f0bSApple OSS Distributions
346*d4514f0bSApple OSS Distributions#
347*d4514f0bSApple OSS Distributions# Command to generate host binaries. Intentionally not
348*d4514f0bSApple OSS Distributions# $(CC), which controls the target compiler
349*d4514f0bSApple OSS Distributions#
350*d4514f0bSApple OSS Distributionsifeq ($(origin HOST_OS_VERSION),undefined)
351*d4514f0bSApple OSS Distributions	export HOST_OS_VERSION	:= $(shell sw_vers -productVersion)
352*d4514f0bSApple OSS Distributionsendif
353*d4514f0bSApple OSS Distributionsifeq ($(origin HOST_CC),undefined)
354*d4514f0bSApple OSS Distributions	export HOST_CC		:= $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find clang)
355*d4514f0bSApple OSS Distributionsendif
356*d4514f0bSApple OSS Distributionsifeq ($(origin HOST_FLEX),undefined)
357*d4514f0bSApple OSS Distributions	export HOST_FLEX	:= $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find flex)
358*d4514f0bSApple OSS Distributionsendif
359*d4514f0bSApple OSS Distributionsifeq ($(origin HOST_BISON),undefined)
360*d4514f0bSApple OSS Distributions	export HOST_BISON	:= $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find bison)
361*d4514f0bSApple OSS Distributionsendif
362*d4514f0bSApple OSS Distributionsifeq ($(origin HOST_GM4),undefined)
363*d4514f0bSApple OSS Distributions	export HOST_GM4		:= $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find gm4)
364*d4514f0bSApple OSS Distributionsendif
365*d4514f0bSApple OSS Distributionsifeq ($(origin HOST_CODESIGN),undefined)
366*d4514f0bSApple OSS Distributions	export HOST_CODESIGN	:= /usr/bin/codesign
367*d4514f0bSApple OSS Distributionsendif
368*d4514f0bSApple OSS Distributionsifeq ($(origin HOST_CODESIGN_ALLOCATE),undefined)
369*d4514f0bSApple OSS Distributions	export HOST_CODESIGN_ALLOCATE	:= $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find codesign_allocate)
370*d4514f0bSApple OSS Distributionsendif
371*d4514f0bSApple OSS Distributions
372*d4514f0bSApple OSS Distributions#
373*d4514f0bSApple OSS Distributions# The following variables are functions invoked with "call", and thus
374*d4514f0bSApple OSS Distributions# behave similarly to externally compiled commands
375*d4514f0bSApple OSS Distributions#
376*d4514f0bSApple OSS Distributions
377*d4514f0bSApple OSS Distributions# $(1) is an expanded kernel config from a TARGET_CONFIGS_UC tuple
378*d4514f0bSApple OSS Distributions# $(2) is an expanded arch config from a TARGET_CONFIGS_UC tuple
379*d4514f0bSApple OSS Distributions# $(3) is an expanded machine config from a TARGET_CONFIGS_UC tuple
380*d4514f0bSApple OSS Distributions_function_create_build_configs_join = $(strip $(1))^$(strip $(2))^$(strip $(3))
381*d4514f0bSApple OSS Distributions
382*d4514f0bSApple OSS Distributions# $(1) is an un-expanded kernel config from a TARGET_CONFIGS_UC tuple
383*d4514f0bSApple OSS Distributions# $(2) is an un-expanded arch config from a TARGET_CONFIGS_UC tuple
384*d4514f0bSApple OSS Distributions# $(3) is an un-expanded machine config from a TARGET_CONFIGS_UC tuple
385*d4514f0bSApple OSS Distributions_function_create_build_configs_do_expand =          $(call _function_create_build_configs_join, \
386*d4514f0bSApple OSS Distributions							   $(if $(filter DEFAULT,$(1)), \
387*d4514f0bSApple OSS Distributions								$(DEFAULT_KERNEL_CONFIG), \
388*d4514f0bSApple OSS Distributions								$(1) \
389*d4514f0bSApple OSS Distributions							    ), \
390*d4514f0bSApple OSS Distributions							   $(if $(filter DEFAULT,$(2)), \
391*d4514f0bSApple OSS Distributions								$(DEFAULT_ARCH_CONFIG), \
392*d4514f0bSApple OSS Distributions								$(2) \
393*d4514f0bSApple OSS Distributions							    ), \
394*d4514f0bSApple OSS Distributions							   $(if $(filter DEFAULT,$(3)), \
395*d4514f0bSApple OSS Distributions								$(if $(filter DEFAULT,$(2)), \
396*d4514f0bSApple OSS Distributions								     $(DEFAULT_$(DEFAULT_ARCH_CONFIG)_MACHINE_CONFIG), \
397*d4514f0bSApple OSS Distributions								     $(DEFAULT_$(strip $(2))_MACHINE_CONFIG) \
398*d4514f0bSApple OSS Distributions								), \
399*d4514f0bSApple OSS Distributions								$(3) \
400*d4514f0bSApple OSS Distributions							    ) \
401*d4514f0bSApple OSS Distributions						     )
402*d4514f0bSApple OSS Distributions
403*d4514f0bSApple OSS Distributions# $(1) is an un-expanded TARGET_CONFIGS_UC list, which must be consumed
404*d4514f0bSApple OSS Distributions#      3 elements at a time
405*d4514f0bSApple OSS Distributionsfunction_create_build_configs = $(sort \
406*d4514f0bSApple OSS Distributions					$(strip \
407*d4514f0bSApple OSS Distributions						 $(call _function_create_build_configs_do_expand, \
408*d4514f0bSApple OSS Distributions							$(word 1,$(1)), \
409*d4514f0bSApple OSS Distributions							$(word 2,$(1)), \
410*d4514f0bSApple OSS Distributions							$(word 3,$(1)), \
411*d4514f0bSApple OSS Distributions						  ) \
412*d4514f0bSApple OSS Distributions						 $(if $(word 4,$(1)), \
413*d4514f0bSApple OSS Distributions						      $(call function_create_build_configs, \
414*d4514f0bSApple OSS Distributions							     $(wordlist 4,$(words $(1)),$(1)) \
415*d4514f0bSApple OSS Distributions						       ), \
416*d4514f0bSApple OSS Distributions						  ) \
417*d4514f0bSApple OSS Distributions					  ) \
418*d4514f0bSApple OSS Distributions				   )
419*d4514f0bSApple OSS Distributions
420*d4514f0bSApple OSS Distributions# Similar to build configs, but alias configs are a 4-tuple
421*d4514f0bSApple OSS Distributions
422*d4514f0bSApple OSS Distributions# $(1) is an expanded kernel config from a TARGET_CONFIGS_ALIASES_UC tuple
423*d4514f0bSApple OSS Distributions# $(2) is an expanded arch config from a TARGET_CONFIGS_ALIASES_UC tuple
424*d4514f0bSApple OSS Distributions# $(3) is an expanded kernel machine config from a TARGET_CONFIGS_ALIASES_UC tuple
425*d4514f0bSApple OSS Distributions# $(4) is an expanded SoC platform config from a TARGET_CONFIGS_ALIASES_UC tuple,
426*d4514f0bSApple OSS Distributions#      which should be an alias of $(3)
427*d4514f0bSApple OSS Distributions_function_create_alias_configs_join = $(strip $(1))^$(strip $(2))^$(strip $(3))^$(strip $(4))
428*d4514f0bSApple OSS Distributions
429*d4514f0bSApple OSS Distributions_function_create_alias_configs_do_expand =	    $(call _function_create_alias_configs_join, \
430*d4514f0bSApple OSS Distributions							   $(if $(filter DEFAULT,$(1)), \
431*d4514f0bSApple OSS Distributions							        $(DEFAULT_KERNEL_CONFIG), \
432*d4514f0bSApple OSS Distributions								$(1) \
433*d4514f0bSApple OSS Distributions							    ), \
434*d4514f0bSApple OSS Distributions							   $(if $(filter DEFAULT,$(2)), \
435*d4514f0bSApple OSS Distributions								$(DEFAULT_ARCH_CONFIG), \
436*d4514f0bSApple OSS Distributions								$(2) \
437*d4514f0bSApple OSS Distributions							    ), \
438*d4514f0bSApple OSS Distributions							   $(3), \
439*d4514f0bSApple OSS Distributions							   $(4) \
440*d4514f0bSApple OSS Distributions						     )
441*d4514f0bSApple OSS Distributions
442*d4514f0bSApple OSS Distributionsfunction_create_alias_configs = $(sort \
443*d4514f0bSApple OSS Distributions					$(strip \
444*d4514f0bSApple OSS Distributions						 $(call _function_create_alias_configs_do_expand, \
445*d4514f0bSApple OSS Distributions							$(word 1,$(1)), \
446*d4514f0bSApple OSS Distributions							$(word 2,$(1)), \
447*d4514f0bSApple OSS Distributions							$(word 3,$(1)), \
448*d4514f0bSApple OSS Distributions							$(word 4,$(1)), \
449*d4514f0bSApple OSS Distributions						  ) \
450*d4514f0bSApple OSS Distributions						 $(if $(word 5,$(1)), \
451*d4514f0bSApple OSS Distributions						      $(call function_create_alias_configs, \
452*d4514f0bSApple OSS Distributions							     $(wordlist 5,$(words $(1)),$(1)) \
453*d4514f0bSApple OSS Distributions						       ), \
454*d4514f0bSApple OSS Distributions						  ) \
455*d4514f0bSApple OSS Distributions					 ) \
456*d4514f0bSApple OSS Distributions				 )
457*d4514f0bSApple OSS Distributions
458*d4514f0bSApple OSS Distributions# $(1) is a fully-expanded kernel config
459*d4514f0bSApple OSS Distributions# $(2) is a fully-expanded arch config
460*d4514f0bSApple OSS Distributions# $(3) is a fully-expanded machine config. "NONE" is not represented in the objdir path
461*d4514f0bSApple OSS Distributionsfunction_convert_target_config_uc_to_objdir = $(if $(filter NONE,$(3)),$(strip $(1))_$(strip $(2)),$(strip $(1))_$(strip $(2))_$(strip $(3)))
462*d4514f0bSApple OSS Distributions
463*d4514f0bSApple OSS Distributions# $(1) is a fully-expanded build config (like "RELEASE^X86_64^NONE")
464*d4514f0bSApple OSS Distributionsfunction_convert_build_config_to_objdir = $(call function_convert_target_config_uc_to_objdir, \
465*d4514f0bSApple OSS Distributions						 $(word 1,$(subst ^, ,$(1))), \
466*d4514f0bSApple OSS Distributions						 $(word 2,$(subst ^, ,$(1))), \
467*d4514f0bSApple OSS Distributions						 $(word 3,$(subst ^, ,$(1))) \
468*d4514f0bSApple OSS Distributions					   )
469*d4514f0bSApple OSS Distributions
470*d4514f0bSApple OSS Distributions# $(1) is a fully-expanded build config (like "RELEASE^X86_64^NONE")
471*d4514f0bSApple OSS Distributionsfunction_extract_kernel_config_from_build_config  = $(word 1,$(subst ^, ,$(1)))
472*d4514f0bSApple OSS Distributionsfunction_extract_arch_config_from_build_config    = $(word 2,$(subst ^, ,$(1)))
473*d4514f0bSApple OSS Distributionsfunction_extract_machine_config_from_build_config = $(word 3,$(subst ^, ,$(1)))
474*d4514f0bSApple OSS Distributions
475*d4514f0bSApple OSS Distributions#
476*d4514f0bSApple OSS Distributions# Returns build config if both architecture and kernel configuration match.
477*d4514f0bSApple OSS Distributions#
478*d4514f0bSApple OSS Distributions#   $(1) - list of build configs
479*d4514f0bSApple OSS Distributions#   $(1) - architecture
480*d4514f0bSApple OSS Distributions#   $(2) - kernel configuration
481*d4514f0bSApple OSS Distributions
482*d4514f0bSApple OSS Distributionsfunction_match_build_config_for_architecture_and_kernel_config = $(strip \
483*d4514f0bSApple OSS Distributions			    $(foreach build_config, $(1), \
484*d4514f0bSApple OSS Distributions			      $(if \
485*d4514f0bSApple OSS Distributions				$(and \
486*d4514f0bSApple OSS Distributions				  $(filter $(2), $(call function_extract_arch_config_from_build_config, $(build_config))), \
487*d4514f0bSApple OSS Distributions				  $(filter $(3), $(call function_extract_kernel_config_from_build_config, $(build_config)))), \
488*d4514f0bSApple OSS Distributions			      $(build_config), )))
489*d4514f0bSApple OSS Distributions
490*d4514f0bSApple OSS Distributions#
491*d4514f0bSApple OSS Distributions# Returns build config if kernel configuration matches.
492*d4514f0bSApple OSS Distributions#
493*d4514f0bSApple OSS Distributions#   $(1) - list of build configs
494*d4514f0bSApple OSS Distributions#   $(2) - kernel configuration
495*d4514f0bSApple OSS Distributions
496*d4514f0bSApple OSS Distributionsfunction_match_build_config_for_kernel_config = $(strip \
497*d4514f0bSApple OSS Distributions			    $(foreach build_config, $(1), \
498*d4514f0bSApple OSS Distributions			      $(if \
499*d4514f0bSApple OSS Distributions				  $(filter $(2), $(call function_extract_kernel_config_from_build_config, $(build_config))), \
500*d4514f0bSApple OSS Distributions			      $(build_config), )))
501*d4514f0bSApple OSS Distributions
502*d4514f0bSApple OSS Distributions# $(1) is an input word
503*d4514f0bSApple OSS Distributions# $(2) is a list of colon-separate potential substitutions like "FOO:BAR BAZ:QUX"
504*d4514f0bSApple OSS Distributions# $(3) is a fallback if no substitutions were made
505*d4514f0bSApple OSS Distributionsfunction_substitute_word_with_replacement = $(strip $(if $(2),								\
506*d4514f0bSApple OSS Distributions							 $(if $(filter $(word 1,$(subst :, ,$(word 1,$(2)))),$(1)),	\
507*d4514f0bSApple OSS Distributions							      $(word 2,$(subst :, ,$(word 1,$(2)))),		\
508*d4514f0bSApple OSS Distributions							      $(call function_substitute_word_with_replacement,$(1),$(wordlist 2,$(words $(2)),$(2)),$(3))), \
509*d4514f0bSApple OSS Distributions							 $(3)								\
510*d4514f0bSApple OSS Distributions						     )									\
511*d4514f0bSApple OSS Distributions					     )
512*d4514f0bSApple OSS Distributions
513*d4514f0bSApple OSS Distributions# You can't assign a variable to an empty space without these
514*d4514f0bSApple OSS Distributions# shenanigans
515*d4514f0bSApple OSS Distributionsempty :=
516*d4514f0bSApple OSS Distributionsspace := $(empty) $(empty)
517*d4514f0bSApple OSS Distributions
518*d4514f0bSApple OSS Distributions# Arithmetic
519*d4514f0bSApple OSS Distributions# $(1) is the number to increment
520*d4514f0bSApple OSS DistributionsNUM32 = 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
521*d4514f0bSApple OSS Distributionsincrement = $(words x $(wordlist 1,$(1),$(NUM32)))
522*d4514f0bSApple OSS Distributionsdecrement = $(words $(wordlist 2,$(1),$(NUM32)))
523*d4514f0bSApple OSS Distributions
524*d4514f0bSApple OSS Distributions# Create a sequence from 1 to $(1)
525*d4514f0bSApple OSS Distributions# F(N) = if N > 0: return F(N-1) + "N" else: return ""
526*d4514f0bSApple OSS Distributionssequence = $(if $(wordlist 1,$(1),$(NUM32)),$(call sequence,$(call decrement,$(1))) $(1),)
527*d4514f0bSApple OSS Distributions
528*d4514f0bSApple OSS Distributions# Reverse a list of words in $(1)
529*d4514f0bSApple OSS Distributionsreverse = $(if $(word 2,$(1)),$(call reverse,$(wordlist 2,$(words $(1)),$(1)))) $(word 1,$(1))
530*d4514f0bSApple OSS Distributions
531*d4514f0bSApple OSS Distributions# vim: set ft=make:
532