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