]> git.saurik.com Git - apple/xnu.git/blame_incremental - makedefs/MakeInc.cmd
xnu-6153.11.26.tar.gz
[apple/xnu.git] / makedefs / MakeInc.cmd
... / ...
CommitLineData
1# -*- mode: makefile;-*-
2#
3# Copyright (C) 1999-2016 Apple Inc. All rights reserved.
4#
5# MakeInc.cmd contains command paths for use during
6# the build, as well as make fragments and text
7# strings that may be evaluated as utility functions.
8#
9
10#
11# Commands for the build environment
12#
13
14##
15# Verbosity
16##
17
18ifeq ($(RC_XBS),YES)
19 VERBOSE = YES
20else
21 VERBOSE = NO
22endif
23
24ECHO = echo
25
26LOG = echo
27makelog = $(info $1)
28ERR = $(ECHO) > /dev/stderr
29
30QUIET ?= 0
31ifneq ($(QUIET),0)
32 LOG = :
33 makelog =
34 ifeq ($(VERBOSE),YES)
35 override VERBOSE = NO
36 endif
37endif
38
39ifeq ($(VERBOSE),YES)
40 _v =
41 _vstdout =
42 XCRUN = /usr/bin/xcrun -verbose
43else
44 _v = @
45 _vstdout = > /dev/null
46 XCRUN = /usr/bin/xcrun
47endif
48
49VERBOSE_GENERATED_MAKE_FRAGMENTS = NO
50
51SDKROOT ?= macosx
52HOST_SDKROOT ?= macosx
53
54# SDKROOT may be passed as a shorthand like "iphoneos.internal". We
55# must resolve these to a full path and override SDKROOT.
56
57ifeq ($(SDKROOT_RESOLVED),)
58export SDKROOT_RESOLVED := $(shell $(XCRUN) -sdk $(SDKROOT) -show-sdk-path)
59ifeq ($(strip $(SDKROOT)_$(SDKROOT_RESOLVED)),/_)
60export SDKROOT_RESOLVED := /
61endif
62endif
63override SDKROOT = $(SDKROOT_RESOLVED)
64
65ifeq ($(HOST_SDKROOT_RESOLVED),)
66export HOST_SDKROOT_RESOLVED := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -show-sdk-path)
67ifeq ($(strip $(HOST_SDKROOT_RESOLVED)),)
68export HOST_SDKROOT_RESOLVED := /
69endif
70endif
71override HOST_SDKROOT = $(HOST_SDKROOT_RESOLVED)
72
73ifeq ($(PLATFORM),)
74 export PLATFORMPATH := $(shell $(XCRUN) -sdk $(SDKROOT) -show-sdk-platform-path)
75 export PLATFORM := $(shell echo $(PLATFORMPATH) | sed 's,^.*/\([^/]*\)\.platform$$,\1,')
76 ifeq ($(PLATFORM),)
77 export PLATFORM := MacOSX
78 else ifeq ($(shell echo $(PLATFORM) | tr A-Z a-z),watchos)
79 export PLATFORM := WatchOS
80 endif
81endif
82
83ifeq ($(PLATFORM),MacOSX)
84 ifeq (DriverKit,$(shell echo $(SDKROOT_RESOLVED) | sed 's,^.*/\([^/1-9]*\)[1-9][^/]*\.sdk$$,\1,'))
85 export PLATFORM := DriverKit
86 export DRIVERKIT ?= 1
87 export DRIVERKITROOT ?= /System/DriverKit
88 export DRIVERKITRUNTIMEROOT = $(DRIVERKITROOT)/Runtime
89 endif
90endif
91
92ifeq ($(SDKVERSION),)
93 export SDKVERSION := $(shell $(XCRUN) -sdk $(SDKROOT) -show-sdk-version)
94endif
95
96# CC/CXX get defined by make(1) by default, so we can't check them
97# against the empty string to see if they haven't been set
98ifeq ($(origin CC),default)
99 export CC := $(shell $(XCRUN) -sdk $(SDKROOT) -find clang)
100endif
101ifeq ($(origin CXX),default)
102 export CXX := $(shell $(XCRUN) -sdk $(SDKROOT) -find clang++)
103endif
104ifeq ($(MIG),)
105 export MIG := $(shell $(XCRUN) -sdk $(SDKROOT) -find mig)
106endif
107ifeq ($(MIGCOM),)
108 export MIGCOM := $(shell $(XCRUN) -sdk $(SDKROOT) -find migcom)
109endif
110ifeq ($(MIGCC),)
111 export MIGCC := $(CC)
112endif
113ifeq ($(IIG),)
114 export IIG := $(shell $(XCRUN) -sdk $(SDKROOT) -find iig)
115endif
116ifeq ($(STRIP),)
117 export STRIP := $(shell $(XCRUN) -sdk $(SDKROOT) -find strip)
118endif
119ifeq ($(LIPO),)
120 export LIPO := $(shell $(XCRUN) -sdk $(SDKROOT) -find lipo)
121endif
122ifeq ($(LIBTOOL),)
123 export LIBTOOL := $(shell $(XCRUN) -sdk $(SDKROOT) -find libtool)
124endif
125ifeq ($(NM),)
126 export NM := $(shell $(XCRUN) -sdk $(SDKROOT) -find nm)
127endif
128ifeq ($(UNIFDEF),)
129 export UNIFDEF := $(shell $(XCRUN) -sdk $(SDKROOT) -find unifdef)
130endif
131ifeq ($(DSYMUTIL),)
132 export DSYMUTIL := $(shell $(XCRUN) -sdk $(SDKROOT) -find dsymutil)
133endif
134ifeq ($(CTFCONVERT),)
135 export CTFCONVERT := $(shell $(XCRUN) -sdk $(SDKROOT) -find ctfconvert)
136endif
137ifeq ($(CTFMERGE),)
138 export CTFMERGE := $(shell $(XCRUN) -sdk $(SDKROOT) -find ctfmerge)
139endif
140ifeq ($(CTFINSERT),)
141 export CTFINSERT := $(shell $(XCRUN) -sdk $(SDKROOT) -find ctf_insert)
142endif
143ifeq ($(NMEDIT),)
144 export NMEDIT := $(shell $(XCRUN) -sdk $(SDKROOT) -find nmedit)
145endif
146
147#
148# Platform options
149#
150SUPPORTED_EMBEDDED_PLATFORMS := iPhoneOS iPhoneOSNano tvOS AppleTVOS WatchOS BridgeOS
151SUPPORTED_SIMULATOR_PLATFORMS := iPhoneSimulator iPhoneNanoSimulator tvSimulator AppleTVSimulator WatchSimulator
152SUPPORTED_PLATFORMS := MacOSX DriverKit $(SUPPORTED_SIMULATOR_PLATFORMS) $(SUPPORTED_EMBEDDED_PLATFORMS)
153
154# Platform-specific tools
155ifneq ($(filter $(SUPPORTED_EMBEDDED_PLATFORMS),$(PLATFORM)),)
156ifeq ($(EMBEDDED_DEVICE_MAP),)
157 export EMBEDDED_DEVICE_MAP := $(shell $(XCRUN) -sdk $(SDKROOT) -find embedded_device_map)
158endif
159EDM_DBPATH ?= $(PLATFORMPATH)/usr/local/standalone/firmware/device_map.db
160endif
161
162# Scripts or tools we build ourselves
163#
164# setsegname - Rename segments in a Mach-O object file
165# kextsymboltool - Create kext pseudo-kext Mach-O kexts binaries
166# decomment - Strip out comments to detect whether a file is comments-only
167# installfile - Atomically copy files, esp. when multiple architectures
168# are trying to install the same target header
169# replacecontents - Write contents to a file and update modtime *only* if
170# contents differ
171#
172SEG_HACK = $(OBJROOT)/SETUP/setsegname/setsegname
173KEXT_CREATE_SYMBOL_SET = $(OBJROOT)/SETUP/kextsymboltool/kextsymboltool
174DECOMMENT = $(OBJROOT)/SETUP/decomment/decomment
175NEWVERS = $(SRCROOT)/config/newvers.pl
176INSTALL = $(OBJROOT)/SETUP/installfile/installfile
177REPLACECONTENTS = $(OBJROOT)/SETUP/replacecontents/replacecontents
178JSONCOMPILATIONDB = $(OBJROOT)/SETUP/json_compilation_db/json_compilation_db
179
180# Standard BSD tools
181RM = /bin/rm -f
182RMDIR = /bin/rmdir
183CP = /bin/cp
184MV = /bin/mv
185LN = /bin/ln -fs
186CAT = /bin/cat
187MKDIR = /bin/mkdir -p
188CHMOD = /bin/chmod
189FIND = /usr/bin/find
190XARGS = /usr/bin/xargs
191PAX = /bin/pax
192BASENAME = /usr/bin/basename
193DIRNAME = /usr/bin/dirname
194TR = /usr/bin/tr
195TOUCH = /usr/bin/touch
196SLEEP = /bin/sleep
197AWK = /usr/bin/awk
198SED = /usr/bin/sed
199PLUTIL = /usr/bin/plutil
200
201#
202# Command to generate host binaries. Intentionally not
203# $(CC), which controls the target compiler
204#
205ifeq ($(HOST_OS_VERSION),)
206 export HOST_OS_VERSION := $(shell sw_vers -productVersion)
207endif
208ifeq ($(HOST_CC),)
209 export HOST_CC := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find clang)
210endif
211ifeq ($(HOST_FLEX),)
212 export HOST_FLEX := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find flex)
213endif
214ifeq ($(HOST_BISON),)
215 export HOST_BISON := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find bison)
216endif
217ifeq ($(HOST_GM4),)
218 export HOST_GM4 := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find gm4)
219endif
220ifeq ($(HOST_CODESIGN),)
221 export HOST_CODESIGN := /usr/bin/codesign
222endif
223ifeq ($(HOST_CODESIGN_ALLOCATE),)
224 export HOST_CODESIGN_ALLOCATE := $(shell $(XCRUN) -sdk $(HOST_SDKROOT) -find codesign_allocate)
225endif
226
227#
228# The following variables are functions invoked with "call", and thus
229# behave similarly to externally compiled commands
230#
231
232# $(1) is an expanded kernel config from a TARGET_CONFIGS_UC tuple
233# $(2) is an expanded arch config from a TARGET_CONFIGS_UC tuple
234# $(3) is an expanded machine config from a TARGET_CONFIGS_UC tuple
235_function_create_build_configs_join = $(strip $(1))^$(strip $(2))^$(strip $(3))
236
237# $(1) is an un-expanded kernel config from a TARGET_CONFIGS_UC tuple
238# $(2) is an un-expanded arch config from a TARGET_CONFIGS_UC tuple
239# $(3) is an un-expanded machine config from a TARGET_CONFIGS_UC tuple
240_function_create_build_configs_do_expand = $(call _function_create_build_configs_join, \
241 $(if $(filter DEFAULT,$(1)), \
242 $(DEFAULT_KERNEL_CONFIG), \
243 $(1) \
244 ), \
245 $(if $(filter DEFAULT,$(2)), \
246 $(DEFAULT_ARCH_CONFIG), \
247 $(2) \
248 ), \
249 $(if $(filter DEFAULT,$(3)), \
250 $(if $(filter DEFAULT,$(2)), \
251 $(DEFAULT_$(DEFAULT_ARCH_CONFIG)_MACHINE_CONFIG), \
252 $(DEFAULT_$(strip $(2))_MACHINE_CONFIG) \
253 ), \
254 $(3) \
255 ) \
256 )
257
258# $(1) is an un-expanded TARGET_CONFIGS_UC list, which must be consumed
259# 3 elements at a time
260function_create_build_configs = $(sort \
261 $(strip \
262 $(call _function_create_build_configs_do_expand, \
263 $(word 1,$(1)), \
264 $(word 2,$(1)), \
265 $(word 3,$(1)), \
266 ) \
267 $(if $(word 4,$(1)), \
268 $(call function_create_build_configs, \
269 $(wordlist 4,$(words $(1)),$(1)) \
270 ), \
271 ) \
272 ) \
273 )
274
275# Similar to build configs, but alias configs are a 4-tuple
276
277# $(1) is an expanded kernel config from a TARGET_CONFIGS_ALIASES_UC tuple
278# $(2) is an expanded arch config from a TARGET_CONFIGS_ALIASES_UC tuple
279# $(3) is an expanded kernel machine config from a TARGET_CONFIGS_ALIASES_UC tuple
280# $(4) is an expanded SoC platform config from a TARGET_CONFIGS_ALIASES_UC tuple,
281# which should be an alias of $(3)
282_function_create_alias_configs_join = $(strip $(1))^$(strip $(2))^$(strip $(3))^$(strip $(4))
283
284_function_create_alias_configs_do_expand = $(call _function_create_alias_configs_join, \
285 $(if $(filter DEFAULT,$(1)), \
286 $(DEFAULT_KERNEL_CONFIG), \
287 $(1) \
288 ), \
289 $(if $(filter DEFAULT,$(2)), \
290 $(DEFAULT_ARCH_CONFIG), \
291 $(2) \
292 ), \
293 $(3), \
294 $(4) \
295 )
296
297function_create_alias_configs = $(sort \
298 $(strip \
299 $(call _function_create_alias_configs_do_expand, \
300 $(word 1,$(1)), \
301 $(word 2,$(1)), \
302 $(word 3,$(1)), \
303 $(word 4,$(1)), \
304 ) \
305 $(if $(word 5,$(1)), \
306 $(call function_create_alias_configs, \
307 $(wordlist 5,$(words $(1)),$(1)) \
308 ), \
309 ) \
310 ) \
311 )
312
313# $(1) is a fully-expanded kernel config
314# $(2) is a fully-expanded arch config
315# $(3) is a fully-expanded machine config. "NONE" is not represented in the objdir path
316function_convert_target_config_uc_to_objdir = $(if $(filter NONE,$(3)),$(strip $(1))_$(strip $(2)),$(strip $(1))_$(strip $(2))_$(strip $(3)))
317
318# $(1) is a fully-expanded build config (like "RELEASE^X86_64^NONE")
319function_convert_build_config_to_objdir = $(call function_convert_target_config_uc_to_objdir, \
320 $(word 1,$(subst ^, ,$(1))), \
321 $(word 2,$(subst ^, ,$(1))), \
322 $(word 3,$(subst ^, ,$(1))) \
323 )
324
325# $(1) is a fully-expanded build config (like "RELEASE^X86_64^NONE")
326function_extract_kernel_config_from_build_config = $(word 1,$(subst ^, ,$(1)))
327function_extract_arch_config_from_build_config = $(word 2,$(subst ^, ,$(1)))
328function_extract_machine_config_from_build_config = $(word 3,$(subst ^, ,$(1)))
329
330# $(1) is an input word
331# $(2) is a list of colon-separate potential substitutions like "FOO:BAR BAZ:QUX"
332# $(3) is a fallback if no substitutions were made
333function_substitute_word_with_replacement = $(strip $(if $(2), \
334 $(if $(filter $(word 1,$(subst :, ,$(word 1,$(2)))),$(1)), \
335 $(word 2,$(subst :, ,$(word 1,$(2)))), \
336 $(call function_substitute_word_with_replacement,$(1),$(wordlist 2,$(words $(2)),$(2)),$(3))), \
337 $(3) \
338 ) \
339 )
340
341# You can't assign a variable to an empty space without these
342# shenanigans
343empty :=
344space := $(empty) $(empty)
345
346# Arithmetic
347# $(1) is the number to increment
348NUM32 = 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
349increment = $(words x $(wordlist 1,$(1),$(NUM32)))
350decrement = $(words $(wordlist 2,$(1),$(NUM32)))
351
352# Create a sequence from 1 to $(1)
353# F(N) = if N > 0: return F(N-1) + "N" else: return ""
354sequence = $(if $(wordlist 1,$(1),$(NUM32)),$(call sequence,$(call decrement,$(1))) $(1),)
355
356# Reverse a list of words in $(1)
357reverse = $(if $(word 2,$(1)),$(call reverse,$(wordlist 2,$(words $(1)),$(1)))) $(word 1,$(1))
358
359# vim: set ft=make: