1 NINJA ?= prebuilts/ninja/$(HOST_PREBUILT_TAG)/ninja 2 3 ifeq ($(USE_SOONG),true) 4 USE_SOONG_FOR_KATI := true 5 endif 6 7 ifeq ($(USE_SOONG_FOR_KATI),true) 8 include $(BUILD_SYSTEM)/soong.mk 9 else 10 KATI ?= $(HOST_OUT_EXECUTABLES)/ckati 11 MAKEPARALLEL ?= $(HOST_OUT_EXECUTABLES)/makeparallel 12 endif 13 14 KATI_OUTPUT_PATTERNS := $(OUT_DIR)/build%.ninja $(OUT_DIR)/ninja%.sh 15 16 # Modifier goals we don't need to pass to Ninja. 17 NINJA_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. 21 PARSE_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. 73 ANDROID_GOALS := $(filter-out $(KATI_OUTPUT_PATTERNS) $(KATI) $(MAKEPARALLEL),\ 74 $(sort $(ORIGINAL_MAKECMDGOALS) $(MAKECMDGOALS))) 75 # Goals we need to pass to Ninja. 76 NINJA_GOALS := $(filter-out $(NINJA_EXCLUDE_GOALS), $(ANDROID_GOALS)) 77 # Goals we need to pass to Kati. 78 KATI_GOALS := $(filter $(PARSE_TIME_MAKE_GOALS), $(ANDROID_GOALS)) 79 80 define replace_space_and_slash 81 $(subst /,_,$(subst $(space),_,$(sort $1))) 82 endef 83 84 KATI_NINJA_SUFFIX := -$(TARGET_PRODUCT) 85 ifneq ($(KATI_GOALS),) 86 KATI_NINJA_SUFFIX := $(KATI_NINJA_SUFFIX)-$(call replace_space_and_slash,$(KATI_GOALS)) 87 endif 88 ifneq ($(ONE_SHOT_MAKEFILE),) 89 KATI_NINJA_SUFFIX := $(KATI_NINJA_SUFFIX)-mmm-$(call replace_space_and_slash,$(ONE_SHOT_MAKEFILE)) 90 endif 91 ifneq ($(BUILD_MODULES_IN_PATHS),) 92 KATI_NINJA_SUFFIX := $(KATI_NINJA_SUFFIX)-mmma-$(call replace_space_and_slash,$(BUILD_MODULES_IN_PATHS)) 93 endif 94 95 my_checksum_suffix := 96 my_ninja_suffix_too_long := $(filter 1, $(shell v='$(KATI_NINJA_SUFFIX)' && echo $$(($${$(pound)v} > 64)))) 97 ifneq ($(my_ninja_suffix_too_long),) 98 # Replace the suffix with a checksum if it gets too long. 99 my_checksum_suffix := $(KATI_NINJA_SUFFIX) 100 KATI_NINJA_SUFFIX := -$(word 1, $(shell echo $(my_checksum_suffix) | $(MD5SUM))) 101 endif 102 103 KATI_BUILD_NINJA := $(OUT_DIR)/build$(KATI_NINJA_SUFFIX).ninja 104 KATI_ENV_SH := $(OUT_DIR)/env$(KATI_NINJA_SUFFIX).sh 105 106 # Write out a file mapping checksum to the real suffix. 107 ifneq ($(my_checksum_suffix),) 108 my_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)) 111 endif 112 113 ifeq (,$(NINJA_STATUS)) 114 NINJA_STATUS := [%p %s/%t]$(space) 115 endif 116 117 ifneq (,$(filter showcommands,$(ORIGINAL_MAKECMDGOALS))) 118 NINJA_ARGS += "-v" 119 endif 120 121 ifdef USE_GOMA 122 KATI_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. 126 NINJA_REMOTE_NUM_JOBS ?= 500 127 NINJA_ARGS += -j$(NINJA_REMOTE_NUM_JOBS) 128 else 129 NINJA_MAKEPARALLEL := $(MAKEPARALLEL) --ninja 130 endif 131 132 ifeq ($(USE_SOONG),true) 133 COMBINED_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) 139 else 140 COMBINED_BUILD_NINJA := $(KATI_BUILD_NINJA) 141 endif 142 143 $(sort $(DEFAULT_GOAL) $(ANDROID_GOALS)) : ninja_wrapper 144 @#empty 145 146 .PHONY: ninja_wrapper 147 ninja_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 153 DUMMY_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 158 KATI_FIND_EMULATOR := --use_find_emulator 159 ifeq ($(KATI_EMULATE_FIND),false) 160 KATI_FIND_EMULATOR := 161 endif 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 166 ifneq ($(USE_SOONG_FOR_KATI),true) 167 KATI_CXX := $(CLANG_CXX) $(CLANG_HOST_GLOBAL_CFLAGS) $(CLANG_HOST_GLOBAL_CPPFLAGS) 168 KATI_LD := $(CLANG_CXX) $(CLANG_HOST_GLOBAL_LDFLAGS) 169 # Build static ckati. Unfortunately Mac OS X doesn't officially support static exectuables. 170 ifeq ($(BUILD_OS),linux) 171 # We need everything in libpthread.a otherwise C++11's threading library will be disabled. 172 KATI_LD += -static -Wl,--whole-archive -lpthread -Wl,--no-whole-archive -ldl 173 endif 174 175 KATI_INTERMEDIATES_PATH := $(HOST_OUT_INTERMEDIATES)/EXECUTABLES/ckati_intermediates 176 KATI_BIN_PATH := $(HOST_OUT_EXECUTABLES) 177 include build/kati/Makefile.ckati 178 179 MAKEPARALLEL_CXX := $(CLANG_CXX) $(CLANG_HOST_GLOBAL_CFLAGS) $(CLANG_HOST_GLOBAL_CPPFLAGS) 180 MAKEPARALLEL_LD := $(CLANG_CXX) $(CLANG_HOST_GLOBAL_LDFLAGS) 181 # Build static makeparallel. Unfortunately Mac OS X doesn't officially support static exectuables. 182 ifeq ($(BUILD_OS),linux) 183 MAKEPARALLEL_LD += -static 184 endif 185 186 MAKEPARALLEL_INTERMEDIATES_PATH := $(HOST_OUT_INTERMEDIATES)/EXECUTABLES/makeparallel_intermediates 187 MAKEPARALLEL_BIN_PATH := $(HOST_OUT_EXECUTABLES) 188 include build/tools/makeparallel/Makefile 189 endif 190 191 .PHONY: FORCE 192 FORCE: 193