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