• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1NINJA ?= prebuilts/ninja/$(HOST_PREBUILT_TAG)/ninja
2
3ifeq ($(USE_SOONG),true)
4USE_SOONG_FOR_KATI := true
5endif
6
7ifeq ($(USE_SOONG_FOR_KATI),true)
8include $(BUILD_SYSTEM)/soong.mk
9else
10KATI ?= $(HOST_OUT_EXECUTABLES)/ckati
11MAKEPARALLEL ?= $(HOST_OUT_EXECUTABLES)/makeparallel
12endif
13
14KATI_OUTPUT_PATTERNS := $(OUT_DIR)/build%.ninja $(OUT_DIR)/ninja%.sh
15
16# Modifier goals we don't need to pass to Ninja.
17NINJA_EXCLUDE_GOALS := showcommands all dist
18.PHONY : $(NINJA_EXCLUDE_GOALS)
19
20# A list of goals which affect parsing of makefiles and we need to pass to Kati.
21PARSE_TIME_MAKE_GOALS := \
22	$(PARSE_TIME_MAKE_GOALS) \
23	$(dont_bother_goals) \
24	all \
25	APP-% \
26	DUMP_% \
27	ECLIPSE-% \
28	PRODUCT-% \
29	boottarball-nodeps \
30	btnod \
31	build-art% \
32	build_kernel-nodeps \
33	clean-oat% \
34	continuous_instrumentation_tests \
35	continuous_native_tests \
36	cts \
37	custom_images \
38	deps-license \
39	dicttool_aosp \
40	dist \
41	dump-products \
42	dumpvar-% \
43	eng \
44	fusion \
45	oem_image \
46	old-cts \
47	online-system-api-sdk-docs \
48	pdk \
49	platform \
50	platform-java \
51	product-graph \
52	samplecode \
53	sdk \
54	sdk_addon \
55	sdk_repo \
56	snod \
57	stnod \
58	systemimage-nodeps \
59	systemtarball-nodeps \
60	target-files-package \
61	test-art% \
62	user \
63	userdataimage \
64	userdebug \
65	valgrind-test-art% \
66	vts \
67	win_sdk \
68	winsdk-tools
69
70-include vendor/google/build/ninja_config.mk
71
72# Any Android goals that need to be built.
73ANDROID_GOALS := $(filter-out $(KATI_OUTPUT_PATTERNS) $(KATI) $(MAKEPARALLEL),\
74    $(sort $(ORIGINAL_MAKECMDGOALS) $(MAKECMDGOALS)))
75# Goals we need to pass to Ninja.
76NINJA_GOALS := $(filter-out $(NINJA_EXCLUDE_GOALS), $(ANDROID_GOALS))
77# Goals we need to pass to Kati.
78KATI_GOALS := $(filter $(PARSE_TIME_MAKE_GOALS),  $(ANDROID_GOALS))
79
80define replace_space_and_slash
81$(subst /,_,$(subst $(space),_,$(sort $1)))
82endef
83
84KATI_NINJA_SUFFIX := -$(TARGET_PRODUCT)
85ifneq ($(KATI_GOALS),)
86KATI_NINJA_SUFFIX := $(KATI_NINJA_SUFFIX)-$(call replace_space_and_slash,$(KATI_GOALS))
87endif
88ifneq ($(ONE_SHOT_MAKEFILE),)
89KATI_NINJA_SUFFIX := $(KATI_NINJA_SUFFIX)-mmm-$(call replace_space_and_slash,$(ONE_SHOT_MAKEFILE))
90endif
91ifneq ($(BUILD_MODULES_IN_PATHS),)
92KATI_NINJA_SUFFIX := $(KATI_NINJA_SUFFIX)-mmma-$(call replace_space_and_slash,$(BUILD_MODULES_IN_PATHS))
93endif
94
95my_checksum_suffix :=
96my_ninja_suffix_too_long := $(filter 1, $(shell v='$(KATI_NINJA_SUFFIX)' && echo $$(($${$(pound)v} > 64))))
97ifneq ($(my_ninja_suffix_too_long),)
98# Replace the suffix with a checksum if it gets too long.
99my_checksum_suffix := $(KATI_NINJA_SUFFIX)
100KATI_NINJA_SUFFIX := -$(word 1, $(shell echo $(my_checksum_suffix) | $(MD5SUM)))
101endif
102
103KATI_BUILD_NINJA := $(OUT_DIR)/build$(KATI_NINJA_SUFFIX).ninja
104KATI_ENV_SH := $(OUT_DIR)/env$(KATI_NINJA_SUFFIX).sh
105
106# Write out a file mapping checksum to the real suffix.
107ifneq ($(my_checksum_suffix),)
108my_ninja_suffix_file := $(basename $(KATI_BUILD_NINJA)).suf
109$(shell mkdir -p $(dir $(my_ninja_suffix_file)) && \
110    echo $(my_checksum_suffix) > $(my_ninja_suffix_file))
111endif
112
113ifeq (,$(NINJA_STATUS))
114NINJA_STATUS := [%p %s/%t]$(space)
115endif
116
117ifneq (,$(filter showcommands,$(ORIGINAL_MAKECMDGOALS)))
118NINJA_ARGS += "-v"
119endif
120
121ifdef USE_GOMA
122KATI_MAKEPARALLEL := $(MAKEPARALLEL)
123# Ninja runs remote jobs (i.e., commands which contain gomacc) with
124# this parallelism. Note the parallelism of all other jobs is still
125# limited by the -j flag passed to GNU make.
126NINJA_REMOTE_NUM_JOBS ?= 500
127NINJA_ARGS += -j$(NINJA_REMOTE_NUM_JOBS)
128else
129NINJA_MAKEPARALLEL := $(MAKEPARALLEL) --ninja
130endif
131
132ifeq ($(USE_SOONG),true)
133COMBINED_BUILD_NINJA := $(OUT_DIR)/combined$(KATI_NINJA_SUFFIX).ninja
134
135$(COMBINED_BUILD_NINJA): $(KATI_BUILD_NINJA) $(SOONG_ANDROID_MK)
136	$(hide) echo "builddir = $(OUT_DIR)" > $(COMBINED_BUILD_NINJA)
137	$(hide) echo "subninja $(SOONG_BUILD_NINJA)" >> $(COMBINED_BUILD_NINJA)
138	$(hide) echo "subninja $(KATI_BUILD_NINJA)" >> $(COMBINED_BUILD_NINJA)
139else
140COMBINED_BUILD_NINJA := $(KATI_BUILD_NINJA)
141endif
142
143$(sort $(DEFAULT_GOAL) $(ANDROID_GOALS)) : ninja_wrapper
144	@#empty
145
146.PHONY: ninja_wrapper
147ninja_wrapper: $(COMBINED_BUILD_NINJA) $(MAKEPARALLEL)
148	@echo Starting build with ninja
149	+$(hide) export NINJA_STATUS="$(NINJA_STATUS)" && source $(KATI_ENV_SH) && $(NINJA_MAKEPARALLEL) $(NINJA) $(NINJA_GOALS) -C $(TOP) -f $(COMBINED_BUILD_NINJA) $(NINJA_ARGS)
150
151# Dummy Android.mk and CleanSpec.mk files so that kati won't recurse into the
152# out directory
153DUMMY_OUT_MKS := $(OUT_DIR)/Android.mk $(OUT_DIR)/CleanSpec.mk
154$(DUMMY_OUT_MKS):
155	@mkdir -p $(dir $@)
156	$(hide) echo '# This file prevents findleaves.py from traversing this directory further' >$@
157
158KATI_FIND_EMULATOR := --use_find_emulator
159ifeq ($(KATI_EMULATE_FIND),false)
160  KATI_FIND_EMULATOR :=
161endif
162$(KATI_BUILD_NINJA): $(KATI) $(MAKEPARALLEL) $(DUMMY_OUT_MKS) $(SOONG_ANDROID_MK) FORCE
163	@echo Running kati to generate build$(KATI_NINJA_SUFFIX).ninja...
164	+$(hide) $(KATI_MAKEPARALLEL) $(KATI) --ninja --ninja_dir=$(OUT_DIR) --ninja_suffix=$(KATI_NINJA_SUFFIX) --regen --ignore_dirty=$(OUT_DIR)/% --no_ignore_dirty=$(SOONG_ANDROID_MK) --ignore_optional_include=$(OUT_DIR)/%.P --detect_android_echo $(KATI_FIND_EMULATOR) -f build/core/main.mk $(KATI_GOALS) --gen_all_targets BUILDING_WITH_NINJA=true SOONG_ANDROID_MK=$(SOONG_ANDROID_MK)
165
166ifneq ($(USE_SOONG_FOR_KATI),true)
167KATI_CXX := $(CLANG_CXX) $(CLANG_HOST_GLOBAL_CFLAGS) $(CLANG_HOST_GLOBAL_CPPFLAGS)
168KATI_LD := $(CLANG_CXX) $(CLANG_HOST_GLOBAL_LDFLAGS)
169# Build static ckati. Unfortunately Mac OS X doesn't officially support static exectuables.
170ifeq ($(BUILD_OS),linux)
171# We need everything in libpthread.a otherwise C++11's threading library will be disabled.
172KATI_LD += -static -Wl,--whole-archive -lpthread -Wl,--no-whole-archive -ldl
173endif
174
175KATI_INTERMEDIATES_PATH := $(HOST_OUT_INTERMEDIATES)/EXECUTABLES/ckati_intermediates
176KATI_BIN_PATH := $(HOST_OUT_EXECUTABLES)
177include build/kati/Makefile.ckati
178
179MAKEPARALLEL_CXX := $(CLANG_CXX) $(CLANG_HOST_GLOBAL_CFLAGS) $(CLANG_HOST_GLOBAL_CPPFLAGS)
180MAKEPARALLEL_LD := $(CLANG_CXX) $(CLANG_HOST_GLOBAL_LDFLAGS)
181# Build static makeparallel. Unfortunately Mac OS X doesn't officially support static exectuables.
182ifeq ($(BUILD_OS),linux)
183MAKEPARALLEL_LD += -static
184endif
185
186MAKEPARALLEL_INTERMEDIATES_PATH := $(HOST_OUT_INTERMEDIATES)/EXECUTABLES/makeparallel_intermediates
187MAKEPARALLEL_BIN_PATH := $(HOST_OUT_EXECUTABLES)
188include build/tools/makeparallel/Makefile
189endif
190
191.PHONY: FORCE
192FORCE:
193