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