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
35 # Dispatch non-xnu build aliases to their own build
36 # systems. All xnu variants start with MakeInc_top.
39 ifneq ($(findstring Libsyscall,$(RC_ProjectName)),)
41 include $(MakeInc_cmd)
43 ifeq ($(RC_ProjectName),Libsyscall_headers_Sim)
44 TARGET=-target Libsyscall_headers_Sim
47 ifeq ($(RC_ProjectName),Libsyscall_driverkit)
48 TARGET=-target Libsyscall_driverkit
54 SDKROOT ?= macosx.internal
58 xcodebuild $@ $(TARGET) \
60 "SRCROOT=$(SRCROOT)/libsyscall" \
61 "OBJROOT=$(OBJROOT)" \
62 "SYMROOT=$(SYMROOT)" \
63 "DSTROOT=$(DSTROOT)" \
66 Libsyscall_driverkit: install
68 .PHONY: Libsyscall_driverkit
75 else ifneq ($(findstring libkxld_host,$(RC_ProjectName)),)
77 include $(MakeInc_cmd)
81 installhdrs install clean:
82 $(MAKE) -C libkern/kxld $@ USE_APPLE_PB_SUPPORT=all PRODUCT_TYPE=ARCHIVE
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)
89 else ifneq ($(findstring libkxld,$(RC_ProjectName)),)
91 include $(MakeInc_cmd)
95 installhdrs install clean:
96 $(MAKE) -C libkern/kxld $@ USE_APPLE_PB_SUPPORT=all
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)
103 else ifneq ($(findstring libkmod,$(RC_ProjectName)),)
111 "SRCROOT=$(SRCROOT)/libkern/kmod" \
112 "OBJROOT=$(OBJROOT)" \
113 "SYMROOT=$(SYMROOT)" \
114 "DSTROOT=$(DSTROOT)" \
122 else ifneq ($(findstring xnu_tests,$(RC_ProjectName)),)
124 export SYSCTL_HW_PHYSICALCPU := $(shell /usr/sbin/sysctl -n hw.physicalcpu)
125 export SYSCTL_HW_LOGICALCPU := $(shell /usr/sbin/sysctl -n hw.logicalcpu)
126 MAKEJOBS := --jobs=$(shell expr $(SYSCTL_HW_LOGICALCPU) + 1)
139 else ifeq ($(RC_ProjectName),xnu_tests_driverkit)
141 export SYSCTL_HW_PHYSICALCPU := $(shell /usr/sbin/sysctl -n hw.physicalcpu)
142 export SYSCTL_HW_LOGICALCPU := $(shell /usr/sbin/sysctl -n hw.logicalcpu)
143 MAKEJOBS := --jobs=$(shell expr $(SYSCTL_HW_LOGICALCPU) + 1)
149 install: xnu_tests_driverkit
156 else # all other RC_ProjectName
158 ifndef CURRENT_BUILD_CONFIG
160 # avoid having to include MakeInc.cmd
163 else ifeq ($(VERBOSE),YES)
170 # Setup for parallel sub-makes, taking into account physical and logical
171 # CPUs. If the system does not support SMT, use N+1.
172 # If MAKEJOBS or -jN is passed on the make line, that takes precedence.
174 export SYSCTL_HW_PHYSICALCPU := $(shell /usr/sbin/sysctl -n hw.physicalcpu)
175 export SYSCTL_HW_LOGICALCPU := $(shell /usr/sbin/sysctl -n hw.logicalcpu)
176 MAKEJOBS := --jobs=$(shell expr $(SYSCTL_HW_LOGICALCPU) + 1)
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 \
189 cscope tags TAGS checkstyle restyle check_uncrustify uncrustify \
194 # Targets for internal build system debugging
196 print_exports print_exports_first_build_config \
203 ifeq ($(BUILD_JSON_COMPILATION_DATABASE),1)
205 DEFAULT_TARGET := build
208 .PHONY: $(TOP_TARGETS)
210 default: $(DEFAULT_TARGET)
212 ifneq ($(REMOTEBUILD),)
214 $(_v)$(VERSDIR)/tools/remote_build.sh _REMOTEBUILD_TARGET=$@ _REMOTEBUILD_MAKE=$(MAKE) $(if $(filter --,$(MAKEFLAGS)),-,)$(MAKEFLAGS)
217 $(_v)$(MAKE) $(MAKEARGS) -r $(if $(filter -j,$(MAKEFLAGS)),,$(MAKEJOBS)) -f $(MakeInc_top) $@
220 else # CURRENT_BUILD_CONFIG
222 include $(MakeInc_cmd)
223 include $(MakeInc_def)
236 CONFIG_SUBDIRS = config tools san
238 INSTINC_SUBDIRS = $(ALL_SUBDIRS) EXTERNAL_HEADERS
239 INSTINC_SUBDIRS_X86_64 = $(INSTINC_SUBDIRS)
240 INSTINC_SUBDIRS_X86_64H = $(INSTINC_SUBDIRS)
241 INSTINC_SUBDIRS_ARM = $(INSTINC_SUBDIRS)
242 INSTINC_SUBDIRS_ARM64 = $(INSTINC_SUBDIRS)
244 EXPINC_SUBDIRS = $(ALL_SUBDIRS)
245 EXPINC_SUBDIRS_X86_64 = $(EXPINC_SUBDIRS)
246 EXPINC_SUBDIRS_X86_64H = $(EXPINC_SUBDIRS)
247 EXPINC_SUBDIRS_ARM = $(EXPINC_SUBDIRS)
248 EXPINC_SUBDIRS_ARM64 = $(EXPINC_SUBDIRS)
250 SETUP_SUBDIRS = SETUP san bsd
252 COMP_SUBDIRS_X86_64 = $(ALL_SUBDIRS)
253 COMP_SUBDIRS_X86_64H = $(ALL_SUBDIRS)
254 COMP_SUBDIRS_ARM = $(ALL_SUBDIRS)
255 COMP_SUBDIRS_ARM64 = $(ALL_SUBDIRS)
257 INSTTEXTFILES_SUBDIRS = \
259 INSTTEXTFILES_SUBDIRS_X86_64 = $(INSTTEXTFILES_SUBDIRS)
260 INSTTEXTFILES_SUBDIRS_X86_64H = $(INSTTEXTFILES_SUBDIRS)
261 INSTTEXTFILES_SUBDIRS_ARM = $(INSTTEXTFILES_SUBDIRS)
262 INSTTEXTFILES_SUBDIRS_ARM64 = $(INSTTEXTFILES_SUBDIRS)
264 include $(MakeInc_kernel)
265 include $(MakeInc_rule)
266 include $(MakeInc_dir)
268 endif # CURRENT_BUILD_CONFIG
270 endif # all other RC_ProjectName
272 installapi_libkdd installhdrs_libkdd install_libkdd:
274 xcodebuild -target Default $(subst _libkdd,,$@) \
276 "SRCROOT=$(SRCROOT)/libkdd" \
277 "OBJROOT=$(OBJROOT)" \
278 "SYMROOT=$(SYMROOT)" \
279 "DSTROOT=$(DSTROOT)" \
283 installapi_libkdd_tests installhdrs_libkdd_tests install_libkdd_tests:
285 xcodebuild -target tests $(subst _libkdd_tests,,$@) \
287 "SRCROOT=$(SRCROOT)/libkdd" \
288 "OBJROOT=$(OBJROOT)" \
289 "SYMROOT=$(SYMROOT)" \
290 "DSTROOT=$(DSTROOT)" \
294 installapi_libkdd_host installhdrs_libkdd_host install_libkdd_host:
296 xcodebuild -configuration ReleaseHost -target kdd.framework $(subst _libkdd_host,,$@) \
298 "SRCROOT=$(SRCROOT)/libkdd" \
299 "OBJROOT=$(OBJROOT)" \
300 "SYMROOT=$(SYMROOT)" \
301 "DSTROOT=$(DSTROOT)" \
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.
307 # Define the target here in the outermost scope of the initial Makefile
310 $(MAKE) -C $(SRCROOT)/tools/tests $(if $(filter -j,$(MAKEFLAGS)),,$(MAKEJOBS)) \
311 SRCROOT=$(SRCROOT)/tools/tests
312 $(MAKE) -C $(SRCROOT)/tests $(if $(filter -j,$(MAKEFLAGS)),,$(MAKEJOBS)) \
313 SRCROOT=$(SRCROOT)/tests
316 $(MAKE) -C $(SRCROOT)/tests/driverkit $(if $(filter -j,$(MAKEFLAGS)),,$(MAKEJOBS)) \
317 SRCROOT=$(SRCROOT)/tests/driverkit
321 # The "analyze" target defined below invokes Clang Static Analyzer
322 # with a predefined set of checks and options for the project.
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".
330 STATIC_ANALYZER_OUTPUT_DIR ?= $(SRCROOT)/BUILD/StaticAnalyzer
332 # By default, the default make target is analyzed. You can analyze
333 # other targets by setting this variable in your make invocation.
334 STATIC_ANALYZER_TARGET ?=
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.
338 STATIC_ANALYZER_EXTRA_FLAGS ?=
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)
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)