]> git.saurik.com Git - apple/xnu.git/blame - Makefile
xnu-7195.60.75.tar.gz
[apple/xnu.git] / Makefile
CommitLineData
39236c6e 1#
2a1bd2d3 2# Copyright (C) 1999-2020 Apple Inc. All rights reserved.
39236c6e 3#
1c79356b 4ifndef VERSDIR
39236c6e 5export VERSDIR := $(shell /bin/pwd)
1c79356b 6endif
39236c6e 7
9bccf70c 8ifndef SRCROOT
39236c6e 9export SRCROOT := $(shell /bin/pwd)
9bccf70c
A
10endif
11ifndef OBJROOT
39236c6e 12export OBJROOT = $(SRCROOT)/BUILD/obj
9bccf70c
A
13endif
14ifndef DSTROOT
39236c6e 15export DSTROOT = $(SRCROOT)/BUILD/dst
9bccf70c
A
16endif
17ifndef SYMROOT
39236c6e 18export SYMROOT = $(SRCROOT)/BUILD/sym
9bccf70c 19endif
cb323159
A
20ifndef MallocNanoZone
21export MallocNanoZone := 1
22endif
23
24# Avoid make default rules, make becomes faster
25MAKEFLAGS+=r
1c79356b 26
39236c6e
A
27export MakeInc_top=${VERSDIR}/makedefs/MakeInc.top
28export MakeInc_kernel=${VERSDIR}/makedefs/MakeInc.kernel
1c79356b
A
29export MakeInc_cmd=${VERSDIR}/makedefs/MakeInc.cmd
30export MakeInc_def=${VERSDIR}/makedefs/MakeInc.def
31export MakeInc_rule=${VERSDIR}/makedefs/MakeInc.rule
32export MakeInc_dir=${VERSDIR}/makedefs/MakeInc.dir
33
39236c6e
A
34#
35# Dispatch non-xnu build aliases to their own build
36# systems. All xnu variants start with MakeInc_top.
37#
38
f427ee49 39ifneq ($(findstring Libsyscall,$(RC_ProjectName)),)
39236c6e 40
cb323159
A
41include $(MakeInc_cmd)
42
f427ee49
A
43ifeq ($(RC_ProjectName),Libsyscall_headers_Sim)
44TARGET=-target Libsyscall_headers_Sim
45endif
46
47ifeq ($(RC_ProjectName),Libsyscall_driverkit)
48TARGET=-target Libsyscall_driverkit
39236c6e
A
49endif
50
51default: install
52
39037602
A
53# default to OS X
54SDKROOT ?= macosx.internal
55
39236c6e
A
56installhdrs install:
57 cd libsyscall ; \
58 xcodebuild $@ $(TARGET) \
cb323159 59 $(MAKEOVERRIDES) \
39236c6e 60 "SRCROOT=$(SRCROOT)/libsyscall" \
39037602
A
61 "OBJROOT=$(OBJROOT)" \
62 "SYMROOT=$(SYMROOT)" \
39236c6e
A
63 "DSTROOT=$(DSTROOT)" \
64 "SDKROOT=$(SDKROOT)"
65
cb323159
A
66Libsyscall_driverkit: install
67
68.PHONY: Libsyscall_driverkit
69
39236c6e
A
70clean:
71
72installsrc:
73 pax -rw . $(SRCROOT)
74
f427ee49 75else ifneq ($(findstring libkxld_host,$(RC_ProjectName)),)
39236c6e 76
fe8ab488
A
77include $(MakeInc_cmd)
78
39236c6e
A
79default: install
80
81installhdrs install clean:
f427ee49 82 $(MAKE) -C libkern/kxld $@ USE_APPLE_PB_SUPPORT=all PRODUCT_TYPE=ARCHIVE
39236c6e
A
83
84installsrc:
fe8ab488
A
85 $(_v)$(MKDIR) $(SRCROOT)
86 $(_v)$(FIND) -x . \! \( \( -name BUILD -o -name .svn -o -name .git -o -name cscope.\* -o -name \*~ \) -prune \) -print0 | $(PAX) -rw -p a -d0 $(SRCROOT)
87 $(_v)$(CHMOD) -R go+rX $(SRCROOT)
39236c6e 88
f427ee49 89else ifneq ($(findstring libkxld,$(RC_ProjectName)),)
39236c6e 90
fe8ab488
A
91include $(MakeInc_cmd)
92
39236c6e
A
93default: install
94
95installhdrs install clean:
f427ee49 96 $(MAKE) -C libkern/kxld $@ USE_APPLE_PB_SUPPORT=all
39236c6e
A
97
98installsrc:
fe8ab488
A
99 $(_v)$(MKDIR) $(SRCROOT)
100 $(_v)$(FIND) -x . \! \( \( -name BUILD -o -name .svn -o -name .git -o -name cscope.\* -o -name \*~ \) -prune \) -print0 | $(PAX) -rw -p a -d0 $(SRCROOT)
101 $(_v)$(CHMOD) -R go+rX $(SRCROOT)
39236c6e 102
f427ee49 103else ifneq ($(findstring libkmod,$(RC_ProjectName)),)
39236c6e
A
104
105default: install
106
107installhdrs install:
108 cd libkern/kmod ; \
39037602 109 xcodebuild $@ \
cb323159 110 $(MAKEOVERRIDES) \
39236c6e 111 "SRCROOT=$(SRCROOT)/libkern/kmod" \
39037602
A
112 "OBJROOT=$(OBJROOT)" \
113 "SYMROOT=$(SYMROOT)" \
39236c6e
A
114 "DSTROOT=$(DSTROOT)" \
115 "SDKROOT=$(SDKROOT)"
116
117clean:
118
4bd07ac2
A
119installsrc:
120 pax -rw . $(SRCROOT)
121
f427ee49 122else ifneq ($(findstring xnu_tests,$(RC_ProjectName)),)
39236c6e 123
39037602
A
124export SYSCTL_HW_PHYSICALCPU := $(shell /usr/sbin/sysctl -n hw.physicalcpu)
125export SYSCTL_HW_LOGICALCPU := $(shell /usr/sbin/sysctl -n hw.logicalcpu)
cb323159 126MAKEJOBS := --jobs=$(shell expr $(SYSCTL_HW_LOGICALCPU) + 1)
39037602 127
39236c6e
A
128default: install
129
130installhdrs:
131
4bd07ac2 132install: xnu_tests
39236c6e
A
133
134clean:
135
f427ee49
A
136installsrc:
137 pax -rw . $(SRCROOT)
138
139else ifeq ($(RC_ProjectName),xnu_tests_driverkit)
140
141export SYSCTL_HW_PHYSICALCPU := $(shell /usr/sbin/sysctl -n hw.physicalcpu)
142export SYSCTL_HW_LOGICALCPU := $(shell /usr/sbin/sysctl -n hw.logicalcpu)
143MAKEJOBS := --jobs=$(shell expr $(SYSCTL_HW_LOGICALCPU) + 1)
144
145default: install
146
147installhdrs:
148
149install: xnu_tests_driverkit
150
151clean:
152
39236c6e
A
153installsrc:
154 pax -rw . $(SRCROOT)
155
156else # all other RC_ProjectName
157
158ifndef CURRENT_BUILD_CONFIG
159
160# avoid having to include MakeInc.cmd
161ifeq ($(RC_XBS),YES)
162_v =
163else ifeq ($(VERBOSE),YES)
164_v =
165else
166_v = @
167endif
168
169#
fe8ab488
A
170# Setup for parallel sub-makes, taking into account physical and logical
171# CPUs. If the system does not support SMT, use N+1.
39236c6e
A
172# If MAKEJOBS or -jN is passed on the make line, that takes precedence.
173#
fe8ab488
A
174export SYSCTL_HW_PHYSICALCPU := $(shell /usr/sbin/sysctl -n hw.physicalcpu)
175export SYSCTL_HW_LOGICALCPU := $(shell /usr/sbin/sysctl -n hw.logicalcpu)
cb323159 176MAKEJOBS := --jobs=$(shell expr $(SYSCTL_HW_LOGICALCPU) + 1)
39236c6e 177
f427ee49
A
178TOP_TARGETS = \
179 clean \
180 installsrc \
181 exporthdrs \
182 all all_desktop all_embedded \
183 all_release_embedded all_development_embedded \
184 installhdrs installhdrs_desktop installhdrs_embedded \
185 installhdrs_release_embedded installhdrs_development_embedded \
186 install install_desktop install_embedded \
187 install_release_embedded install_development_embedded \
188 install_kernels \
f427ee49 189 cscope tags TAGS checkstyle restyle check_uncrustify uncrustify \
fe8ab488
A
190 help
191
3e170ce0
A
192DEFAULT_TARGET = all
193
fe8ab488 194# Targets for internal build system debugging
f427ee49
A
195TOP_TARGETS += \
196 print_exports print_exports_first_build_config \
197 setup \
198 build \
199 config \
200 install_textfiles \
fe8ab488 201 install_config
39236c6e 202
3e170ce0
A
203ifeq ($(BUILD_JSON_COMPILATION_DATABASE),1)
204MAKEARGS += -B
205DEFAULT_TARGET := build
206endif
207
39236c6e
A
208.PHONY: $(TOP_TARGETS)
209
3e170ce0 210default: $(DEFAULT_TARGET)
39236c6e
A
211
212ifneq ($(REMOTEBUILD),)
213$(TOP_TARGETS):
fe8ab488 214 $(_v)$(VERSDIR)/tools/remote_build.sh _REMOTEBUILD_TARGET=$@ _REMOTEBUILD_MAKE=$(MAKE) $(if $(filter --,$(MAKEFLAGS)),-,)$(MAKEFLAGS)
39236c6e
A
215else
216$(TOP_TARGETS):
3e170ce0 217 $(_v)$(MAKE) $(MAKEARGS) -r $(if $(filter -j,$(MAKEFLAGS)),,$(MAKEJOBS)) -f $(MakeInc_top) $@
39236c6e
A
218endif
219
220else # CURRENT_BUILD_CONFIG
1c79356b
A
221
222include $(MakeInc_cmd)
223include $(MakeInc_def)
224
225ALL_SUBDIRS = \
5ba3f43e 226 security \
39236c6e 227 bsd \
1c79356b
A
228 iokit \
229 osfmk \
1c79356b
A
230 pexpert \
231 libkern \
2d21ac55 232 libsa \
5ba3f43e
A
233 config \
234 san
1c79356b 235
5ba3f43e 236CONFIG_SUBDIRS = config tools san
55e303ae 237
91447636 238INSTINC_SUBDIRS = $(ALL_SUBDIRS) EXTERNAL_HEADERS
6d2010ae 239INSTINC_SUBDIRS_X86_64 = $(INSTINC_SUBDIRS)
fe8ab488 240INSTINC_SUBDIRS_X86_64H = $(INSTINC_SUBDIRS)
6d2010ae 241INSTINC_SUBDIRS_ARM = $(INSTINC_SUBDIRS)
3e170ce0 242INSTINC_SUBDIRS_ARM64 = $(INSTINC_SUBDIRS)
2d21ac55 243
1c79356b 244EXPINC_SUBDIRS = $(ALL_SUBDIRS)
b0d623f7 245EXPINC_SUBDIRS_X86_64 = $(EXPINC_SUBDIRS)
fe8ab488 246EXPINC_SUBDIRS_X86_64H = $(EXPINC_SUBDIRS)
2d21ac55 247EXPINC_SUBDIRS_ARM = $(EXPINC_SUBDIRS)
3e170ce0 248EXPINC_SUBDIRS_ARM64 = $(EXPINC_SUBDIRS)
2d21ac55 249
cb323159 250SETUP_SUBDIRS = SETUP san bsd
b0d623f7 251
b0d623f7 252COMP_SUBDIRS_X86_64 = $(ALL_SUBDIRS)
fe8ab488 253COMP_SUBDIRS_X86_64H = $(ALL_SUBDIRS)
b0d623f7 254COMP_SUBDIRS_ARM = $(ALL_SUBDIRS)
3e170ce0 255COMP_SUBDIRS_ARM64 = $(ALL_SUBDIRS)
55e303ae 256
fe8ab488 257INSTTEXTFILES_SUBDIRS = \
9bccf70c 258 bsd
f427ee49
A
259INSTTEXTFILES_SUBDIRS_X86_64 = $(INSTTEXTFILES_SUBDIRS)
260INSTTEXTFILES_SUBDIRS_X86_64H = $(INSTTEXTFILES_SUBDIRS)
261INSTTEXTFILES_SUBDIRS_ARM = $(INSTTEXTFILES_SUBDIRS)
262INSTTEXTFILES_SUBDIRS_ARM64 = $(INSTTEXTFILES_SUBDIRS)
9bccf70c 263
39236c6e 264include $(MakeInc_kernel)
1c79356b
A
265include $(MakeInc_rule)
266include $(MakeInc_dir)
6d2010ae 267
39236c6e
A
268endif # CURRENT_BUILD_CONFIG
269
270endif # all other RC_ProjectName
271
a39ff7e2 272installapi_libkdd installhdrs_libkdd install_libkdd:
3e170ce0 273 cd libkdd; \
d9a64523 274 xcodebuild -target Default $(subst _libkdd,,$@) \
cb323159 275 $(MAKEOVERRIDES) \
d9a64523
A
276 "SRCROOT=$(SRCROOT)/libkdd" \
277 "OBJROOT=$(OBJROOT)" \
278 "SYMROOT=$(SYMROOT)" \
279 "DSTROOT=$(DSTROOT)" \
280 "SDKROOT=$(SDKROOT)"
281
282
283installapi_libkdd_tests installhdrs_libkdd_tests install_libkdd_tests:
284 cd libkdd; \
285 xcodebuild -target tests $(subst _libkdd_tests,,$@) \
cb323159 286 $(MAKEOVERRIDES) \
3e170ce0 287 "SRCROOT=$(SRCROOT)/libkdd" \
39037602
A
288 "OBJROOT=$(OBJROOT)" \
289 "SYMROOT=$(SYMROOT)" \
3e170ce0
A
290 "DSTROOT=$(DSTROOT)" \
291 "SDKROOT=$(SDKROOT)"
292
293
a39ff7e2
A
294installapi_libkdd_host installhdrs_libkdd_host install_libkdd_host:
295 cd libkdd; \
d9a64523 296 xcodebuild -configuration ReleaseHost -target kdd.framework $(subst _libkdd_host,,$@) \
cb323159 297 $(MAKEOVERRIDES) \
a39ff7e2
A
298 "SRCROOT=$(SRCROOT)/libkdd" \
299 "OBJROOT=$(OBJROOT)" \
300 "SYMROOT=$(SYMROOT)" \
301 "DSTROOT=$(DSTROOT)" \
302 "SDKROOT=$(SDKROOT)"
303
304
4bd07ac2
A
305# "xnu_tests" and "testbots" are targets that can be invoked via a standalone
306# "make xnu_tests" or via buildit/XBS with the RC_ProjectName=xnu_tests.
39236c6e
A
307# Define the target here in the outermost scope of the initial Makefile
308
39037602
A
309xnu_tests:
310 $(MAKE) -C $(SRCROOT)/tools/tests $(if $(filter -j,$(MAKEFLAGS)),,$(MAKEJOBS)) \
39236c6e 311 SRCROOT=$(SRCROOT)/tools/tests
d9a64523
A
312 $(MAKE) -C $(SRCROOT)/tests $(if $(filter -j,$(MAKEFLAGS)),,$(MAKEJOBS)) \
313 SRCROOT=$(SRCROOT)/tests
f427ee49
A
314
315xnu_tests_driverkit:
316 $(MAKE) -C $(SRCROOT)/tests/driverkit $(if $(filter -j,$(MAKEFLAGS)),,$(MAKEJOBS)) \
317 SRCROOT=$(SRCROOT)/tests/driverkit
318
2a1bd2d3 319
f427ee49
A
320#
321# The "analyze" target defined below invokes Clang Static Analyzer
322# with a predefined set of checks and options for the project.
323#
324
325# By default, analysis results are available in BUILD/StaticAnalyzer.
326# Set this variable in your make invocation to use a different directory.
327# Note that these results are only deleted when the build directory
328# is cleaned. They aren't deleted every time the analyzer is re-run,
329# but they are deleted after "make clean".
330STATIC_ANALYZER_OUTPUT_DIR ?= $(SRCROOT)/BUILD/StaticAnalyzer
331
332# By default, the default make target is analyzed. You can analyze
333# other targets by setting this variable in your make invocation.
334STATIC_ANALYZER_TARGET ?=
335
336# You can pass additional flags to scan-build by setting this variable
337# in your make invocation. For example, you can enable additional checks.
338STATIC_ANALYZER_EXTRA_FLAGS ?=
339
340analyze:
341 # This is where the reports are going to be available.
342 # Old reports are deleted on make clean only.
343 mkdir -p $(STATIC_ANALYZER_OUTPUT_DIR)
344
345 # Recursively build the requested target under scan-build.
346 # Exclude checks that weren't deemed to be security critical,
347 # like null pointer dereferences.
348 xcrun scan-build -o $(STATIC_ANALYZER_OUTPUT_DIR) \
349 -disable-checker deadcode.DeadStores \
350 -disable-checker core.NullDereference \
351 -disable-checker core.DivideZero \
352 $(STATIC_ANALYZER_EXTRA_FLAGS) \
353 make $(STATIC_ANALYZER_TARGET)