1SOONG_OUT_DIR := $(OUT_DIR)/soong
2SOONG_HOST_EXECUTABLES := $(SOONG_OUT_DIR)/host/$(HOST_PREBUILT_TAG)/bin
3KATI := $(SOONG_HOST_EXECUTABLES)/ckati
4MAKEPARALLEL := $(SOONG_HOST_EXECUTABLES)/makeparallel
5
6SOONG := $(SOONG_OUT_DIR)/soong
7SOONG_BOOTSTRAP := $(SOONG_OUT_DIR)/.soong.bootstrap
8SOONG_BUILD_NINJA := $(SOONG_OUT_DIR)/build.ninja
9SOONG_ANDROID_MK := $(SOONG_OUT_DIR)/Android.mk
10SOONG_IN_MAKE := $(SOONG_OUT_DIR)/.soong.in_make
11SOONG_VARIABLES := $(SOONG_OUT_DIR)/soong.variables
12
13# We need to rebootstrap soong if SOONG_OUT_DIR or the reverse path from
14# SOONG_OUT_DIR to TOP changes
15SOONG_NEEDS_REBOOTSTRAP :=
16ifneq ($(wildcard $(SOONG_BOOTSTRAP)),)
17  ifneq ($(SOONG_OUT_DIR),$(strip $(shell source $(SOONG_BOOTSTRAP); echo $$BUILDDIR)))
18    SOONG_NEEDS_REBOOTSTRAP := FORCE
19    $(warning soong_out_dir changed)
20  endif
21  ifneq ($(strip $(shell build/soong/reverse_path.py $(SOONG_OUT_DIR))),$(strip $(shell source $(SOONG_BOOTSTRAP); echo $$SRCDIR_FROM_BUILDDIR)))
22    SOONG_NEEDS_REBOOTSTRAP := FORCE
23    $(warning reverse path changed)
24  endif
25endif
26
27# Bootstrap soong.
28$(SOONG_BOOTSTRAP): bootstrap.bash $(SOONG_NEEDS_REBOOTSTRAP)
29	$(hide) mkdir -p $(dir $@)
30	$(hide) BUILDDIR=$(SOONG_OUT_DIR) ./bootstrap.bash
31
32# Create soong.variables with copies of makefile settings.  Runs every build,
33# but only updates soong.variables if it changes
34SOONG_VARIABLES_TMP := $(SOONG_VARIABLES).$$$$
35$(SOONG_VARIABLES): FORCE
36	$(hide) mkdir -p $(dir $@)
37	$(hide) (\
38	echo '{'; \
39	echo '    "Device_uses_jemalloc": $(if $(filter true,$(MALLOC_SVELTE)),false,true),'; \
40	echo '    "Device_uses_dlmalloc": $(if $(filter true,$(MALLOC_SVELTE)),true,false),'; \
41	echo '    "Platform_sdk_version": $(PLATFORM_SDK_VERSION),'; \
42	echo '    "Unbundled_build": $(if $(TARGET_BUILD_APPS),true,false),'; \
43	echo '    "Brillo": $(if $(BRILLO),true,false),'; \
44	echo ''; \
45	echo '    "DeviceName": "$(TARGET_DEVICE)",'; \
46	echo '    "DeviceArch": "$(TARGET_ARCH)",'; \
47	echo '    "DeviceArchVariant": "$(TARGET_ARCH_VARIANT)",'; \
48	echo '    "DeviceCpuVariant": "$(TARGET_CPU_VARIANT)",'; \
49	echo '    "DeviceAbi": ["$(TARGET_CPU_ABI)", "$(TARGET_CPU_ABI2)"],'; \
50	echo '    "DeviceUsesClang": $(if $(USE_CLANG_PLATFORM_BUILD),$(USE_CLANG_PLATFORM_BUILD),false),'; \
51	echo ''; \
52	echo '    "DeviceSecondaryArch": "$(TARGET_2ND_ARCH)",'; \
53	echo '    "DeviceSecondaryArchVariant": "$(TARGET_2ND_ARCH_VARIANT)",'; \
54	echo '    "DeviceSecondaryCpuVariant": "$(TARGET_2ND_CPU_VARIANT)",'; \
55	echo '    "DeviceSecondaryAbi": ["$(TARGET_2ND_CPU_ABI)", "$(TARGET_2ND_CPU_ABI2)"],'; \
56	echo ''; \
57	echo '    "HostArch": "$(HOST_ARCH)",'; \
58	echo '    "HostSecondaryArch": "$(HOST_2ND_ARCH)",'; \
59	echo ''; \
60	echo '    "CrossHost": "$(HOST_CROSS_OS)",'; \
61	echo '    "CrossHostArch": "$(HOST_CROSS_ARCH)",'; \
62	echo '    "CrossHostSecondaryArch": "$(HOST_CROSS_2ND_ARCH)"'; \
63	echo '}') > $(SOONG_VARIABLES_TMP); \
64	if ! cmp -s $(SOONG_VARIABLES_TMP) $(SOONG_VARIABLES); then \
65	  mv $(SOONG_VARIABLES_TMP) $(SOONG_VARIABLES); \
66	else \
67	  rm $(SOONG_VARIABLES_TMP); \
68	fi
69
70# Tell soong that it is embedded in make
71$(SOONG_IN_MAKE):
72	$(hide) mkdir -p $(dir $@)
73	$(hide) touch $@
74
75# Build an Android.mk listing all soong outputs as prebuilts
76$(SOONG_ANDROID_MK): $(SOONG_BOOTSTRAP) $(SOONG_VARIABLES) $(SOONG_IN_MAKE) FORCE
77	$(hide) $(SOONG) $(KATI) $(MAKEPARALLEL) $(NINJA_ARGS)
78
79$(KATI): $(SOONG_ANDROID_MK)
80$(MAKEPARALLEL): $(SOONG_ANDROID_MK)
81