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