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