2 # Copyright (C) 1999-2020 Apple Inc. All rights reserved.
5 export VERSDIR := $(shell /bin/pwd)
9 export SRCROOT := $(shell /bin/pwd)
12 export OBJROOT = $(SRCROOT)/BUILD/obj
15 export DSTROOT = $(SRCROOT)/BUILD/dst
18 export SYMROOT = $(SRCROOT)/BUILD/sym
21 export MallocNanoZone := 1
24 # Avoid make default rules, make becomes faster
27 export MakeInc_top=${VERSDIR}/makedefs/MakeInc.top
28 export MakeInc_kernel=${VERSDIR}/makedefs/MakeInc.kernel
29 export MakeInc_cmd=${VERSDIR}/makedefs/MakeInc.cmd
30 export MakeInc_def=${VERSDIR}/makedefs/MakeInc.def
31 export MakeInc_rule=${VERSDIR}/makedefs/MakeInc.rule
32 export MakeInc_dir=${VERSDIR}/makedefs/MakeInc.dir
36 # Dispatch non-xnu build aliases to their own build
37 # systems. All xnu variants start with MakeInc_top.
40 ifneq ($(findstring Libsyscall,$(RC_ProjectName)),)
42 include $(MakeInc_cmd)
44 ifeq ($(RC_ProjectName),Libsyscall_headers_Sim)
45 TARGET=-target Libsyscall_headers_Sim
48 ifeq ($(RC_ProjectName),Libsyscall_driverkit)
49 TARGET=-target Libsyscall_driverkit
55 SDKROOT ?= macosx.internal
59 xcodebuild $@ $(TARGET) \
61 "SRCROOT=$(SRCROOT)/libsyscall" \
62 "OBJROOT=$(OBJROOT)" \
63 "SYMROOT=$(SYMROOT)" \
64 "DSTROOT=$(DSTROOT)" \
67 Libsyscall_driverkit: install
69 .PHONY: Libsyscall_driverkit
76 else ifneq ($(findstring libkxld_host,$(RC_ProjectName)),)
78 include $(MakeInc_cmd)
82 installhdrs install clean:
83 $(MAKE) -C libkern/kxld $@ USE_APPLE_PB_SUPPORT=all PRODUCT_TYPE=ARCHIVE
86 $(_v)$(MKDIR) $(SRCROOT)
87 $(_v)$(FIND) -x . \! \( \( -name BUILD -o -name .svn -o -name .git -o -name cscope.\* -o -name \*~ \) -prune \) -print0 | $(PAX) -rw -p a -d0 $(SRCROOT)
88 $(_v)$(CHMOD) -R go+rX $(SRCROOT)
90 else ifneq ($(findstring libkxld,$(RC_ProjectName)),)
92 include $(MakeInc_cmd)
96 installhdrs install clean:
97 $(MAKE) -C libkern/kxld $@ USE_APPLE_PB_SUPPORT=all
100 $(_v)$(MKDIR) $(SRCROOT)
101 $(_v)$(FIND) -x . \! \( \( -name BUILD -o -name .svn -o -name .git -o -name cscope.\* -o -name \*~ \) -prune \) -print0 | $(PAX) -rw -p a -d0 $(SRCROOT)
102 $(_v)$(CHMOD) -R go+rX $(SRCROOT)
104 else ifneq ($(findstring libkmod,$(RC_ProjectName)),)
112 "SRCROOT=$(SRCROOT)/libkern/kmod" \
113 "OBJROOT=$(OBJROOT)" \
114 "SYMROOT=$(SYMROOT)" \
115 "DSTROOT=$(DSTROOT)" \
123 else ifneq ($(findstring xnu_tests,$(RC_ProjectName)),)
125 export SYSCTL_HW_PHYSICALCPU := $(shell /usr/sbin/sysctl -n hw.physicalcpu)
126 export SYSCTL_HW_LOGICALCPU := $(shell /usr/sbin/sysctl -n hw.logicalcpu)
127 MAKEJOBS := --jobs=$(shell expr $(SYSCTL_HW_LOGICALCPU) + 1)
140 else ifeq ($(RC_ProjectName),xnu_tests_driverkit)
142 export SYSCTL_HW_PHYSICALCPU := $(shell /usr/sbin/sysctl -n hw.physicalcpu)
143 export SYSCTL_HW_LOGICALCPU := $(shell /usr/sbin/sysctl -n hw.logicalcpu)
144 MAKEJOBS := --jobs=$(shell expr $(SYSCTL_HW_LOGICALCPU) + 1)
150 install: xnu_tests_driverkit
157 else # all other RC_ProjectName
159 ifndef CURRENT_BUILD_CONFIG
161 # avoid having to include MakeInc.cmd
164 else ifeq ($(VERBOSE),YES)
171 # Setup for parallel sub-makes, taking into account physical and logical
172 # CPUs. If the system does not support SMT, use N+1.
173 # If MAKEJOBS or -jN is passed on the make line, that takes precedence.
175 export SYSCTL_HW_PHYSICALCPU := $(shell /usr/sbin/sysctl -n hw.physicalcpu)
176 export SYSCTL_HW_LOGICALCPU := $(shell /usr/sbin/sysctl -n hw.logicalcpu)
177 MAKEJOBS := --jobs=$(shell expr $(SYSCTL_HW_LOGICALCPU) + 1)
183 all all_desktop all_embedded \
184 all_release_embedded all_development_embedded \
185 installhdrs installhdrs_desktop installhdrs_embedded \
186 installhdrs_release_embedded installhdrs_development_embedded \
187 install install_desktop install_embedded \
188 install_release_embedded install_development_embedded \
195 # Targets for internal build system debugging
197 print_exports print_exports_first_build_config \
204 ifeq ($(BUILD_JSON_COMPILATION_DATABASE),1)
206 DEFAULT_TARGET := build
209 .PHONY: $(TOP_TARGETS)
211 default: $(DEFAULT_TARGET)
213 ifneq ($(REMOTEBUILD),)
215 $(_v)$(VERSDIR)/tools/remote_build.sh _REMOTEBUILD_TARGET=$@ _REMOTEBUILD_MAKE=$(MAKE) $(if $(filter --,$(MAKEFLAGS)),-,)$(MAKEFLAGS)
218 $(_v)$(MAKE) $(MAKEARGS) -r $(if $(filter -j,$(MAKEFLAGS)),,$(MAKEJOBS)) -f $(MakeInc_top) $@
221 else # CURRENT_BUILD_CONFIG
223 include $(MakeInc_cmd)
224 include $(MakeInc_def)
237 CONFIG_SUBDIRS = config tools san
239 INSTINC_SUBDIRS = $(ALL_SUBDIRS) EXTERNAL_HEADERS
240 INSTINC_SUBDIRS_X86_64 = $(INSTINC_SUBDIRS)
241 INSTINC_SUBDIRS_X86_64H = $(INSTINC_SUBDIRS)
242 INSTINC_SUBDIRS_ARM = $(INSTINC_SUBDIRS)
243 INSTINC_SUBDIRS_ARM64 = $(INSTINC_SUBDIRS)
245 EXPINC_SUBDIRS = $(ALL_SUBDIRS)
246 EXPINC_SUBDIRS_X86_64 = $(EXPINC_SUBDIRS)
247 EXPINC_SUBDIRS_X86_64H = $(EXPINC_SUBDIRS)
248 EXPINC_SUBDIRS_ARM = $(EXPINC_SUBDIRS)
249 EXPINC_SUBDIRS_ARM64 = $(EXPINC_SUBDIRS)
251 SETUP_SUBDIRS = SETUP san bsd
253 COMP_SUBDIRS_X86_64 = $(ALL_SUBDIRS)
254 COMP_SUBDIRS_X86_64H = $(ALL_SUBDIRS)
255 COMP_SUBDIRS_ARM = $(ALL_SUBDIRS)
256 COMP_SUBDIRS_ARM64 = $(ALL_SUBDIRS)
258 INSTTEXTFILES_SUBDIRS = \
260 INSTTEXTFILES_SUBDIRS_X86_64 = $(INSTTEXTFILES_SUBDIRS)
261 INSTTEXTFILES_SUBDIRS_X86_64H = $(INSTTEXTFILES_SUBDIRS)
262 INSTTEXTFILES_SUBDIRS_ARM = $(INSTTEXTFILES_SUBDIRS)
263 INSTTEXTFILES_SUBDIRS_ARM64 = $(INSTTEXTFILES_SUBDIRS)
265 include $(MakeInc_kernel)
266 include $(MakeInc_rule)
267 include $(MakeInc_dir)
269 endif # CURRENT_BUILD_CONFIG
271 endif # all other RC_ProjectName
273 installapi_libkdd installhdrs_libkdd install_libkdd:
275 xcodebuild -target Default $(subst _libkdd,,$@) \
277 "SRCROOT=$(SRCROOT)/libkdd" \
278 "OBJROOT=$(OBJROOT)" \
279 "SYMROOT=$(SYMROOT)" \
280 "DSTROOT=$(DSTROOT)" \
284 installapi_libkdd_tests installhdrs_libkdd_tests install_libkdd_tests:
286 xcodebuild -target tests $(subst _libkdd_tests,,$@) \
288 "SRCROOT=$(SRCROOT)/libkdd" \
289 "OBJROOT=$(OBJROOT)" \
290 "SYMROOT=$(SYMROOT)" \
291 "DSTROOT=$(DSTROOT)" \
295 installapi_libkdd_host installhdrs_libkdd_host install_libkdd_host:
297 xcodebuild -configuration ReleaseHost -target kdd.framework $(subst _libkdd_host,,$@) \
299 "SRCROOT=$(SRCROOT)/libkdd" \
300 "OBJROOT=$(OBJROOT)" \
301 "SYMROOT=$(SYMROOT)" \
302 "DSTROOT=$(DSTROOT)" \
306 # "xnu_tests" and "testbots" are targets that can be invoked via a standalone
307 # "make xnu_tests" or via buildit/XBS with the RC_ProjectName=xnu_tests.
308 # Define the target here in the outermost scope of the initial Makefile
311 $(MAKE) -C $(SRCROOT)/tools/tests $(if $(filter -j,$(MAKEFLAGS)),,$(MAKEJOBS)) \
312 SRCROOT=$(SRCROOT)/tools/tests
313 $(MAKE) -C $(SRCROOT)/tests $(if $(filter -j,$(MAKEFLAGS)),,$(MAKEJOBS)) \
314 SRCROOT=$(SRCROOT)/tests
317 $(MAKE) -C $(SRCROOT)/tests/driverkit $(if $(filter -j,$(MAKEFLAGS)),,$(MAKEJOBS)) \
318 SRCROOT=$(SRCROOT)/tests/driverkit
321 include $(MakeInc_cmd)
324 # The "analyze" target defined below invokes Clang Static Analyzer
325 # with a predefined set of checks and options for the project.
328 # By default, analysis results are available in BUILD/StaticAnalyzer.
329 # Set this variable in your make invocation to use a different directory.
330 # Note that these results are only deleted when the build directory
331 # is cleaned. They aren't deleted every time the analyzer is re-run,
332 # but they are deleted after "make clean".
333 STATIC_ANALYZER_OUTPUT_DIR ?= $(SRCROOT)/BUILD/StaticAnalyzer
335 # By default, the default make target is analyzed. You can analyze
336 # other targets by setting this variable in your make invocation.
337 STATIC_ANALYZER_TARGET ?=
339 # You can pass additional flags to scan-build by setting this variable
340 # in your make invocation. For example, you can enable additional checks.
341 STATIC_ANALYZER_EXTRA_FLAGS ?=
344 # This is where the reports are going to be available.
345 # Old reports are deleted on make clean only.
346 $(_v)$(MKDIR) $(STATIC_ANALYZER_OUTPUT_DIR)
348 # Recursively build the requested target under scan-build.
349 # Exclude checks that weren't deemed to be security critical,
350 # like null pointer dereferences.
351 $(_v)$(XCRUN) $(SCAN_BUILD) -o $(STATIC_ANALYZER_OUTPUT_DIR) \
352 -disable-checker deadcode.DeadStores \
353 -disable-checker core.NullDereference \
354 -disable-checker core.DivideZero \
355 $(STATIC_ANALYZER_EXTRA_FLAGS) \
356 $(MAKE) $(STATIC_ANALYZER_TARGET) QUIET=1 2>&1 | $(GREP) "^scan-build:"