1ifndef KATI
2$(warning Calling make directly is no longer supported.)
3$(warning Either use 'envsetup.sh; m' or 'build/soong/soong_ui.bash --make-mode')
4$(error done)
5endif
6
7$(info [1/1] initializing build system ...)
8
9# Absolute path of the present working direcotry.
10# This overrides the shell variable $PWD, which does not necessarily points to
11# the top of the source tree, for example when "make -C" is used in m/mm/mmm.
12PWD := $(shell pwd)
13
14# This is the default target.  It must be the first declared target.
15.PHONY: droid
16DEFAULT_GOAL := droid
17$(DEFAULT_GOAL): droid_targets
18
19.PHONY: droid_targets
20droid_targets:
21
22# Set up various standard variables based on configuration
23# and host information.
24include build/make/core/config.mk
25
26ifneq ($(filter $(dont_bother_goals), $(MAKECMDGOALS)),)
27dont_bother := true
28endif
29
30.KATI_READONLY := SOONG_CONFIG_NAMESPACES
31.KATI_READONLY := $(foreach n,$(SOONG_CONFIG_NAMESPACES),SOONG_CONFIG_$(n))
32.KATI_READONLY := $(foreach n,$(SOONG_CONFIG_NAMESPACES),$(foreach k,$(SOONG_CONFIG_$(n)),SOONG_CONFIG_$(n)_$(k)))
33
34include $(SOONG_MAKEVARS_MK)
35
36include $(BUILD_SYSTEM)/clang/config.mk
37
38# Write the build number to a file so it can be read back in
39# without changing the command line every time.  Avoids rebuilds
40# when using ninja.
41$(shell mkdir -p $(SOONG_OUT_DIR) && \
42    echo -n $(BUILD_NUMBER) > $(SOONG_OUT_DIR)/build_number.txt)
43BUILD_NUMBER_FILE := $(SOONG_OUT_DIR)/build_number.txt
44.KATI_READONLY := BUILD_NUMBER_FILE
45$(KATI_obsolete_var BUILD_NUMBER,See https://android.googlesource.com/platform/build/+/master/Changes.md#BUILD_NUMBER)
46$(BUILD_NUMBER_FILE):
47	touch $@
48
49DATE_FROM_FILE := date -d @$(BUILD_DATETIME_FROM_FILE)
50.KATI_READONLY := DATE_FROM_FILE
51
52# Pick a reasonable string to use to identify files.
53ifeq ($(strip $(HAS_BUILD_NUMBER)),false)
54  # BUILD_NUMBER has a timestamp in it, which means that
55  # it will change every time.  Pick a stable value.
56  FILE_NAME_TAG := eng.$(BUILD_USERNAME)
57else
58  FILE_NAME_TAG := $(file <$(BUILD_NUMBER_FILE))
59endif
60.KATI_READONLY := FILE_NAME_TAG
61
62# Make an empty directory, which can be used to make empty jars
63EMPTY_DIRECTORY := $(OUT_DIR)/empty
64$(shell mkdir -p $(EMPTY_DIRECTORY) && rm -rf $(EMPTY_DIRECTORY)/*)
65
66# CTS-specific config.
67-include cts/build/config.mk
68# VTS-specific config.
69-include test/vts/tools/vts-tradefed/build/config.mk
70# device-tests-specific-config.
71-include tools/tradefederation/build/suites/device-tests/config.mk
72# general-tests-specific-config.
73-include tools/tradefederation/build/suites/general-tests/config.mk
74# STS-specific config.
75-include test/sts/tools/sts-tradefed/build/config.mk
76# CTS-Instant-specific config
77-include test/suite_harness/tools/cts-instant-tradefed/build/config.mk
78# MTS-specific config.
79-include test/mts/tools/build/config.mk
80# VTS-Core-specific config.
81-include test/vts/tools/vts-core-tradefed/build/config.mk
82# CSUITE-specific config.
83-include test/app_compat/csuite/tools/build/config.mk
84
85# Clean rules
86.PHONY: clean-dex-files
87clean-dex-files:
88	$(hide) find $(OUT_DIR) -name "*.dex" | xargs rm -f
89	$(hide) for i in `find $(OUT_DIR) -name "*.jar" -o -name "*.apk"` ; do ((unzip -l $$i 2> /dev/null | \
90				grep -q "\.dex$$" && rm -f $$i) || continue ) ; done
91	@echo "All dex files and archives containing dex files have been removed."
92
93# Include the google-specific config
94-include vendor/google/build/config.mk
95
96# These are the modifier targets that don't do anything themselves, but
97# change the behavior of the build.
98# (must be defined before including definitions.make)
99INTERNAL_MODIFIER_TARGETS := all
100
101# EMMA_INSTRUMENT_STATIC merges the static jacoco library to each
102# jacoco-enabled module.
103ifeq (true,$(EMMA_INSTRUMENT_STATIC))
104EMMA_INSTRUMENT := true
105endif
106
107ifeq (true,$(EMMA_INSTRUMENT))
108# Adding the jacoco library can cause the inclusion of
109# some typically banned classes
110# So if the user didn't specify SKIP_BOOT_JARS_CHECK, enable it here
111ifndef SKIP_BOOT_JARS_CHECK
112SKIP_BOOT_JARS_CHECK := true
113endif
114endif
115
116#
117# -----------------------------------------------------------------
118# Validate ADDITIONAL_DEFAULT_PROPERTIES.
119ifneq ($(ADDITIONAL_DEFAULT_PROPERTIES),)
120$(error ADDITIONAL_DEFAULT_PROPERTIES must not be set before here: $(ADDITIONAL_DEFAULT_PROPERTIES))
121endif
122
123#
124# -----------------------------------------------------------------
125# Validate ADDITIONAL_BUILD_PROPERTIES.
126ifneq ($(ADDITIONAL_BUILD_PROPERTIES),)
127$(error ADDITIONAL_BUILD_PROPERTIES must not be set before here: $(ADDITIONAL_BUILD_PROPERTIES))
128endif
129
130ADDITIONAL_BUILD_PROPERTIES :=
131
132#
133# -----------------------------------------------------------------
134# Validate ADDITIONAL_PRODUCT_PROPERTIES.
135ifneq ($(ADDITIONAL_PRODUCT_PROPERTIES),)
136$(error ADDITIONAL_PRODUCT_PROPERTIES must not be set before here: $(ADDITIONAL_PRODUCT_PROPERTIES))
137endif
138
139ADDITIONAL_PRODUCT_PROPERTIES :=
140
141#
142# -----------------------------------------------------------------
143# Add the product-defined properties to the build properties.
144ifdef PRODUCT_SHIPPING_API_LEVEL
145ADDITIONAL_BUILD_PROPERTIES += \
146  ro.product.first_api_level=$(PRODUCT_SHIPPING_API_LEVEL)
147endif
148
149ifneq ($(BOARD_PROPERTY_OVERRIDES_SPLIT_ENABLED), true)
150  ADDITIONAL_BUILD_PROPERTIES += $(PRODUCT_PROPERTY_OVERRIDES)
151else
152  ifndef BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE
153    ADDITIONAL_BUILD_PROPERTIES += $(PRODUCT_PROPERTY_OVERRIDES)
154  endif
155endif
156
157
158# Bring in standard build system definitions.
159include $(BUILD_SYSTEM)/definitions.mk
160
161# Bring in dex_preopt.mk
162include $(BUILD_SYSTEM)/dex_preopt.mk
163
164ifneq ($(filter user userdebug eng,$(MAKECMDGOALS)),)
165$(info ***************************************************************)
166$(info ***************************************************************)
167$(info Do not pass '$(filter user userdebug eng,$(MAKECMDGOALS))' on \
168       the make command line.)
169$(info Set TARGET_BUILD_VARIANT in buildspec.mk, or use lunch or)
170$(info choosecombo.)
171$(info ***************************************************************)
172$(info ***************************************************************)
173$(error stopping)
174endif
175
176# These are the valid values of TARGET_BUILD_VARIANT.
177INTERNAL_VALID_VARIANTS := user userdebug eng
178ifneq ($(filter-out $(INTERNAL_VALID_VARIANTS),$(TARGET_BUILD_VARIANT)),)
179$(info ***************************************************************)
180$(info ***************************************************************)
181$(info Invalid variant: $(TARGET_BUILD_VARIANT))
182$(info Valid values are: $(INTERNAL_VALID_VARIANTS))
183$(info ***************************************************************)
184$(info ***************************************************************)
185$(error stopping)
186endif
187
188# -----------------------------------------------------------------
189# Variable to check java support level inside PDK build.
190# Not necessary if the components is not in PDK.
191# not defined : not supported
192# "sdk" : sdk API only
193# "platform" : platform API supproted
194TARGET_BUILD_JAVA_SUPPORT_LEVEL := platform
195
196# -----------------------------------------------------------------
197# The pdk (Platform Development Kit) build
198include build/make/core/pdk_config.mk
199
200# -----------------------------------------------------------------
201
202ADDITIONAL_BUILD_PROPERTIES += ro.treble.enabled=${PRODUCT_FULL_TREBLE}
203
204$(KATI_obsolete_var PRODUCT_FULL_TREBLE,\
205	Code should be written to work regardless of a device being Treble or \
206	variables like PRODUCT_SEPOLICY_SPLIT should be used until that is \
207	possible.)
208
209# Sets ro.actionable_compatible_property.enabled to know on runtime whether the
210# allowed list of actionable compatible properties is enabled or not.
211ifeq ($(PRODUCT_ACTIONABLE_COMPATIBLE_PROPERTY_DISABLE),true)
212ADDITIONAL_DEFAULT_PROPERTIES += ro.actionable_compatible_property.enabled=false
213else
214ADDITIONAL_DEFAULT_PROPERTIES += ro.actionable_compatible_property.enabled=${PRODUCT_COMPATIBLE_PROPERTY}
215endif
216
217# Add the system server compiler filter if they are specified for the product.
218ifneq (,$(PRODUCT_SYSTEM_SERVER_COMPILER_FILTER))
219ADDITIONAL_PRODUCT_PROPERTIES += dalvik.vm.systemservercompilerfilter=$(PRODUCT_SYSTEM_SERVER_COMPILER_FILTER)
220endif
221
222# Enable core platform API violation warnings on userdebug and eng builds.
223ifneq ($(TARGET_BUILD_VARIANT),user)
224ADDITIONAL_BUILD_PROPERTIES += persist.debug.dalvik.vm.core_platform_api_policy=just-warn
225endif
226
227# Sets the default value of ro.postinstall.fstab.prefix to /system.
228# Device board config should override the value to /product when needed by:
229#
230#     PRODUCT_PRODUCT_PROPERTIES += ro.postinstall.fstab.prefix=/product
231#
232# It then uses ${ro.postinstall.fstab.prefix}/etc/fstab.postinstall to
233# mount system_other partition.
234ADDITIONAL_DEFAULT_PROPERTIES += ro.postinstall.fstab.prefix=/system
235
236# Set ro.product.vndk.version to know the VNDK version required by product
237# modules. It uses the version in PRODUCT_PRODUCT_VNDK_VERSION. If the value
238# is "current", use PLATFORM_VNDK_VERSION.
239ifdef PRODUCT_PRODUCT_VNDK_VERSION
240ifeq ($(PRODUCT_PRODUCT_VNDK_VERSION),current)
241ADDITIONAL_PRODUCT_PROPERTIES += ro.product.vndk.version=$(PLATFORM_VNDK_VERSION)
242else
243ADDITIONAL_PRODUCT_PROPERTIES += ro.product.vndk.version=$(PRODUCT_PRODUCT_VNDK_VERSION)
244endif
245endif
246
247# -----------------------------------------------------------------
248###
249### In this section we set up the things that are different
250### between the build variants
251###
252
253is_sdk_build :=
254
255ifneq ($(filter sdk win_sdk sdk_addon,$(MAKECMDGOALS)),)
256is_sdk_build := true
257endif
258
259## user/userdebug ##
260
261user_variant := $(filter user userdebug,$(TARGET_BUILD_VARIANT))
262enable_target_debugging := true
263tags_to_install :=
264ifneq (,$(user_variant))
265  # Target is secure in user builds.
266  ADDITIONAL_DEFAULT_PROPERTIES += ro.secure=1
267  ADDITIONAL_DEFAULT_PROPERTIES += security.perf_harden=1
268
269  ifeq ($(user_variant),user)
270    ADDITIONAL_DEFAULT_PROPERTIES += ro.adb.secure=1
271  endif
272
273  ifeq ($(user_variant),userdebug)
274    # Pick up some extra useful tools
275    tags_to_install += debug
276  else
277    # Disable debugging in plain user builds.
278    enable_target_debugging :=
279  endif
280
281  # Disallow mock locations by default for user builds
282  ADDITIONAL_DEFAULT_PROPERTIES += ro.allow.mock.location=0
283
284else # !user_variant
285  # Turn on checkjni for non-user builds.
286  ADDITIONAL_BUILD_PROPERTIES += ro.kernel.android.checkjni=1
287  # Set device insecure for non-user builds.
288  ADDITIONAL_DEFAULT_PROPERTIES += ro.secure=0
289  # Allow mock locations by default for non user builds
290  ADDITIONAL_DEFAULT_PROPERTIES += ro.allow.mock.location=1
291endif # !user_variant
292
293ifeq (true,$(strip $(enable_target_debugging)))
294  # Target is more debuggable and adbd is on by default
295  ADDITIONAL_DEFAULT_PROPERTIES += ro.debuggable=1
296  # Enable Dalvik lock contention logging.
297  ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.lockprof.threshold=500
298else # !enable_target_debugging
299  # Target is less debuggable and adbd is off by default
300  ADDITIONAL_DEFAULT_PROPERTIES += ro.debuggable=0
301endif # !enable_target_debugging
302
303## eng ##
304
305ifeq ($(TARGET_BUILD_VARIANT),eng)
306tags_to_install := debug eng
307ifneq ($(filter ro.setupwizard.mode=ENABLED, $(call collapse-pairs, $(ADDITIONAL_BUILD_PROPERTIES))),)
308  # Don't require the setup wizard on eng builds
309  ADDITIONAL_BUILD_PROPERTIES := $(filter-out ro.setupwizard.mode=%,\
310          $(call collapse-pairs, $(ADDITIONAL_BUILD_PROPERTIES))) \
311          ro.setupwizard.mode=OPTIONAL
312endif
313ifndef is_sdk_build
314  # To speedup startup of non-preopted builds, don't verify or compile the boot image.
315  ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.image-dex2oat-filter=extract
316endif
317endif
318
319## asan ##
320
321# Install some additional tools on ASAN builds IFF we are also installing debug tools
322ifneq ($(filter address,$(SANITIZE_TARGET)),)
323ifneq (,$(filter debug,$(tags_to_install)))
324  tags_to_install += asan
325endif
326endif
327
328## java coverage ##
329# Install additional tools on java coverage builds
330ifeq (true,$(EMMA_INSTRUMENT))
331ifneq (,$(filter debug,$(tags_to_install)))
332  tags_to_install += java_coverage
333endif
334endif
335
336
337## sdk ##
338
339ifdef is_sdk_build
340
341# Detect if we want to build a repository for the SDK
342sdk_repo_goal := $(strip $(filter sdk_repo,$(MAKECMDGOALS)))
343MAKECMDGOALS := $(strip $(filter-out sdk_repo,$(MAKECMDGOALS)))
344
345ifneq ($(words $(sort $(filter-out $(INTERNAL_MODIFIER_TARGETS) checkbuild emulator_tests target-files-package,$(MAKECMDGOALS)))),1)
346$(error The 'sdk' target may not be specified with any other targets)
347endif
348
349# AUX dependencies are already added by now; remove triggers from the MAKECMDGOALS
350MAKECMDGOALS := $(strip $(filter-out AUX-%,$(MAKECMDGOALS)))
351
352# TODO: this should be eng I think.  Since the sdk is built from the eng
353# variant.
354tags_to_install := debug eng
355ADDITIONAL_BUILD_PROPERTIES += xmpp.auto-presence=true
356ADDITIONAL_BUILD_PROPERTIES += ro.config.nocheckin=yes
357else # !sdk
358endif
359
360BUILD_WITHOUT_PV := true
361
362ADDITIONAL_BUILD_PROPERTIES += net.bt.name=Android
363
364# ------------------------------------------------------------
365# Define a function that, given a list of module tags, returns
366# non-empty if that module should be installed in /system.
367
368# For most goals, anything not tagged with the "tests" tag should
369# be installed in /system.
370define should-install-to-system
371$(if $(filter tests,$(1)),,true)
372endef
373
374ifdef is_sdk_build
375# For the sdk goal, anything with the "samples" tag should be
376# installed in /data even if that module also has "eng"/"debug"/"user".
377define should-install-to-system
378$(if $(filter samples tests,$(1)),,true)
379endef
380endif
381
382
383# If they only used the modifier goals (all, etc), we'll actually
384# build the default target.
385ifeq ($(filter-out $(INTERNAL_MODIFIER_TARGETS),$(MAKECMDGOALS)),)
386.PHONY: $(INTERNAL_MODIFIER_TARGETS)
387$(INTERNAL_MODIFIER_TARGETS): $(DEFAULT_GOAL)
388endif
389
390#
391# Typical build; include any Android.mk files we can find.
392#
393
394# Strip and readonly a few more variables so they won't be modified.
395$(readonly-final-product-vars)
396ADDITIONAL_DEFAULT_PROPERTIES := $(strip $(ADDITIONAL_DEFAULT_PROPERTIES))
397.KATI_READONLY := ADDITIONAL_DEFAULT_PROPERTIES
398ADDITIONAL_BUILD_PROPERTIES := $(strip $(ADDITIONAL_BUILD_PROPERTIES))
399.KATI_READONLY := ADDITIONAL_BUILD_PROPERTIES
400ADDITIONAL_PRODUCT_PROPERTIES := $(strip $(ADDITIONAL_PRODUCT_PROPERTIES))
401.KATI_READONLY := ADDITIONAL_PRODUCT_PROPERTIES
402
403ifneq ($(PRODUCT_ENFORCE_RRO_TARGETS),)
404ENFORCE_RRO_SOURCES :=
405endif
406
407# Color-coded warnings including current module info
408# $(1): message to print
409define pretty-warning
410$(shell $(call echo-warning,$(LOCAL_MODULE_MAKEFILE),$(LOCAL_MODULE): $(1)))
411endef
412
413# Color-coded errors including current module info
414# $(1): message to print
415define pretty-error
416$(shell $(call echo-error,$(LOCAL_MODULE_MAKEFILE),$(LOCAL_MODULE): $(1)))
417$(error done)
418endef
419
420subdir_makefiles_inc := .
421FULL_BUILD :=
422
423ifneq ($(dont_bother),true)
424FULL_BUILD := true
425#
426# Include all of the makefiles in the system
427#
428
429subdir_makefiles := $(SOONG_ANDROID_MK) $(file <$(OUT_DIR)/.module_paths/Android.mk.list) $(SOONG_OUT_DIR)/late-$(TARGET_PRODUCT).mk
430subdir_makefiles_total := $(words int $(subdir_makefiles) post finish)
431.KATI_READONLY := subdir_makefiles_total
432
433$(foreach mk,$(subdir_makefiles),$(info [$(call inc_and_print,subdir_makefiles_inc)/$(subdir_makefiles_total)] including $(mk) ...)$(eval include $(mk)))
434
435ifneq (,$(PDK_FUSION_PLATFORM_ZIP)$(PDK_FUSION_PLATFORM_DIR))
436# Bring in the PDK platform.zip modules.
437include $(BUILD_SYSTEM)/pdk_fusion_modules.mk
438endif # PDK_FUSION_PLATFORM_ZIP || PDK_FUSION_PLATFORM_DIR
439
440droid_targets : blueprint_tools
441
442endif # dont_bother
443
444ifndef subdir_makefiles_total
445subdir_makefiles_total := $(words init post finish)
446endif
447
448$(info [$(call inc_and_print,subdir_makefiles_inc)/$(subdir_makefiles_total)] finishing build rules ...)
449
450# -------------------------------------------------------------------
451# All module makefiles have been included at this point.
452# -------------------------------------------------------------------
453
454# -------------------------------------------------------------------
455# Use basic warning/error messages now that LOCAL_MODULE_MAKEFILE
456# and LOCAL_MODULE aren't useful anymore.
457# -------------------------------------------------------------------
458define pretty-warning
459$(warning $(1))
460endef
461
462define pretty-error
463$(error $(1))
464endef
465
466# -------------------------------------------------------------------
467# Enforce to generate all RRO packages for modules having resource
468# overlays.
469# -------------------------------------------------------------------
470ifneq ($(PRODUCT_ENFORCE_RRO_TARGETS),)
471$(call generate_all_enforce_rro_packages)
472endif
473
474# -------------------------------------------------------------------
475# Fix up CUSTOM_MODULES to refer to installed files rather than
476# just bare module names.  Leave unknown modules alone in case
477# they're actually full paths to a particular file.
478known_custom_modules := $(filter $(ALL_MODULES),$(CUSTOM_MODULES))
479unknown_custom_modules := $(filter-out $(ALL_MODULES),$(CUSTOM_MODULES))
480CUSTOM_MODULES := \
481	$(call module-installed-files,$(known_custom_modules)) \
482	$(unknown_custom_modules)
483
484# -------------------------------------------------------------------
485# Define dependencies for modules that require other modules.
486# This can only happen now, after we've read in all module makefiles.
487#
488# TODO: deal with the fact that a bare module name isn't
489# unambiguous enough.  Maybe declare short targets like
490# APPS:Quake or HOST:SHARED_LIBRARIES:libutils.
491# BUG: the system image won't know to depend on modules that are
492# brought in as requirements of other modules.
493#
494# Resolve the required module name to 32-bit or 64-bit variant.
495# Get a list of corresponding 32-bit module names, if one exists.
496define get-32-bit-modules
497$(sort $(foreach m,$(1),\
498  $(if $(ALL_MODULES.$(m)$(TARGET_2ND_ARCH_MODULE_SUFFIX).CLASS),\
499    $(m)$(TARGET_2ND_ARCH_MODULE_SUFFIX))))
500endef
501# Get a list of corresponding 32-bit module names, if one exists;
502# otherwise return the original module name
503define get-32-bit-modules-if-we-can
504$(sort $(foreach m,$(1),\
505  $(if $(ALL_MODULES.$(m)$(TARGET_2ND_ARCH_MODULE_SUFFIX).CLASS),\
506    $(m)$(TARGET_2ND_ARCH_MODULE_SUFFIX), \
507    $(m))))
508endef
509
510# TODO: we can probably check to see if these modules are actually host
511# modules
512define get-host-32-bit-modules
513$(sort $(foreach m,$(1),\
514  $(if $(ALL_MODULES.$(m)$(HOST_2ND_ARCH_MODULE_SUFFIX).CLASS),\
515    $(m)$(HOST_2ND_ARCH_MODULE_SUFFIX))))
516endef
517# Get a list of corresponding 32-bit module names, if one exists;
518# otherwise return the original module name
519define get-host-32-bit-modules-if-we-can
520$(sort $(foreach m,$(1),\
521  $(if $(ALL_MODULES.$(m)$(HOST_2ND_ARCH_MODULE_SUFFIX).CLASS),\
522    $(m)$(HOST_2ND_ARCH_MODULE_SUFFIX),\
523    $(m))))
524endef
525
526# If a module is for a cross host os, the required modules must be for
527# that OS too.
528# If a module is built for 32-bit, the required modules must be 32-bit too;
529# Otherwise if the module is an executable or shared library,
530#   the required modules must be 64-bit;
531#   otherwise we require both 64-bit and 32-bit variant, if one exists.
532define target-select-bitness-of-required-modules
533$(foreach m,$(ALL_MODULES),\
534  $(eval r := $(ALL_MODULES.$(m).REQUIRED_FROM_TARGET))\
535  $(if $(r),\
536    $(if $(ALL_MODULES.$(m).FOR_2ND_ARCH),\
537      $(eval r_r := $(call get-32-bit-modules-if-we-can,$(r))),\
538      $(if $(filter EXECUTABLES SHARED_LIBRARIES NATIVE_TESTS,$(ALL_MODULES.$(m).CLASS)),\
539        $(eval r_r := $(r)),\
540        $(eval r_r := $(r) $(call get-32-bit-modules,$(r)))\
541       )\
542     )\
543     $(eval ALL_MODULES.$(m).REQUIRED_FROM_TARGET := $(strip $(r_r)))\
544  )\
545)
546endef
547$(call target-select-bitness-of-required-modules)
548
549define host-select-bitness-of-required-modules
550$(foreach m,$(ALL_MODULES),\
551  $(eval r := $(ALL_MODULES.$(m).REQUIRED_FROM_HOST))\
552  $(if $(r),\
553    $(if $(ALL_MODULES.$(m).FOR_2ND_ARCH),\
554      $(eval r_r := $(call get-host-32-bit-modules-if-we-can,$(r))),\
555      $(if $(filter EXECUTABLES SHARED_LIBRARIES NATIVE_TESTS,$(ALL_MODULES.$(m).CLASS)),\
556        $(eval r_r := $(r)),\
557        $(eval r_r := $(r) $(call get-host-32-bit-modules,$(r)))\
558       )\
559     )\
560     $(eval ALL_MODULES.$(m).REQUIRED_FROM_HOST := $(strip $(r_r)))\
561  )\
562)
563endef
564$(call host-select-bitness-of-required-modules)
565
566define host-cross-select-bitness-of-required-modules
567$(foreach m,$(ALL_MODULES),\
568  $(eval r := $(ALL_MODULES.$(m).REQUIRED_FROM_HOST_CROSS))\
569  $(if $(r),\
570    $(if $(ALL_MODULES.$(m).FOR_HOST_CROSS),,$(error Only expected REQUIRED_FROM_HOST_CROSS on FOR_HOST_CROSS modules - $(m)))\
571    $(eval r := $(addprefix host_cross_,$(r)))\
572    $(if $(ALL_MODULES.$(m).FOR_2ND_ARCH),\
573      $(eval r_r := $(call get-host-32-bit-modules-if-we-can,$(r))),\
574      $(if $(filter EXECUTABLES SHARED_LIBRARIES NATIVE_TESTS,$(ALL_MODULES.$(m).CLASS)),\
575        $(eval r_r := $(r)),\
576        $(eval r_r := $(r) $(call get-host-32-bit-modules,$(r)))\
577       )\
578     )\
579     $(eval ALL_MODULES.$(m).REQUIRED_FROM_HOST_CROSS := $(strip $(r_r)))\
580  )\
581)
582endef
583$(call host-cross-select-bitness-of-required-modules)
584r_r :=
585
586define add-required-deps
587$(1): | $(2)
588endef
589
590# Use a normal dependency instead of an order-only dependency when installing
591# host dynamic binaries so that the timestamp of the final binary always
592# changes, even if the toc optimization has skipped relinking the binary
593# and its dependant shared libraries.
594define add-required-host-so-deps
595$(1): $(2)
596endef
597
598# Sets up dependencies such that whenever a host module is installed,
599# any other host modules listed in $(ALL_MODULES.$(m).REQUIRED_FROM_HOST) will also be installed
600define add-all-host-to-host-required-modules-deps
601$(foreach m,$(ALL_MODULES), \
602  $(eval r := $(ALL_MODULES.$(m).REQUIRED_FROM_HOST)) \
603  $(if $(r), \
604    $(eval r := $(call module-installed-files,$(r))) \
605    $(eval h_m := $(filter $(HOST_OUT)/%, $(ALL_MODULES.$(m).INSTALLED))) \
606    $(eval h_r := $(filter $(HOST_OUT)/%, $(r))) \
607    $(eval h_m := $(filter-out $(h_r), $(h_m))) \
608    $(if $(h_m), $(eval $(call add-required-deps, $(h_m),$(h_r)))) \
609  ) \
610)
611endef
612$(call add-all-host-to-host-required-modules-deps)
613
614# Sets up dependencies such that whenever a host cross module is installed,
615# any other host cross modules listed in $(ALL_MODULES.$(m).REQUIRED_FROM_HOST_CROSS) will also be installed
616define add-all-host-cross-to-host-cross-required-modules-deps
617$(foreach m,$(ALL_MODULES), \
618  $(eval r := $(ALL_MODULES.$(m).REQUIRED_FROM_HOST_CROSS)) \
619  $(if $(r), \
620    $(eval r := $(call module-installed-files,$(r))) \
621    $(eval hc_m := $(filter $(HOST_CROSS_OUT)/%, $(ALL_MODULES.$(m).INSTALLED))) \
622    $(eval hc_r := $(filter $(HOST_CROSS_OUT)/%, $(r))) \
623    $(eval hc_m := $(filter-out $(hc_r), $(hc_m))) \
624    $(if $(hc_m), $(eval $(call add-required-deps, $(hc_m),$(hc_r)))) \
625  ) \
626)
627endef
628$(call add-all-host-cross-to-host-cross-required-modules-deps)
629
630# Sets up dependencies such that whenever a target module is installed,
631# any other target modules listed in $(ALL_MODULES.$(m).REQUIRED_FROM_TARGET) will also be installed
632define add-all-target-to-target-required-modules-deps
633$(foreach m,$(ALL_MODULES), \
634  $(eval r := $(ALL_MODULES.$(m).REQUIRED_FROM_TARGET)) \
635  $(if $(r), \
636    $(eval r := $(call module-installed-files,$(r))) \
637    $(eval t_m := $(filter $(TARGET_OUT_ROOT)/%, $(ALL_MODULES.$(m).INSTALLED))) \
638    $(eval t_r := $(filter $(TARGET_OUT_ROOT)/%, $(r))) \
639    $(eval t_m := $(filter-out $(t_r), $(t_m))) \
640    $(if $(t_m), $(eval $(call add-required-deps, $(t_m),$(t_r)))) \
641  ) \
642)
643endef
644$(call add-all-target-to-target-required-modules-deps)
645
646# Sets up dependencies such that whenever a host module is installed,
647# any target modules listed in $(ALL_MODULES.$(m).TARGET_REQUIRED_FROM_HOST) will also be installed
648define add-all-host-to-target-required-modules-deps
649$(foreach m,$(ALL_MODULES), \
650  $(eval req_mods := $(ALL_MODULES.$(m).TARGET_REQUIRED_FROM_HOST))\
651  $(if $(req_mods), \
652    $(eval req_files := )\
653    $(foreach req_mod,$(req_mods), \
654      $(eval req_file := $(filter $(TARGET_OUT_ROOT)/%, $(call module-installed-files,$(req_mod)))) \
655      $(if $(strip $(req_file)),\
656        ,\
657        $(error $(m).LOCAL_TARGET_REQUIRED_MODULES : illegal value $(req_mod) : not a device module. If you want to specify host modules to be required to be installed along with your host module, add those module names to LOCAL_REQUIRED_MODULES instead)\
658      )\
659      $(eval req_files := $(req_files)$(space)$(req_file))\
660    )\
661    $(eval req_files := $(strip $(req_files)))\
662    $(eval mod_files := $(filter $(HOST_OUT)/%, $(call module-installed-files,$(m)))) \
663    $(eval mod_files := $(filter-out $(req_files),$(mod_files)))\
664    $(if $(mod_files),\
665      $(eval $(call add-required-deps, $(mod_files),$(req_files))) \
666    )\
667  )\
668)
669endef
670$(call add-all-host-to-target-required-modules-deps)
671
672# Sets up dependencies such that whenever a target module is installed,
673# any host modules listed in $(ALL_MODULES.$(m).HOST_REQUIRED_FROM_TARGET) will also be installed
674define add-all-target-to-host-required-modules-deps
675$(foreach m,$(ALL_MODULES), \
676  $(eval req_mods := $(ALL_MODULES.$(m).HOST_REQUIRED_FROM_TARGET))\
677  $(if $(req_mods), \
678    $(eval req_files := )\
679    $(foreach req_mod,$(req_mods), \
680      $(eval req_file := $(filter $(HOST_OUT)/%, $(call module-installed-files,$(req_mod)))) \
681      $(if $(strip $(req_file)),\
682        ,\
683        $(error $(m).LOCAL_HOST_REQUIRED_MODULES : illegal value $(req_mod) : not a host module. If you want to specify target modules to be required to be installed along with your target module, add those module names to LOCAL_REQUIRED_MODULES instead)\
684      )\
685      $(eval req_files := $(req_files)$(space)$(req_file))\
686    )\
687    $(eval req_files := $(strip $(req_files)))\
688    $(eval mod_files := $(filter $(TARGET_OUT_ROOT)/%, $(call module-installed-files,$(m))))\
689    $(eval mod_files := $(filter-out $(req_files),$(mod_files)))\
690    $(if $(mod_files),\
691      $(eval $(call add-required-deps, $(mod_files),$(req_files))) \
692    )\
693  )\
694)
695endef
696$(call add-all-target-to-host-required-modules-deps)
697
698t_m :=
699h_m :=
700hc_m :=
701t_r :=
702h_r :=
703hc_r :=
704
705# Establish the dependencies on the shared libraries.
706# It also adds the shared library module names to ALL_MODULES.$(m).REQUIRED_FROM_(TARGET|HOST|HOST_CROSS),
707# so they can be expanded to product_MODULES later.
708# $(1): TARGET_ or HOST_ or HOST_CROSS_.
709# $(2): non-empty for 2nd arch.
710# $(3): non-empty for host cross compile.
711define resolve-shared-libs-depes
712$(foreach m,$($(if $(2),$($(1)2ND_ARCH_VAR_PREFIX))$(1)DEPENDENCIES_ON_SHARED_LIBRARIES),\
713  $(eval p := $(subst :,$(space),$(m)))\
714  $(eval mod := $(firstword $(p)))\
715  $(eval deps := $(subst $(comma),$(space),$(lastword $(p))))\
716  $(eval root := $(1)OUT$(if $(call streq,$(1),TARGET_),_ROOT))\
717  $(if $(2),$(eval deps := $(addsuffix $($(1)2ND_ARCH_MODULE_SUFFIX),$(deps))))\
718  $(if $(3),$(eval deps := $(addprefix host_cross_,$(deps))))\
719  $(eval r := $(filter $($(root))/%,$(call module-installed-files,\
720    $(deps))))\
721  $(if $(filter $(1),HOST_),\
722    $(eval ALL_MODULES.$(mod).HOST_SHARED_LIBRARY_FILES := $$(ALL_MODULES.$(mod).HOST_SHARED_LIBRARY_FILES) $(word 2,$(p)) $(r))\
723    $(eval ALL_MODULES.$(mod).HOST_SHARED_LIBRARIES := $$(ALL_MODULES.$(mod).HOST_SHARED_LIBRARIES) $(deps))\
724    $(eval $(call add-required-host-so-deps,$(word 2,$(p)),$(r))),\
725    $(eval $(call add-required-deps,$(word 2,$(p)),$(r))))\
726  $(eval ALL_MODULES.$(mod).REQUIRED_FROM_$(patsubst %_,%,$(1)) += $(deps)))
727endef
728
729# Recursively resolve host shared library dependency for a given module.
730# $(1): module name
731# Returns all dependencies of shared library.
732define get-all-shared-libs-deps
733$(if $(_all_deps_for_$(1)_set_),$(_all_deps_for_$(1)_),\
734  $(eval _all_deps_for_$(1)_ :=) \
735  $(foreach dep,$(ALL_MODULES.$(1).HOST_SHARED_LIBRARIES),\
736    $(foreach m,$(call get-all-shared-libs-deps,$(dep)),\
737      $(eval _all_deps_for_$(1)_ := $$(_all_deps_for_$(1)_) $(m))\
738      $(eval _all_deps_for_$(1)_ := $(sort $(_all_deps_for_$(1)_))))\
739    $(eval _all_deps_for_$(1)_ := $$(_all_deps_for_$(1)_) $(dep))\
740    $(eval _all_deps_for_$(1)_ := $(sort $(_all_deps_for_$(1)_) $(dep)))\
741    $(eval _all_deps_for_$(1)_set_ := true))\
742$(_all_deps_for_$(1)_))
743endef
744
745# Scan all modules in general-tests, device-tests and other selected suites and
746# flatten the shared library dependencies.
747define update-host-shared-libs-deps-for-suites
748$(foreach suite,general-tests device-tests vts,\
749  $(foreach m,$(COMPATIBILITY.$(suite).MODULES),\
750    $(eval my_deps := $(call get-all-shared-libs-deps,$(m)))\
751    $(foreach dep,$(my_deps),\
752      $(foreach f,$(ALL_MODULES.$(dep).HOST_SHARED_LIBRARY_FILES),\
753        $(if $(filter $(suite),device-tests general-tests),\
754          $(eval my_testcases := $(HOST_OUT_TESTCASES)),\
755          $(eval my_testcases := $$(COMPATIBILITY_TESTCASES_OUT_$(suite))))\
756        $(eval target := $(my_testcases)/$(lastword $(subst /, ,$(dir $(f))))/$(notdir $(f)))\
757        $(eval COMPATIBILITY.$(suite).HOST_SHARED_LIBRARY.FILES := \
758          $$(COMPATIBILITY.$(suite).HOST_SHARED_LIBRARY.FILES) $(f):$(target))\
759        $(eval COMPATIBILITY.$(suite).HOST_SHARED_LIBRARY.FILES := \
760          $(sort $(COMPATIBILITY.$(suite).HOST_SHARED_LIBRARY.FILES)))))))
761endef
762
763$(call resolve-shared-libs-depes,TARGET_)
764ifdef TARGET_2ND_ARCH
765$(call resolve-shared-libs-depes,TARGET_,true)
766endif
767$(call resolve-shared-libs-depes,HOST_)
768ifdef HOST_2ND_ARCH
769$(call resolve-shared-libs-depes,HOST_,true)
770endif
771# Update host side shared library dependencies for tests in suite device-tests and general-tests.
772# This should be called after calling resolve-shared-libs-depes for HOST_2ND_ARCH.
773$(call update-host-shared-libs-deps-for-suites)
774ifdef HOST_CROSS_OS
775$(call resolve-shared-libs-depes,HOST_CROSS_,,true)
776ifdef HOST_CROSS_2ND_ARCH
777$(call resolve-shared-libs-depes,HOST_CROSS_,true,true)
778endif
779endif
780
781# Pass the shared libraries dependencies to prebuilt ELF file check.
782define add-elf-file-check-shared-lib
783$(1): PRIVATE_SHARED_LIBRARY_FILES += $(2)
784$(1): $(2)
785endef
786
787define resolve-shared-libs-for-elf-file-check
788$(foreach m,$($(if $(2),$($(1)2ND_ARCH_VAR_PREFIX))$(1)DEPENDENCIES_ON_SHARED_LIBRARIES),\
789  $(eval p := $(subst :,$(space),$(m)))\
790  $(eval mod := $(firstword $(p)))\
791  \
792  $(eval deps := $(subst $(comma),$(space),$(lastword $(p))))\
793  $(if $(2),$(eval deps := $(addsuffix $($(1)2ND_ARCH_MODULE_SUFFIX),$(deps))))\
794  $(eval root := $(1)OUT$(if $(call streq,$(1),TARGET_),_ROOT))\
795  $(eval deps := $(filter $($(root))/%$($(1)SHLIB_SUFFIX),$(call module-built-files,$(deps))))\
796  \
797  $(eval r := $(firstword $(filter \
798    $($(if $(2),$($(1)2ND_ARCH_VAR_PREFIX))TARGET_OUT_INTERMEDIATES)/EXECUTABLES/%\
799    $($(if $(2),$($(1)2ND_ARCH_VAR_PREFIX))TARGET_OUT_INTERMEDIATES)/NATIVE_TESTS/%\
800    $($(if $(2),$($(1)2ND_ARCH_VAR_PREFIX))TARGET_OUT_INTERMEDIATES)/SHARED_LIBRARIES/%,\
801    $(call module-built-files,$(mod)))))\
802  \
803  $(if $(r),\
804    $(eval stamp := $(dir $(r))check_elf_files.timestamp)\
805    $(eval $(call add-elf-file-check-shared-lib,$(stamp),$(deps)))\
806  ))
807endef
808
809$(call resolve-shared-libs-for-elf-file-check,TARGET_)
810ifdef TARGET_2ND_ARCH
811$(call resolve-shared-libs-for-elf-file-check,TARGET_,true)
812endif
813
814m :=
815r :=
816p :=
817stamp :=
818deps :=
819add-required-deps :=
820
821################################################################################
822# Link type checking
823#
824# ALL_LINK_TYPES contains a list of all link type prefixes (generally one per
825# module, but APKs can "link" to both java and native code). The link type
826# prefix consists of all the information needed by intermediates-dir-for:
827#
828#  LINK_TYPE:TARGET:_:2ND:STATIC_LIBRARIES:libfoo
829#
830#   1: LINK_TYPE literal
831#   2: prefix
832#     - TARGET
833#     - HOST
834#     - HOST_CROSS
835#     - AUX-<variant-name>
836#   3: Whether to use the common intermediates directory or not
837#     - _
838#     - COMMON
839#   4: Whether it's the second arch or not
840#     - _
841#     - 2ND_
842#   5: Module Class
843#     - STATIC_LIBRARIES
844#     - SHARED_LIBRARIES
845#     - ...
846#   6: Module Name
847#
848# Then fields under that are separated by a period and the field name:
849#   - TYPE: the link types for this module
850#   - MAKEFILE: Where this module was defined
851#   - BUILT: The built module location
852#   - DEPS: the link type prefixes for the module's dependencies
853#   - ALLOWED: the link types to allow in this module's dependencies
854#   - WARN: the link types to warn about in this module's dependencies
855#
856# All of the dependency link types not listed in ALLOWED or WARN will become
857# errors.
858################################################################################
859
860link_type_error :=
861
862define link-type-prefix-base
863$(word 2,$(subst :,$(space),$(1)))
864endef
865define link-type-prefix
866$(if $(filter AUX-%,$(link-type-prefix-base)),$(patsubst AUX-%,AUX,$(link-type-prefix-base)),$(link-type-prefix-base))
867endef
868define link-type-aux-variant
869$(if $(filter AUX-%,$(link-type-prefix-base)),$(patsubst AUX-%,%,$(link-type-prefix-base)))
870endef
871define link-type-common
872$(patsubst _,,$(word 3,$(subst :,$(space),$(1))))
873endef
874define link-type-2ndarchprefix
875$(patsubst _,,$(word 4,$(subst :,$(space),$(1))))
876endef
877define link-type-class
878$(word 5,$(subst :,$(space),$(1)))
879endef
880define link-type-name
881$(word 6,$(subst :,$(space),$(1)))
882endef
883define link-type-os
884$(strip $(eval _p := $(link-type-prefix))\
885  $(if $(filter HOST HOST_CROSS,$(_p)),\
886    $($(_p)_OS),\
887    $(if $(filter AUX,$(_p)),AUX,android)))
888endef
889define link-type-arch
890$($(link-type-prefix)_$(link-type-2ndarchprefix)ARCH)
891endef
892define link-type-name-variant
893$(link-type-name) ($(link-type-class) $(link-type-os)-$(link-type-arch))
894endef
895
896# $(1): the prefix of the module doing the linking
897# $(2): the prefix of the linked module
898define link-type-warning
899$(shell $(call echo-warning,$($(1).MAKEFILE),"$(call link-type-name,$(1)) ($($(1).TYPE)) should not link against $(call link-type-name,$(2)) ($(3))"))
900endef
901
902# $(1): the prefix of the module doing the linking
903# $(2): the prefix of the linked module
904define link-type-error
905$(shell $(call echo-error,$($(1).MAKEFILE),"$(call link-type-name,$(1)) ($($(1).TYPE)) can not link against $(call link-type-name,$(2)) ($(3))"))\
906$(eval link_type_error := true)
907endef
908
909link-type-missing :=
910ifneq ($(ALLOW_MISSING_DEPENDENCIES),true)
911  # Print an error message if the linked-to module is missing
912  # $(1): the prefix of the module doing the linking
913  # $(2): the prefix of the missing module
914  define link-type-missing
915    $(shell $(call echo-error,$($(1).MAKEFILE),"$(call link-type-name-variant,$(1)) missing $(call link-type-name-variant,$(2))"))\
916    $(eval available_variants := $(filter %:$(call link-type-name,$(2)),$(ALL_LINK_TYPES)))\
917    $(if $(available_variants),\
918      $(info Available variants:)\
919      $(foreach v,$(available_variants),$(info $(space)$(space)$(call link-type-name-variant,$(v)))))\
920    $(info You can set ALLOW_MISSING_DEPENDENCIES=true in your environment if this is intentional, but that may defer real problems until later in the build.)\
921    $(eval link_type_error := true)
922  endef
923else
924  define link-type-missing
925    $(eval $$(1).MISSING := true)
926  endef
927endif
928
929# Verify that $(1) can link against $(2)
930# Both $(1) and $(2) are the link type prefix defined above
931define verify-link-type
932$(foreach t,$($(2).TYPE),\
933  $(if $(filter-out $($(1).ALLOWED),$(t)),\
934    $(if $(filter $(t),$($(1).WARN)),\
935      $(call link-type-warning,$(1),$(2),$(t)),\
936      $(call link-type-error,$(1),$(2),$(t)))))
937endef
938
939$(foreach lt,$(ALL_LINK_TYPES),\
940  $(foreach d,$($(lt).DEPS),\
941    $(if $($(d).TYPE),\
942      $(call verify-link-type,$(lt),$(d)),\
943      $(call link-type-missing,$(lt),$(d)))))
944
945ifdef link_type_error
946  $(error exiting from previous errors)
947endif
948
949# -------------------------------------------------------------------
950# Handle exported/imported includes
951
952# Recursively calculate flags
953$(foreach export,$(EXPORTS_LIST), \
954  $(eval EXPORTS.$$(export) = $$(EXPORTS.$(export).FLAGS) \
955    $(foreach dep,$(EXPORTS.$(export).REEXPORT),$$(EXPORTS.$(dep)))))
956
957# Recursively calculate dependencies
958$(foreach export,$(EXPORTS_LIST), \
959  $(eval EXPORT_DEPS.$$(export) = $$(EXPORTS.$(export).DEPS) \
960    $(foreach dep,$(EXPORTS.$(export).REEXPORT),$$(EXPORT_DEPS.$(dep)))))
961
962# Converts the recursive variables to simple variables so that we don't have to
963# evaluate them for every .o rule
964$(foreach export,$(EXPORTS_LIST),$(eval EXPORTS.$$(export) := $$(strip $$(EXPORTS.$$(export)))))
965$(foreach export,$(EXPORTS_LIST),$(eval EXPORT_DEPS.$$(export) := $$(sort $$(EXPORT_DEPS.$$(export)))))
966
967# Add dependencies
968$(foreach export,$(EXPORTS_LIST),$(eval $(call add-dependency,$$(EXPORTS.$$(export).USERS),$$(EXPORT_DEPS.$$(export)))))
969
970# -------------------------------------------------------------------
971# Figure out our module sets.
972#
973# Of the modules defined by the component makefiles,
974# determine what we actually want to build.
975
976
977# Expand a list of modules to the modules that they override (if any)
978# $(1): The list of modules.
979define module-overrides
980$(foreach m,$(1),$(PACKAGES.$(m).OVERRIDES) $(EXECUTABLES.$(m).OVERRIDES) $(SHARED_LIBRARIES.$(m).OVERRIDES) $(ETC.$(m).OVERRIDES))
981endef
982
983###########################################################
984## Expand a module name list with REQUIRED modules
985###########################################################
986# $(1): The variable name that holds the initial module name list.
987#       the variable will be modified to hold the expanded results.
988# $(2): The initial module name list.
989# $(3): The list of overridden modules.
990# Returns empty string (maybe with some whitespaces).
991define expand-required-modules
992$(eval _erm_req := $(foreach m,$(2),$(ALL_MODULES.$(m).REQUIRED_FROM_TARGET))) \
993$(eval _erm_new_modules := $(sort $(filter-out $($(1)),$(_erm_req)))) \
994$(eval _erm_new_overrides := $(call module-overrides,$(_erm_new_modules))) \
995$(eval _erm_all_overrides := $(3) $(_erm_new_overrides)) \
996$(eval _erm_new_modules := $(filter-out $(_erm_all_overrides), $(_erm_new_modules))) \
997$(eval $(1) := $(filter-out $(_erm_new_overrides),$($(1)))) \
998$(eval $(1) += $(_erm_new_modules)) \
999$(if $(_erm_new_modules),\
1000  $(call expand-required-modules,$(1),$(_erm_new_modules),$(_erm_all_overrides)))
1001endef
1002
1003# Same as expand-required-modules above, but does not handle module overrides, as
1004# we don't intend to support them on the host.
1005# $(1): The variable name that holds the initial module name list.
1006#       the variable will be modified to hold the expanded results.
1007# $(2): The initial module name list.
1008# $(3): HOST or HOST_CROSS depending on whether we're expanding host or host cross modules
1009# Returns empty string (maybe with some whitespaces).
1010define expand-required-host-modules
1011$(eval _erm_req := $(foreach m,$(2),$(ALL_MODULES.$(m).REQUIRED_FROM_$(3)))) \
1012$(eval _erm_new_modules := $(sort $(filter-out $($(1)),$(_erm_req)))) \
1013$(eval $(1) += $(_erm_new_modules)) \
1014$(if $(_erm_new_modules),\
1015  $(call expand-required-host-modules,$(1),$(_erm_new_modules),$(3)))
1016endef
1017
1018# Transforms paths relative to PRODUCT_OUT to absolute paths.
1019# $(1): list of relative paths
1020# $(2): optional suffix to append to paths
1021define resolve-product-relative-paths
1022  $(subst $(_vendor_path_placeholder),$(TARGET_COPY_OUT_VENDOR),\
1023    $(subst $(_product_path_placeholder),$(TARGET_COPY_OUT_PRODUCT),\
1024      $(subst $(_system_ext_path_placeholder),$(TARGET_COPY_OUT_SYSTEM_EXT),\
1025        $(subst $(_odm_path_placeholder),$(TARGET_COPY_OUT_ODM),\
1026          $(foreach p,$(1),$(call append-path,$(PRODUCT_OUT),$(p)$(2)))))))
1027endef
1028
1029# Returns modules included automatically as a result of certain BoardConfig
1030# variables being set.
1031define auto-included-modules
1032  $(if $(BOARD_VNDK_VERSION),vndk_package) \
1033  $(if $(DEVICE_MANIFEST_FILE),vendor_manifest.xml) \
1034  $(if $(DEVICE_MANIFEST_SKUS),$(foreach sku, $(DEVICE_MANIFEST_SKUS),vendor_manifest_$(sku).xml)) \
1035  $(if $(ODM_MANIFEST_FILES),odm_manifest.xml) \
1036  $(if $(ODM_MANIFEST_SKUS),$(foreach sku, $(ODM_MANIFEST_SKUS),odm_manifest_$(sku).xml)) \
1037
1038endef
1039
1040# Lists most of the files a particular product installs, including:
1041# - PRODUCT_PACKAGES, and their LOCAL_REQUIRED_MODULES
1042# - PRODUCT_COPY_FILES
1043# The base list of modules to build for this product is specified
1044# by the appropriate product definition file, which was included
1045# by product_config.mk.
1046# Name resolution for PRODUCT_PACKAGES:
1047#   foo:32 resolves to foo_32;
1048#   foo:64 resolves to foo;
1049#   foo resolves to both foo and foo_32 (if foo_32 is defined).
1050#
1051# Name resolution for LOCAL_REQUIRED_MODULES:
1052#   If a module is built for 2nd arch, its required module resolves to
1053#   32-bit variant, if it exits. See the select-bitness-of-required-modules definition.
1054# $(1): product makefile
1055define product-installed-files
1056  $(eval _pif_modules := \
1057    $(call get-product-var,$(1),PRODUCT_PACKAGES) \
1058    $(if $(filter eng,$(tags_to_install)),$(call get-product-var,$(1),PRODUCT_PACKAGES_ENG)) \
1059    $(if $(filter debug,$(tags_to_install)),$(call get-product-var,$(1),PRODUCT_PACKAGES_DEBUG)) \
1060    $(if $(filter tests,$(tags_to_install)),$(call get-product-var,$(1),PRODUCT_PACKAGES_TESTS)) \
1061    $(if $(filter asan,$(tags_to_install)),$(call get-product-var,$(1),PRODUCT_PACKAGES_DEBUG_ASAN)) \
1062    $(if $(filter java_coverage,$(tags_to_install)),$(call get-product-var,$(1),PRODUCT_PACKAGES_DEBUG_JAVA_COVERAGE)) \
1063    $(call auto-included-modules) \
1064  ) \
1065  $(eval ### Filter out the overridden packages and executables before doing expansion) \
1066  $(eval _pif_overrides := $(call module-overrides,$(_pif_modules))) \
1067  $(eval _pif_modules := $(filter-out $(_pif_overrides), $(_pif_modules))) \
1068  $(eval ### Resolve the :32 :64 module name) \
1069  $(eval _pif_modules_32 := $(patsubst %:32,%,$(filter %:32, $(_pif_modules)))) \
1070  $(eval _pif_modules_64 := $(patsubst %:64,%,$(filter %:64, $(_pif_modules)))) \
1071  $(eval _pif_modules_rest := $(filter-out %:32 %:64,$(_pif_modules))) \
1072  $(eval ### Note for 32-bit product, 32 and 64 will be added as their original module names.) \
1073  $(eval _pif_modules := $(call get-32-bit-modules-if-we-can, $(_pif_modules_32))) \
1074  $(eval _pif_modules += $(_pif_modules_64)) \
1075  $(eval ### For the rest we add both) \
1076  $(eval _pif_modules += $(call get-32-bit-modules, $(_pif_modules_rest))) \
1077  $(eval _pif_modules += $(_pif_modules_rest)) \
1078  $(call expand-required-modules,_pif_modules,$(_pif_modules),$(_pif_overrides)) \
1079  $(filter-out $(HOST_OUT_ROOT)/%,$(call module-installed-files, $(_pif_modules))) \
1080  $(call resolve-product-relative-paths,\
1081    $(foreach cf,$(call get-product-var,$(1),PRODUCT_COPY_FILES),$(call word-colon,2,$(cf))))
1082endef
1083
1084# Similar to product-installed-files above, but handles PRODUCT_HOST_PACKAGES instead
1085# This does support the :32 / :64 syntax, but does not support module overrides.
1086define host-installed-files
1087  $(eval _hif_modules := $(call get-product-var,$(1),PRODUCT_HOST_PACKAGES)) \
1088  $(eval ### Resolve the :32 :64 module name) \
1089  $(eval _hif_modules_32 := $(patsubst %:32,%,$(filter %:32, $(_hif_modules)))) \
1090  $(eval _hif_modules_64 := $(patsubst %:64,%,$(filter %:64, $(_hif_modules)))) \
1091  $(eval _hif_modules_rest := $(filter-out %:32 %:64,$(_hif_modules))) \
1092  $(eval _hif_modules := $(call get-host-32-bit-modules-if-we-can, $(_hif_modules_32))) \
1093  $(eval _hif_modules += $(_hif_modules_64)) \
1094  $(eval ### For the rest we add both) \
1095  $(eval _hif_modules += $(call get-host-32-bit-modules, $(_hif_modules_rest))) \
1096  $(eval _hif_modules += $(_hif_modules_rest)) \
1097  $(eval ### Split host vs host cross modules) \
1098  $(eval _hcif_modules := $(filter host_cross_%,$(_hif_modules))) \
1099  $(eval _hif_modules := $(filter-out host_cross_%,$(_hif_modules))) \
1100  $(call expand-required-host-modules,_hif_modules,$(_hif_modules),HOST) \
1101  $(call expand-required-host-modules,_hcif_modules,$(_hcif_modules),HOST_CROSS) \
1102  $(filter $(HOST_OUT)/%,$(call module-installed-files, $(_hif_modules))) \
1103  $(filter $(HOST_CROSS_OUT)/%,$(call module-installed-files, $(_hcif_modules)))
1104endef
1105
1106# Fails the build if the given list is non-empty, and prints it entries (stripping PRODUCT_OUT).
1107# $(1): list of files to print
1108# $(2): heading to print on failure
1109define maybe-print-list-and-error
1110$(if $(strip $(1)), \
1111  $(warning $(2)) \
1112  $(info Offending entries:) \
1113  $(foreach e,$(sort $(1)),$(info    $(patsubst $(PRODUCT_OUT)/%,%,$(e)))) \
1114  $(error Build failed) \
1115)
1116endef
1117
1118ifdef FULL_BUILD
1119  ifneq (true,$(ALLOW_MISSING_DEPENDENCIES))
1120    # Check to ensure that all modules in PRODUCT_PACKAGES exist (opt in per product)
1121    ifeq (true,$(PRODUCT_ENFORCE_PACKAGES_EXIST))
1122      _allow_list := $(PRODUCT_ENFORCE_PACKAGES_EXIST_ALLOW_LIST)
1123      _modules := $(PRODUCT_PACKAGES)
1124      # Strip :32 and :64 suffixes
1125      _modules := $(patsubst %:32,%,$(_modules))
1126      _modules := $(patsubst %:64,%,$(_modules))
1127      # Sanity check all modules in PRODUCT_PACKAGES exist. We check for the
1128      # existence if either <module> or the <module>_32 variant.
1129      _nonexistent_modules := $(filter-out $(ALL_MODULES),$(_modules))
1130      _nonexistent_modules := $(foreach m,$(_nonexistent_modules),\
1131        $(if $(call get-32-bit-modules,$(m)),,$(m)))
1132      $(call maybe-print-list-and-error,$(filter-out $(_allow_list),$(_nonexistent_modules)),\
1133        $(INTERNAL_PRODUCT) includes non-existent modules in PRODUCT_PACKAGES)
1134      $(call maybe-print-list-and-error,$(filter-out $(_nonexistent_modules),$(_allow_list)),\
1135        $(INTERNAL_PRODUCT) includes redundant allow list entries for non-existent PRODUCT_PACKAGES)
1136    endif
1137
1138    # Check to ensure that all modules in PRODUCT_HOST_PACKAGES exist
1139    #
1140    # Many host modules are Linux-only, so skip this check on Mac. If we ever have Mac-only modules,
1141    # maybe it would make sense to have PRODUCT_HOST_PACKAGES_LINUX/_DARWIN?
1142    ifneq ($(HOST_OS),darwin)
1143      _modules := $(PRODUCT_HOST_PACKAGES)
1144      # Strip :32 and :64 suffixes
1145      _modules := $(patsubst %:32,%,$(_modules))
1146      _modules := $(patsubst %:64,%,$(_modules))
1147      _nonexistent_modules := $(foreach m,$(_modules),\
1148        $(if $(ALL_MODULES.$(m).REQUIRED_FROM_HOST)$(filter $(HOST_OUT_ROOT)/%,$(ALL_MODULES.$(m).INSTALLED)),,$(m)))
1149      $(call maybe-print-list-and-error,$(_nonexistent_modules),\
1150        $(INTERNAL_PRODUCT) includes non-existent modules in PRODUCT_HOST_PACKAGES)
1151    endif
1152  endif
1153
1154  # Some modules produce only host installed files when building with TARGET_BUILD_APPS
1155  ifeq ($(TARGET_BUILD_APPS),)
1156    _modules := $(foreach m,$(PRODUCT_PACKAGES) \
1157                            $(PRODUCT_PACKAGES_DEBUG) \
1158                            $(PRODUCT_PACKAGES_DEBUG_ASAN) \
1159                            $(PRODUCT_PACKAGES_ENG) \
1160                            $(PRODUCT_PACKAGES_TESTS),\
1161                  $(if $(ALL_MODULES.$(m).INSTALLED),\
1162                    $(if $(filter-out $(HOST_OUT_ROOT)/%,$(ALL_MODULES.$(m).INSTALLED)),,\
1163                      $(m))))
1164    $(call maybe-print-list-and-error,$(sort $(_modules)),\
1165      Host modules should be in PRODUCT_HOST_PACKAGES$(comma) not PRODUCT_PACKAGES)
1166  endif
1167
1168  product_host_FILES := $(call host-installed-files,$(INTERNAL_PRODUCT))
1169  product_target_FILES := $(call product-installed-files, $(INTERNAL_PRODUCT))
1170  # WARNING: The product_MODULES variable is depended on by external files.
1171  product_MODULES := $(_pif_modules)
1172
1173  # Verify the artifact path requirements made by included products.
1174  is_asan := $(if $(filter address,$(SANITIZE_TARGET)),true)
1175  ifneq (true,$(or $(is_asan),$(DISABLE_ARTIFACT_PATH_REQUIREMENTS)))
1176  # Fakes don't get installed, and NDK stubs aren't installed to device.
1177  static_allowed_patterns := $(TARGET_OUT_FAKE)/% $(SOONG_OUT_DIR)/ndk/%
1178  # RROs become REQUIRED by the source module, but are always placed on the vendor partition.
1179  static_allowed_patterns += %__auto_generated_rro_product.apk
1180  static_allowed_patterns += %__auto_generated_rro_vendor.apk
1181  # Auto-included targets are not considered
1182  static_allowed_patterns += $(call product-installed-files,)
1183  # $(PRODUCT_OUT)/apex is where shared libraries in APEXes get installed.
1184  # The path can be considered as a fake path, as the shared libraries
1185  # are installed there just to have symbols files for them under
1186  # $(PRODUCT_OUT)/symbols/apex for debugging purpose. The /apex directory
1187  # is never compiled into a filesystem image.
1188  static_allowed_patterns += $(PRODUCT_OUT)/apex/%
1189  ifeq (true,$(BOARD_USES_SYSTEM_OTHER_ODEX))
1190    # Allow system_other odex space optimization.
1191    static_allowed_patterns += \
1192      $(TARGET_OUT_SYSTEM_OTHER)/%.odex \
1193      $(TARGET_OUT_SYSTEM_OTHER)/%.vdex \
1194      $(TARGET_OUT_SYSTEM_OTHER)/%.art
1195  endif
1196
1197CERTIFICATE_VIOLATION_MODULES_FILENAME := $(PRODUCT_OUT)/certificate_violation_modules.txt
1198$(CERTIFICATE_VIOLATION_MODULES_FILENAME):
1199	rm -f $@
1200	$(foreach m,$(sort $(CERTIFICATE_VIOLATION_MODULES)), echo $(m) >> $@;)
1201$(call dist-for-goals,droidcore,$(CERTIFICATE_VIOLATION_MODULES_FILENAME))
1202
1203  all_offending_files :=
1204  $(foreach makefile,$(ARTIFACT_PATH_REQUIREMENT_PRODUCTS),\
1205    $(eval requirements := $(PRODUCTS.$(makefile).ARTIFACT_PATH_REQUIREMENTS)) \
1206    $(eval ### Verify that the product only produces files inside its path requirements.) \
1207    $(eval allowed := $(PRODUCTS.$(makefile).ARTIFACT_PATH_ALLOWED_LIST)) \
1208    $(eval path_patterns := $(call resolve-product-relative-paths,$(requirements),%)) \
1209    $(eval allowed_patterns := $(call resolve-product-relative-paths,$(allowed))) \
1210    $(eval files := $(call product-installed-files, $(makefile))) \
1211    $(eval offending_files := $(filter-out $(path_patterns) $(allowed_patterns) $(static_allowed_patterns),$(files))) \
1212    $(call maybe-print-list-and-error,$(offending_files),\
1213      $(makefile) produces files outside its artifact path requirement. \
1214      Allowed paths are $(subst $(space),$(comma)$(space),$(addsuffix *,$(requirements)))) \
1215    $(eval unused_allowed := $(filter-out $(files),$(allowed_patterns))) \
1216    $(call maybe-print-list-and-error,$(unused_allowed),$(makefile) includes redundant allowed entries in its artifact path requirement.) \
1217    $(eval ### Optionally verify that nothing else produces files inside this artifact path requirement.) \
1218    $(eval extra_files := $(filter-out $(files) $(HOST_OUT)/%,$(product_target_FILES))) \
1219    $(eval files_in_requirement := $(filter $(path_patterns),$(extra_files))) \
1220    $(eval all_offending_files += $(files_in_requirement)) \
1221    $(eval allowed := $(PRODUCT_ARTIFACT_PATH_REQUIREMENT_ALLOWED_LIST)) \
1222    $(eval allowed_patterns := $(call resolve-product-relative-paths,$(allowed))) \
1223    $(eval offending_files := $(filter-out $(allowed_patterns),$(files_in_requirement))) \
1224    $(eval enforcement := $(PRODUCT_ENFORCE_ARTIFACT_PATH_REQUIREMENTS)) \
1225    $(if $(enforcement),\
1226      $(call maybe-print-list-and-error,$(offending_files),\
1227        $(INTERNAL_PRODUCT) produces files inside $(makefile)s artifact path requirement. \
1228        $(PRODUCT_ARTIFACT_PATH_REQUIREMENT_HINT)) \
1229      $(eval unused_allowed := $(if $(filter true strict,$(enforcement)),\
1230        $(foreach p,$(allowed_patterns),$(if $(filter $(p),$(extra_files)),,$(p))))) \
1231      $(call maybe-print-list-and-error,$(unused_allowed),$(INTERNAL_PRODUCT) includes redundant artifact path requirement allowed list entries.) \
1232    ) \
1233  )
1234$(PRODUCT_OUT)/offending_artifacts.txt:
1235	rm -f $@
1236	$(foreach f,$(sort $(all_offending_files)),echo $(f) >> $@;)
1237  endif
1238else
1239  # We're not doing a full build, and are probably only including
1240  # a subset of the module makefiles.  Don't try to build any modules
1241  # requested by the product, because we probably won't have rules
1242  # to build them.
1243  product_target_FILES :=
1244  product_host_FILES :=
1245endif
1246
1247# TODO: Remove the 3 places in the tree that use ALL_DEFAULT_INSTALLED_MODULES
1248# and get rid of it from this list.
1249modules_to_install := $(sort \
1250    $(ALL_DEFAULT_INSTALLED_MODULES) \
1251    $(product_target_FILES) \
1252    $(product_host_FILES) \
1253    $(CUSTOM_MODULES) \
1254  )
1255
1256ifdef FULL_BUILD
1257#
1258# Used by the cleanup logic in soong_ui to remove files that should no longer
1259# be installed.
1260#
1261
1262# Include all tests, so that we remove them from the test suites / testcase
1263# folders when they are removed.
1264test_files := $(foreach ts,$(ALL_COMPATIBILITY_SUITES),$(COMPATIBILITY.$(ts).FILES))
1265
1266$(shell mkdir -p $(PRODUCT_OUT) $(HOST_OUT))
1267
1268$(file >$(PRODUCT_OUT)/.installable_files$(if $(filter address,$(SANITIZE_TARGET)),_asan), \
1269  $(sort $(patsubst $(PRODUCT_OUT)/%,%,$(filter $(PRODUCT_OUT)/%, \
1270    $(modules_to_install) $(test_files)))))
1271
1272$(file >$(HOST_OUT)/.installable_test_files,$(sort \
1273  $(patsubst $(HOST_OUT)/%,%,$(filter $(HOST_OUT)/%, \
1274    $(test_files)))))
1275
1276test_files :=
1277endif
1278
1279
1280# Don't include any GNU General Public License shared objects or static
1281# libraries in SDK images.  GPL executables (not static/dynamic libraries)
1282# are okay if they don't link against any closed source libraries (directly
1283# or indirectly)
1284
1285# It's ok (and necessary) to build the host tools, but nothing that's
1286# going to be installed on the target (including static libraries).
1287
1288ifdef is_sdk_build
1289  target_gnu_MODULES := \
1290              $(filter \
1291                      $(TARGET_OUT_INTERMEDIATES)/% \
1292                      $(TARGET_OUT)/% \
1293                      $(TARGET_OUT_DATA)/%, \
1294                              $(sort $(call get-tagged-modules,gnu)))
1295  target_gnu_MODULES := $(filter-out $(TARGET_OUT_EXECUTABLES)/%,$(target_gnu_MODULES))
1296  target_gnu_MODULES := $(filter-out %/libopenjdkjvmti.so,$(target_gnu_MODULES))
1297  target_gnu_MODULES := $(filter-out %/libopenjdkjvmtid.so,$(target_gnu_MODULES))
1298  $(info Removing from sdk:)$(foreach d,$(target_gnu_MODULES),$(info : $(d)))
1299  modules_to_install := \
1300              $(filter-out $(target_gnu_MODULES),$(modules_to_install))
1301
1302  # Ensure every module listed in PRODUCT_PACKAGES* gets something installed
1303  # TODO: Should we do this for all builds and not just the sdk?
1304  dangling_modules :=
1305  $(foreach m, $(PRODUCT_PACKAGES), \
1306    $(if $(strip $(ALL_MODULES.$(m).INSTALLED) $(ALL_MODULES.$(m)$(TARGET_2ND_ARCH_MODULE_SUFFIX).INSTALLED)),,\
1307      $(eval dangling_modules += $(m))))
1308  ifneq ($(dangling_modules),)
1309    $(warning: Modules '$(dangling_modules)' in PRODUCT_PACKAGES have nothing to install!)
1310  endif
1311  $(foreach m, $(PRODUCT_PACKAGES_DEBUG), \
1312    $(if $(strip $(ALL_MODULES.$(m).INSTALLED)),,\
1313      $(warning $(ALL_MODULES.$(m).MAKEFILE): Module '$(m)' in PRODUCT_PACKAGES_DEBUG has nothing to install!)))
1314  $(foreach m, $(PRODUCT_PACKAGES_ENG), \
1315    $(if $(strip $(ALL_MODULES.$(m).INSTALLED)),,\
1316      $(warning $(ALL_MODULES.$(m).MAKEFILE): Module '$(m)' in PRODUCT_PACKAGES_ENG has nothing to install!)))
1317  $(foreach m, $(PRODUCT_PACKAGES_TESTS), \
1318    $(if $(strip $(ALL_MODULES.$(m).INSTALLED)),,\
1319      $(warning $(ALL_MODULES.$(m).MAKEFILE): Module '$(m)' in PRODUCT_PACKAGES_TESTS has nothing to install!)))
1320endif
1321
1322# build/make/core/Makefile contains extra stuff that we don't want to pollute this
1323# top-level makefile with.  It expects that ALL_DEFAULT_INSTALLED_MODULES
1324# contains everything that's built during the current make, but it also further
1325# extends ALL_DEFAULT_INSTALLED_MODULES.
1326ALL_DEFAULT_INSTALLED_MODULES := $(modules_to_install)
1327include $(BUILD_SYSTEM)/Makefile
1328modules_to_install := $(sort $(ALL_DEFAULT_INSTALLED_MODULES))
1329ALL_DEFAULT_INSTALLED_MODULES :=
1330
1331
1332# These are additional goals that we build, in order to make sure that there
1333# is as little code as possible in the tree that doesn't build.
1334modules_to_check := $(foreach m,$(ALL_MODULES),$(ALL_MODULES.$(m).CHECKED))
1335
1336# If you would like to build all goals, and not skip any intermediate
1337# steps, you can pass the "all" modifier goal on the commandline.
1338ifneq ($(filter all,$(MAKECMDGOALS)),)
1339modules_to_check += $(foreach m,$(ALL_MODULES),$(ALL_MODULES.$(m).BUILT))
1340endif
1341
1342# Build docs as part of checkbuild to catch more breakages.
1343modules_to_check += $(ALL_DOCS)
1344
1345# for easier debugging
1346modules_to_check := $(sort $(modules_to_check))
1347#$(error modules_to_check $(modules_to_check))
1348
1349# -------------------------------------------------------------------
1350# This is used to to get the ordering right, you can also use these,
1351# but they're considered undocumented, so don't complain if their
1352# behavior changes.
1353# An internal target that depends on all copied headers
1354# (see copy_headers.make).  Other targets that need the
1355# headers to be copied first can depend on this target.
1356.PHONY: all_copied_headers
1357all_copied_headers: ;
1358
1359$(ALL_C_CPP_ETC_OBJECTS): | all_copied_headers
1360
1361# All the droid stuff, in directories
1362.PHONY: files
1363files: $(modules_to_install) \
1364       $(INSTALLED_ANDROID_INFO_TXT_TARGET)
1365
1366# -------------------------------------------------------------------
1367
1368.PHONY: checkbuild
1369checkbuild: $(modules_to_check) droid_targets check-elf-files
1370
1371ifeq (true,$(ANDROID_BUILD_EVERYTHING_BY_DEFAULT))
1372droid: checkbuild
1373endif
1374
1375.PHONY: ramdisk
1376ramdisk: $(INSTALLED_RAMDISK_TARGET)
1377
1378.PHONY: ramdisk_debug
1379ramdisk_debug: $(INSTALLED_DEBUG_RAMDISK_TARGET)
1380
1381.PHONY: ramdisk_test_harness
1382ramdisk_test_harness: $(INSTALLED_TEST_HARNESS_RAMDISK_TARGET)
1383
1384.PHONY: vendor_ramdisk_debug
1385vendor_ramdisk_debug: $(INSTALLED_VENDOR_DEBUG_RAMDISK_TARGET)
1386
1387.PHONY: userdataimage
1388userdataimage: $(INSTALLED_USERDATAIMAGE_TARGET)
1389
1390ifneq (,$(filter userdataimage, $(MAKECMDGOALS)))
1391$(call dist-for-goals, userdataimage, $(BUILT_USERDATAIMAGE_TARGET))
1392endif
1393
1394.PHONY: cacheimage
1395cacheimage: $(INSTALLED_CACHEIMAGE_TARGET)
1396
1397.PHONY: bptimage
1398bptimage: $(INSTALLED_BPTIMAGE_TARGET)
1399
1400.PHONY: vendorimage
1401vendorimage: $(INSTALLED_VENDORIMAGE_TARGET)
1402
1403.PHONY: vendorbootimage
1404vendorbootimage: $(INSTALLED_VENDOR_BOOTIMAGE_TARGET)
1405
1406.PHONY: vendorbootimage_debug
1407vendorbootimage_debug: $(INSTALLED_VENDOR_DEBUG_BOOTIMAGE_TARGET)
1408
1409.PHONY: productimage
1410productimage: $(INSTALLED_PRODUCTIMAGE_TARGET)
1411
1412.PHONY: systemextimage
1413systemextimage: $(INSTALLED_SYSTEM_EXTIMAGE_TARGET)
1414
1415.PHONY: odmimage
1416odmimage: $(INSTALLED_ODMIMAGE_TARGET)
1417
1418.PHONY: systemotherimage
1419systemotherimage: $(INSTALLED_SYSTEMOTHERIMAGE_TARGET)
1420
1421.PHONY: superimage_empty
1422superimage_empty: $(INSTALLED_SUPERIMAGE_EMPTY_TARGET)
1423
1424.PHONY: bootimage
1425bootimage: $(INSTALLED_BOOTIMAGE_TARGET)
1426
1427.PHONY: bootimage_debug
1428bootimage_debug: $(INSTALLED_DEBUG_BOOTIMAGE_TARGET)
1429
1430.PHONY: bootimage_test_harness
1431bootimage_test_harness: $(INSTALLED_TEST_HARNESS_BOOTIMAGE_TARGET)
1432
1433.PHONY: vbmetaimage
1434vbmetaimage: $(INSTALLED_VBMETAIMAGE_TARGET)
1435
1436.PHONY: auxiliary
1437auxiliary: $(INSTALLED_AUX_TARGETS)
1438
1439# Build files and then package it into the rom formats
1440.PHONY: droidcore
1441droidcore: $(filter $(HOST_OUT_ROOT)/%,$(modules_to_install)) \
1442    $(INSTALLED_SYSTEMIMAGE_TARGET) \
1443    $(INSTALLED_RAMDISK_TARGET) \
1444    $(INSTALLED_BOOTIMAGE_TARGET) \
1445    $(INSTALLED_RADIOIMAGE_TARGET) \
1446    $(INSTALLED_DEBUG_RAMDISK_TARGET) \
1447    $(INSTALLED_DEBUG_BOOTIMAGE_TARGET) \
1448    $(INSTALLED_RECOVERYIMAGE_TARGET) \
1449    $(INSTALLED_VBMETAIMAGE_TARGET) \
1450    $(INSTALLED_USERDATAIMAGE_TARGET) \
1451    $(INSTALLED_CACHEIMAGE_TARGET) \
1452    $(INSTALLED_BPTIMAGE_TARGET) \
1453    $(INSTALLED_VENDORIMAGE_TARGET) \
1454    $(INSTALLED_VENDOR_BOOTIMAGE_TARGET) \
1455    $(INSTALLED_VENDOR_DEBUG_RAMDISK_TARGET) \
1456    $(INSTALLED_VENDOR_DEBUG_BOOTIMAGE_TARGET) \
1457    $(INSTALLED_ODMIMAGE_TARGET) \
1458    $(INSTALLED_SUPERIMAGE_EMPTY_TARGET) \
1459    $(INSTALLED_PRODUCTIMAGE_TARGET) \
1460    $(INSTALLED_SYSTEMOTHERIMAGE_TARGET) \
1461    $(INSTALLED_FILES_FILE) \
1462    $(INSTALLED_FILES_JSON) \
1463    $(INSTALLED_FILES_FILE_VENDOR) \
1464    $(INSTALLED_FILES_JSON_VENDOR) \
1465    $(INSTALLED_FILES_FILE_ODM) \
1466    $(INSTALLED_FILES_JSON_ODM) \
1467    $(INSTALLED_FILES_FILE_PRODUCT) \
1468    $(INSTALLED_FILES_JSON_PRODUCT) \
1469    $(INSTALLED_FILES_FILE_SYSTEM_EXT) \
1470    $(INSTALLED_FILES_JSON_SYSTEM_EXT) \
1471    $(INSTALLED_FILES_FILE_SYSTEMOTHER) \
1472    $(INSTALLED_FILES_JSON_SYSTEMOTHER) \
1473    $(INSTALLED_FILES_FILE_RAMDISK) \
1474    $(INSTALLED_FILES_JSON_RAMDISK) \
1475    $(INSTALLED_FILES_FILE_DEBUG_RAMDISK) \
1476    $(INSTALLED_FILES_JSON_DEBUG_RAMDISK) \
1477    $(INSTALLED_FILES_FILE_VENDOR_DEBUG_RAMDISK) \
1478    $(INSTALLED_FILES_JSON_VENDOR_DEBUG_RAMDISK) \
1479    $(INSTALLED_FILES_FILE_ROOT) \
1480    $(INSTALLED_FILES_JSON_ROOT) \
1481    $(INSTALLED_FILES_FILE_RECOVERY) \
1482    $(INSTALLED_FILES_JSON_RECOVERY) \
1483    $(INSTALLED_ANDROID_INFO_TXT_TARGET) \
1484    auxiliary \
1485    soong_docs
1486
1487# dist_files only for putting your library into the dist directory with a full build.
1488.PHONY: dist_files
1489
1490.PHONY: apps_only
1491ifneq ($(TARGET_BUILD_APPS),)
1492  # If this build is just for apps, only build apps and not the full system by default.
1493
1494  unbundled_build_modules :=
1495  ifneq ($(filter all,$(TARGET_BUILD_APPS)),)
1496    # If they used the magic goal "all" then build all apps in the source tree.
1497    unbundled_build_modules := $(foreach m,$(sort $(ALL_MODULES)),$(if $(filter APPS,$(ALL_MODULES.$(m).CLASS)),$(m)))
1498  else
1499    unbundled_build_modules := $(TARGET_BUILD_APPS)
1500  endif
1501
1502  # Dist the installed files if they exist.
1503  apps_only_installed_files := $(foreach m,$(unbundled_build_modules),$(ALL_MODULES.$(m).INSTALLED))
1504  $(call dist-for-goals,apps_only, $(apps_only_installed_files))
1505
1506  # Dist the bundle files if they exist.
1507  apps_only_bundle_files := $(foreach m,$(unbundled_build_modules),\
1508    $(if $(ALL_MODULES.$(m).BUNDLE),$(ALL_MODULES.$(m).BUNDLE):$(m)-base.zip))
1509  $(call dist-for-goals,apps_only, $(apps_only_bundle_files))
1510
1511  # Dist the lint reports if they exist.
1512  apps_only_lint_report_files := $(foreach m,$(unbundled_build_modules),\
1513    $(foreach report,$(ALL_MODULES.$(m).LINT_REPORTS),\
1514      $(report):$(m)-$(notdir $(report))))
1515  .PHONY: lint-check
1516  lint-check: $(foreach f, $(apps_only_lint_report_files), $(call word-colon,1,$(f)))
1517  $(call dist-for-goals,lint-check, $(apps_only_lint_report_files))
1518
1519  # For uninstallable modules such as static Java library, we have to dist the built file,
1520  # as <module_name>.<suffix>
1521  apps_only_dist_built_files := $(foreach m,$(unbundled_build_modules),$(if $(ALL_MODULES.$(m).INSTALLED),,\
1522      $(if $(ALL_MODULES.$(m).BUILT),$(ALL_MODULES.$(m).BUILT):$(m)$(suffix $(ALL_MODULES.$(m).BUILT)))\
1523      $(if $(ALL_MODULES.$(m).AAR),$(ALL_MODULES.$(m).AAR):$(m).aar)\
1524      ))
1525  $(call dist-for-goals,apps_only, $(apps_only_dist_built_files))
1526
1527  ifeq ($(EMMA_INSTRUMENT),true)
1528    $(JACOCO_REPORT_CLASSES_ALL) : $(apps_only_installed_files)
1529    $(call dist-for-goals,apps_only, $(JACOCO_REPORT_CLASSES_ALL))
1530  endif
1531
1532  $(PROGUARD_DICT_ZIP) : $(apps_only_installed_files)
1533  $(call dist-for-goals,apps_only, $(PROGUARD_DICT_ZIP))
1534
1535  $(SYMBOLS_ZIP) : $(apps_only_installed_files)
1536  $(call dist-for-goals,apps_only, $(SYMBOLS_ZIP))
1537
1538  $(COVERAGE_ZIP) : $(apps_only_installed_files)
1539  $(call dist-for-goals,apps_only, $(COVERAGE_ZIP))
1540
1541apps_only: $(unbundled_build_modules)
1542
1543droid_targets: apps_only
1544
1545# Combine the NOTICE files for a apps_only build
1546$(eval $(call combine-notice-files, html, \
1547    $(target_notice_file_txt), \
1548    $(target_notice_file_html_or_xml), \
1549    "Notices for files for apps:", \
1550    $(TARGET_OUT_NOTICE_FILES), \
1551    $(apps_only_installed_files)))
1552
1553
1554else # TARGET_BUILD_APPS
1555  $(call dist-for-goals, droidcore, \
1556    $(INTERNAL_UPDATE_PACKAGE_TARGET) \
1557    $(INTERNAL_OTA_PACKAGE_TARGET) \
1558    $(INTERNAL_OTA_METADATA) \
1559    $(INTERNAL_OTA_RETROFIT_DYNAMIC_PARTITIONS_PACKAGE_TARGET) \
1560    $(BUILT_OTATOOLS_PACKAGE) \
1561    $(SYMBOLS_ZIP) \
1562    $(PROGUARD_DICT_ZIP) \
1563    $(COVERAGE_ZIP) \
1564    $(APPCOMPAT_ZIP) \
1565    $(INSTALLED_FILES_FILE) \
1566    $(INSTALLED_FILES_JSON) \
1567    $(INSTALLED_FILES_FILE_VENDOR) \
1568    $(INSTALLED_FILES_JSON_VENDOR) \
1569    $(INSTALLED_FILES_FILE_ODM) \
1570    $(INSTALLED_FILES_JSON_ODM) \
1571    $(INSTALLED_FILES_FILE_PRODUCT) \
1572    $(INSTALLED_FILES_JSON_PRODUCT) \
1573    $(INSTALLED_FILES_FILE_SYSTEM_EXT) \
1574    $(INSTALLED_FILES_JSON_SYSTEM_EXT) \
1575    $(INSTALLED_FILES_FILE_SYSTEMOTHER) \
1576    $(INSTALLED_FILES_JSON_SYSTEMOTHER) \
1577    $(INSTALLED_FILES_FILE_RECOVERY) \
1578    $(INSTALLED_FILES_JSON_RECOVERY) \
1579    $(INSTALLED_BUILD_PROP_TARGET) \
1580    $(BUILT_TARGET_FILES_PACKAGE) \
1581    $(INSTALLED_ANDROID_INFO_TXT_TARGET) \
1582    $(INSTALLED_MISC_INFO_TARGET) \
1583    $(INSTALLED_RAMDISK_TARGET) \
1584   )
1585
1586  # Put a copy of the radio/bootloader files in the dist dir.
1587  $(foreach f,$(INSTALLED_RADIOIMAGE_TARGET), \
1588    $(call dist-for-goals, droidcore, $(f)))
1589
1590  ifneq ($(ANDROID_BUILD_EMBEDDED),true)
1591  ifneq ($(TARGET_BUILD_PDK),true)
1592    $(call dist-for-goals, droidcore, \
1593      $(APPS_ZIP) \
1594      $(INTERNAL_EMULATOR_PACKAGE_TARGET) \
1595    )
1596  endif
1597  endif
1598
1599  $(call dist-for-goals, droidcore, \
1600    $(INSTALLED_FILES_FILE_ROOT) \
1601    $(INSTALLED_FILES_JSON_ROOT) \
1602  )
1603
1604  ifneq ($(BOARD_BUILD_SYSTEM_ROOT_IMAGE),true)
1605    $(call dist-for-goals, droidcore, \
1606      $(INSTALLED_FILES_FILE_RAMDISK) \
1607      $(INSTALLED_FILES_JSON_RAMDISK) \
1608      $(INSTALLED_FILES_FILE_DEBUG_RAMDISK) \
1609      $(INSTALLED_FILES_JSON_DEBUG_RAMDISK) \
1610      $(INSTALLED_FILES_FILE_VENDOR_DEBUG_RAMDISK) \
1611      $(INSTALLED_FILES_JSON_VENDOR_DEBUG_RAMDISK) \
1612      $(INSTALLED_DEBUG_RAMDISK_TARGET) \
1613      $(INSTALLED_DEBUG_BOOTIMAGE_TARGET) \
1614      $(INSTALLED_VENDOR_DEBUG_RAMDISK_TARGET) \
1615      $(INSTALLED_VENDOR_DEBUG_BOOTIMAGE_TARGET) \
1616    )
1617    $(call dist-for-goals, bootimage_test_harness, \
1618      $(INSTALLED_TEST_HARNESS_RAMDISK_TARGET) \
1619      $(INSTALLED_TEST_HARNESS_BOOTIMAGE_TARGET) \
1620    )
1621  endif
1622
1623  ifeq ($(BOARD_USES_RECOVERY_AS_BOOT),true)
1624    $(call dist-for-goals, droidcore, \
1625      $(recovery_ramdisk) \
1626    )
1627  endif
1628
1629  ifeq ($(EMMA_INSTRUMENT),true)
1630    $(JACOCO_REPORT_CLASSES_ALL) : $(modules_to_install)
1631    $(call dist-for-goals, dist_files, $(JACOCO_REPORT_CLASSES_ALL))
1632  endif
1633
1634  # Put XML formatted API files in the dist dir.
1635  $(TARGET_OUT_COMMON_INTERMEDIATES)/api.xml: $(call java-lib-files,android_stubs_current) $(APICHECK)
1636  $(TARGET_OUT_COMMON_INTERMEDIATES)/system-api.xml: $(call java-lib-files,android_system_stubs_current) $(APICHECK)
1637  $(TARGET_OUT_COMMON_INTERMEDIATES)/module-lib-api.xml: $(call java-lib-files,android_module_lib_stubs_current) $(APICHECK)
1638  $(TARGET_OUT_COMMON_INTERMEDIATES)/system-server-api.xml: $(call java-lib-files,android_system_server_stubs_current) $(APICHECK)
1639  $(TARGET_OUT_COMMON_INTERMEDIATES)/test-api.xml: $(call java-lib-files,android_test_stubs_current) $(APICHECK)
1640
1641  api_xmls := $(addprefix $(TARGET_OUT_COMMON_INTERMEDIATES)/,api.xml system-api.xml module-lib-api.xml system-server-api.xml test-api.xml)
1642  $(api_xmls):
1643	$(hide) echo "Converting API file to XML: $@"
1644	$(hide) mkdir -p $(dir $@)
1645	$(hide) $(APICHECK_COMMAND) --input-api-jar $< --api-xml $@
1646
1647  $(call dist-for-goals, dist_files, $(api_xmls))
1648  api_xmls :=
1649
1650# Building a full system-- the default is to build droidcore
1651droid_targets: droidcore dist_files
1652
1653endif # TARGET_BUILD_APPS
1654
1655.PHONY: docs
1656docs: $(ALL_DOCS)
1657
1658.PHONY: sdk win_sdk winsdk-tools sdk_addon
1659ALL_SDK_TARGETS := $(INTERNAL_SDK_TARGET)
1660sdk: $(ALL_SDK_TARGETS)
1661$(call dist-for-goals,sdk win_sdk, \
1662    $(ALL_SDK_TARGETS) \
1663    $(SYMBOLS_ZIP) \
1664    $(COVERAGE_ZIP) \
1665    $(APPCOMPAT_ZIP) \
1666    $(INSTALLED_BUILD_PROP_TARGET) \
1667)
1668
1669# umbrella targets to assit engineers in verifying builds
1670.PHONY: java native target host java-host java-target native-host native-target \
1671        java-host-tests java-target-tests native-host-tests native-target-tests \
1672        java-tests native-tests host-tests target-tests tests java-dex \
1673        native-host-cross
1674# some synonyms
1675.PHONY: host-java target-java host-native target-native \
1676        target-java-tests target-native-tests
1677host-java : java-host
1678target-java : java-target
1679host-native : native-host
1680target-native : native-target
1681target-java-tests : java-target-tests
1682target-native-tests : native-target-tests
1683tests : host-tests target-tests
1684
1685# Phony target to run all java compilations that use javac
1686.PHONY: javac-check
1687
1688.PHONY: findbugs
1689findbugs: $(INTERNAL_FINDBUGS_HTML_TARGET) $(INTERNAL_FINDBUGS_XML_TARGET)
1690
1691LSDUMP_PATHS_FILE := $(PRODUCT_OUT)/lsdump_paths.txt
1692
1693.PHONY: findlsdumps
1694# LSDUMP_PATHS is a list of tag:path.
1695findlsdumps: $(LSDUMP_PATHS_FILE) $(foreach p,$(LSDUMP_PATHS),$(call word-colon,2,$(p)))
1696
1697$(LSDUMP_PATHS_FILE): PRIVATE_LSDUMP_PATHS := $(LSDUMP_PATHS)
1698$(LSDUMP_PATHS_FILE):
1699	@echo "Generate $@"
1700	@rm -rf $@ && echo -e "$(subst :,:$(space),$(subst $(space),\n,$(PRIVATE_LSDUMP_PATHS)))" > $@
1701
1702.PHONY: check-elf-files
1703check-elf-files:
1704
1705#xxx scrape this from ALL_MODULE_NAME_TAGS
1706.PHONY: modules
1707modules:
1708	@echo "Available sub-modules:"
1709	@echo "$(call module-names-for-tag-list,$(ALL_MODULE_TAGS))" | \
1710	      tr -s ' ' '\n' | sort -u
1711
1712.PHONY: dump-files
1713dump-files:
1714	$(info product_target_FILES for $(TARGET_DEVICE) ($(INTERNAL_PRODUCT)):)
1715	$(foreach p,$(sort $(product_target_FILES)),$(info :   $(p)))
1716	@echo Successfully dumped product file list
1717
1718.PHONY: nothing
1719nothing:
1720	@echo Successfully read the makefiles.
1721
1722.PHONY: tidy_only
1723tidy_only:
1724	@echo Successfully make tidy_only.
1725
1726ndk: $(SOONG_OUT_DIR)/ndk.timestamp
1727.PHONY: ndk
1728
1729$(call dist-write-file,$(KATI_PACKAGE_MK_DIR)/dist.mk)
1730
1731$(info [$(call inc_and_print,subdir_makefiles_inc)/$(subdir_makefiles_total)] writing build rules ...)
1732