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