1#
2# Copyright (C) 2008 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#      http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16
17# Catch users that directly include base_rules.mk
18$(call record-module-type,base_rules)
19
20# Users can define base-rules-hook in their buildspec.mk to perform
21# arbitrary operations as each module is included.
22ifdef base-rules-hook
23  ifndef _has_warned_about_base_rules_hook
24    $(warning base-rules-hook is deprecated, please remove usages of it and/or convert to Soong.)
25    _has_warned_about_base_rules_hook := true
26  endif
27  $(if $(base-rules-hook),)
28endif
29
30###########################################################
31## Common instructions for a generic module.
32###########################################################
33
34LOCAL_MODULE := $(strip $(LOCAL_MODULE))
35ifeq ($(LOCAL_MODULE),)
36  $(error $(LOCAL_PATH): LOCAL_MODULE is not defined)
37endif
38$(call verify-module-name)
39
40my_test_data :=
41my_test_config :=
42
43LOCAL_IS_HOST_MODULE := $(strip $(LOCAL_IS_HOST_MODULE))
44ifdef LOCAL_IS_HOST_MODULE
45  ifneq ($(LOCAL_IS_HOST_MODULE),true)
46    $(error $(LOCAL_PATH): LOCAL_IS_HOST_MODULE must be "true" or empty, not "$(LOCAL_IS_HOST_MODULE)")
47  endif
48  ifeq ($(LOCAL_HOST_PREFIX),)
49    my_prefix := HOST_
50  else
51    my_prefix := $(LOCAL_HOST_PREFIX)
52  endif
53  my_host := host-
54  my_kind := HOST
55else
56  my_prefix := TARGET_
57  my_kind :=
58  my_host :=
59endif
60
61ifeq ($(my_prefix),HOST_CROSS_)
62  my_host_cross := true
63else
64  my_host_cross :=
65endif
66
67ifeq (true, $(LOCAL_PRODUCT_MODULE))
68ifneq (,$(filter $(LOCAL_MODULE),$(PRODUCT_FORCE_PRODUCT_MODULES_TO_SYSTEM_PARTITION)))
69  LOCAL_PRODUCT_MODULE :=
70endif
71endif
72
73_path := $(LOCAL_MODULE_PATH) $(LOCAL_MODULE_PATH_32) $(LOCAL_MODULE_PATH_64)
74ifneq ($(filter $(TARGET_OUT_VENDOR)%,$(_path)),)
75LOCAL_VENDOR_MODULE := true
76else ifneq ($(filter $(TARGET_OUT_OEM)/%,$(_path)),)
77LOCAL_OEM_MODULE := true
78else ifneq ($(filter $(TARGET_OUT_ODM)/%,$(_path)),)
79LOCAL_ODM_MODULE := true
80else ifneq ($(filter $(TARGET_OUT_PRODUCT)/%,$(_path)),)
81LOCAL_PRODUCT_MODULE := true
82else ifneq ($(filter $(TARGET_OUT_SYSTEM_EXT)/%,$(_path)),)
83LOCAL_SYSTEM_EXT_MODULE := true
84endif
85_path :=
86
87# TODO(b/135957588) Remove following workaround
88# LOCAL_PRODUCT_SERVICES_MODULE to LOCAL_PRODUCT_MODULE for all Android.mk
89ifndef LOCAL_PRODUCT_MODULE
90LOCAL_PRODUCT_MODULE := $(LOCAL_PRODUCT_SERVICES_MODULE)
91endif
92
93ifndef LOCAL_PROPRIETARY_MODULE
94  LOCAL_PROPRIETARY_MODULE := $(LOCAL_VENDOR_MODULE)
95endif
96ifndef LOCAL_VENDOR_MODULE
97  LOCAL_VENDOR_MODULE := $(LOCAL_PROPRIETARY_MODULE)
98endif
99ifneq ($(filter-out $(LOCAL_PROPRIETARY_MODULE),$(LOCAL_VENDOR_MODULE))$(filter-out $(LOCAL_VENDOR_MODULE),$(LOCAL_PROPRIETARY_MODULE)),)
100$(call pretty-error,Only one of LOCAL_PROPRIETARY_MODULE[$(LOCAL_PROPRIETARY_MODULE)] and LOCAL_VENDOR_MODULE[$(LOCAL_VENDOR_MODULE)] may be set, or they must be equal)
101endif
102
103ifeq ($(LOCAL_HOST_MODULE),true)
104my_image_variant := host
105else ifeq ($(LOCAL_VENDOR_MODULE),true)
106my_image_variant := vendor
107else ifeq ($(LOCAL_OEM_MODULE),true)
108my_image_variant := vendor
109else ifeq ($(LOCAL_ODM_MODULE),true)
110my_image_variant := vendor
111else ifeq ($(LOCAL_PRODUCT_MODULE),true)
112my_image_variant := product
113else
114my_image_variant := core
115endif
116
117non_system_module := $(filter true, \
118   $(LOCAL_PRODUCT_MODULE) \
119   $(LOCAL_SYSTEM_EXT_MODULE) \
120   $(LOCAL_VENDOR_MODULE) \
121   $(LOCAL_PROPRIETARY_MODULE))
122
123include $(BUILD_SYSTEM)/local_vendor_product.mk
124
125# local_current_sdk needs to run before local_systemsdk because the former may override
126# LOCAL_SDK_VERSION which is used by the latter.
127include $(BUILD_SYSTEM)/local_current_sdk.mk
128
129# Check if the use of System SDK is correct. Note that, for Soong modules, the system sdk version
130# check is done in Soong. No need to do it twice.
131ifneq ($(LOCAL_MODULE_MAKEFILE),$(SOONG_ANDROID_MK))
132include $(BUILD_SYSTEM)/local_systemsdk.mk
133endif
134
135# Ninja has an implicit dependency on the command being run, and kati will
136# regenerate the ninja manifest if any read makefile changes, so there is no
137# need to have dependencies on makefiles.
138# This won't catch all the cases where LOCAL_ADDITIONAL_DEPENDENCIES contains
139# a .mk file, because a few users of LOCAL_ADDITIONAL_DEPENDENCIES don't include
140# base_rules.mk, but it will fix the most common ones.
141LOCAL_ADDITIONAL_DEPENDENCIES := $(filter-out %.mk,$(LOCAL_ADDITIONAL_DEPENDENCIES))
142
143my_bad_deps := $(strip $(foreach dep,$(filter-out | ||,$(LOCAL_ADDITIONAL_DEPENDENCIES)),\
144                 $(if $(findstring /,$(dep)),,$(dep))))
145ifneq ($(my_bad_deps),)
146$(call pretty-warning,"Bad LOCAL_ADDITIONAL_DEPENDENCIES: $(my_bad_deps)")
147$(call pretty-error,"LOCAL_ADDITIONAL_DEPENDENCIES must only contain paths (not module names)")
148endif
149
150###########################################################
151## Validate and define fallbacks for input LOCAL_* variables.
152###########################################################
153
154LOCAL_UNINSTALLABLE_MODULE := $(strip $(LOCAL_UNINSTALLABLE_MODULE))
155
156# Only the tags mentioned in this test are expected to be set by module
157# makefiles. Anything else is either a typo or a source of unexpected
158# behaviors.
159ifneq ($(filter-out tests optional samples,$(LOCAL_MODULE_TAGS)),)
160$(call pretty-error,unusual tags: $(filter-out tests optional samples,$(LOCAL_MODULE_TAGS)))
161endif
162
163LOCAL_MODULE_CLASS := $(strip $(LOCAL_MODULE_CLASS))
164ifneq ($(words $(LOCAL_MODULE_CLASS)),1)
165  $(error $(LOCAL_PATH): LOCAL_MODULE_CLASS must contain exactly one word, not "$(LOCAL_MODULE_CLASS)")
166endif
167
168my_32_64_bit_suffix := $(if $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)IS_64_BIT),64,32)
169
170ifneq (true,$(LOCAL_UNINSTALLABLE_MODULE))
171my_multilib_module_path := $(strip $(LOCAL_MODULE_PATH_$(my_32_64_bit_suffix)))
172ifdef my_multilib_module_path
173my_module_path := $(my_multilib_module_path)
174else
175my_module_path := $(strip $(LOCAL_MODULE_PATH))
176endif
177my_module_path := $(patsubst %/,%,$(my_module_path))
178my_module_relative_path := $(strip $(LOCAL_MODULE_RELATIVE_PATH))
179
180ifdef LOCAL_IS_HOST_MODULE
181  partition_tag :=
182  actual_partition_tag :=
183else
184ifeq (true,$(strip $(LOCAL_VENDOR_MODULE)))
185  partition_tag := _VENDOR
186  # A vendor module could be on the vendor partition at "vendor" or the system
187  # partition at "system/vendor".
188  actual_partition_tag := $(if $(filter true,$(BOARD_USES_VENDORIMAGE)),vendor,system)
189else ifeq (true,$(strip $(LOCAL_OEM_MODULE)))
190  partition_tag := _OEM
191  actual_partition_tag := oem
192else ifeq (true,$(strip $(LOCAL_ODM_MODULE)))
193  partition_tag := _ODM
194  # An ODM module could be on the odm partition at "odm", the vendor partition
195  # at "vendor/odm", or the system partition at "system/vendor/odm".
196  actual_partition_tag := $(if $(filter true,$(BOARD_USES_ODMIMAGE)),odm,$(if $(filter true,$(BOARD_USES_VENDORIMAGE)),vendor,system))
197else ifeq (true,$(strip $(LOCAL_PRODUCT_MODULE)))
198  partition_tag := _PRODUCT
199  # A product module could be on the product partition at "product" or the
200  # system partition at "system/product".
201  actual_partition_tag := $(if $(filter true,$(BOARD_USES_PRODUCTIMAGE)),product,system)
202else ifeq (true,$(strip $(LOCAL_SYSTEM_EXT_MODULE)))
203  partition_tag := _SYSTEM_EXT
204  # A system_ext-specific module could be on the system_ext partition at
205  # "system_ext" or the system partition at "system/system_ext".
206  actual_partition_tag := $(if $(filter true,$(BOARD_USES_SYSTEM_EXTIMAGE)),system_ext,system)
207else ifeq (NATIVE_TESTS,$(LOCAL_MODULE_CLASS))
208  partition_tag := _DATA
209  actual_partition_tag := data
210else
211  # The definition of should-install-to-system will be different depending
212  # on which goal (e.g., sdk or just droid) is being built.
213  partition_tag := $(if $(call should-install-to-system,$(LOCAL_MODULE_TAGS)),,_DATA)
214  actual_partition_tag := $(if $(partition_tag),data,system)
215endif
216endif
217# For test modules that lack a suite tag, set null-suite as the default.
218# We only support adding a default suite to native tests, native benchmarks, and instrumentation tests.
219# This is because they are the only tests we currently auto-generate test configs for.
220ifndef LOCAL_COMPATIBILITY_SUITE
221  ifneq ($(filter NATIVE_TESTS NATIVE_BENCHMARK, $(LOCAL_MODULE_CLASS)),)
222    LOCAL_COMPATIBILITY_SUITE := null-suite
223  endif
224  ifneq ($(filter APPS, $(LOCAL_MODULE_CLASS)),)
225    ifneq ($(filter $(LOCAL_MODULE_TAGS),tests),)
226      LOCAL_COMPATIBILITY_SUITE := null-suite
227    endif
228  endif
229endif
230
231use_testcase_folder :=
232ifeq ($(my_module_path),)
233  ifneq ($(LOCAL_MODULE),$(filter $(LOCAL_MODULE),$(DEFAULT_DATA_OUT_MODULES)))
234    ifdef LOCAL_COMPATIBILITY_SUITE
235      ifneq (true, $(LOCAL_IS_HOST_MODULE))
236        use_testcase_folder := true
237      endif
238    endif
239  endif
240endif
241
242ifeq ($(LOCAL_IS_UNIT_TEST),true)
243  ifeq ($(LOCAL_IS_HOST_MODULE),true)
244    LOCAL_COMPATIBILITY_SUITE += host-unit-tests
245  endif
246endif
247
248ifeq ($(my_module_path),)
249  install_path_var := $(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)OUT$(partition_tag)_$(LOCAL_MODULE_CLASS)
250  ifeq (true,$(LOCAL_PRIVILEGED_MODULE))
251    install_path_var := $(install_path_var)_PRIVILEGED
252  endif
253
254  my_module_path := $($(install_path_var))
255
256  # If use_testcase_folder be set, and LOCAL_MODULE_PATH not set,
257  # overwrite the default path under testcase.
258  ifeq ($(use_testcase_folder),true)
259    arch_dir := $($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)
260    testcase_folder := $($(my_prefix)OUT_TESTCASES)/$(LOCAL_MODULE)/$(arch_dir)
261    my_module_path := $(testcase_folder)
262    arch_dir :=
263  endif
264
265  ifeq ($(strip $(my_module_path)),)
266    $(error $(LOCAL_PATH): unhandled install path "$(install_path_var) for $(LOCAL_MODULE)")
267  endif
268endif
269ifneq ($(my_module_relative_path),)
270  my_module_path := $(my_module_path)/$(my_module_relative_path)
271endif
272endif # not LOCAL_UNINSTALLABLE_MODULE
273
274ifneq ($(strip $(LOCAL_BUILT_MODULE)$(LOCAL_INSTALLED_MODULE)),)
275  $(error $(LOCAL_PATH): LOCAL_BUILT_MODULE and LOCAL_INSTALLED_MODULE must not be defined by component makefiles)
276endif
277
278my_register_name := $(LOCAL_MODULE)
279ifeq ($(my_host_cross),true)
280  my_register_name := host_cross_$(LOCAL_MODULE)
281endif
282ifdef LOCAL_2ND_ARCH_VAR_PREFIX
283ifndef LOCAL_NO_2ND_ARCH_MODULE_SUFFIX
284my_register_name := $(my_register_name)$($(my_prefix)2ND_ARCH_MODULE_SUFFIX)
285endif
286endif
287
288ifeq ($(my_host_cross),true)
289  my_all_targets := host_cross_$(my_register_name)_all_targets
290else ifneq ($(LOCAL_IS_HOST_MODULE),)
291  my_all_targets := host_$(my_register_name)_all_targets
292else
293  my_all_targets := device_$(my_register_name)_all_targets
294endif
295
296# Make sure that this IS_HOST/CLASS/MODULE combination is unique.
297module_id := MODULE.$(if \
298    $(LOCAL_IS_HOST_MODULE),$($(my_prefix)OS),TARGET).$(LOCAL_MODULE_CLASS).$(my_register_name)
299ifdef $(module_id)
300$(error $(LOCAL_PATH): $(module_id) already defined by $($(module_id)))
301endif
302$(module_id) := $(LOCAL_PATH)
303
304# These are the same as local-intermediates-dir / local-generated-sources dir, but faster
305intermediates.COMMON := $($(my_prefix)OUT_COMMON_INTERMEDIATES)/$(LOCAL_MODULE_CLASS)/$(LOCAL_MODULE)_intermediates
306ifneq (,$(filter $(my_prefix)$(LOCAL_MODULE_CLASS),$(COMMON_MODULE_CLASSES)))
307  intermediates := $($(my_prefix)OUT_COMMON_INTERMEDIATES)/$(LOCAL_MODULE_CLASS)/$(LOCAL_MODULE)_intermediates
308  generated_sources_dir := $($(my_prefix)OUT_COMMON_GEN)/$(LOCAL_MODULE_CLASS)/$(LOCAL_MODULE)_intermediates
309else
310  ifneq (,$(filter $(LOCAL_MODULE_CLASS),$(PER_ARCH_MODULE_CLASSES)))
311    intermediates := $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)OUT_INTERMEDIATES)/$(LOCAL_MODULE_CLASS)/$(LOCAL_MODULE)_intermediates
312  else
313    intermediates := $($(my_prefix)OUT_INTERMEDIATES)/$(LOCAL_MODULE_CLASS)/$(LOCAL_MODULE)_intermediates
314  endif
315  generated_sources_dir := $($(my_prefix)OUT_GEN)/$(LOCAL_MODULE_CLASS)/$(LOCAL_MODULE)_intermediates
316endif
317
318ifneq ($(LOCAL_OVERRIDES_MODULES),)
319  ifndef LOCAL_IS_HOST_MODULE
320    ifeq ($(LOCAL_MODULE_CLASS),EXECUTABLES)
321      EXECUTABLES.$(LOCAL_MODULE).OVERRIDES := $(strip $(LOCAL_OVERRIDES_MODULES))
322    else ifeq ($(LOCAL_MODULE_CLASS),SHARED_LIBRARIES)
323      SHARED_LIBRARIES.$(LOCAL_MODULE).OVERRIDES := $(strip $(LOCAL_OVERRIDES_MODULES))
324    else ifeq ($(LOCAL_MODULE_CLASS),ETC)
325      ETC.$(LOCAL_MODULE).OVERRIDES := $(strip $(LOCAL_OVERRIDES_MODULES))
326    else
327      $(call pretty-error,LOCAL_MODULE_CLASS := $(LOCAL_MODULE_CLASS) cannot use LOCAL_OVERRIDES_MODULES)
328    endif
329  else
330    $(call pretty-error,host modules cannot use LOCAL_OVERRIDES_MODULES)
331  endif
332endif
333
334###########################################################
335# Pick a name for the intermediate and final targets
336###########################################################
337include $(BUILD_SYSTEM)/configure_module_stem.mk
338
339LOCAL_BUILT_MODULE := $(intermediates)/$(my_built_module_stem)
340
341ifneq (,$(LOCAL_SOONG_INSTALLED_MODULE))
342  ifneq ($(LOCAL_MODULE_MAKEFILE),$(SOONG_ANDROID_MK))
343    $(call pretty-error, LOCAL_SOONG_INSTALLED_MODULE can only be used from $(SOONG_ANDROID_MK))
344  endif
345  # Use the install path requested by Soong.
346  LOCAL_INSTALLED_MODULE := $(LOCAL_SOONG_INSTALLED_MODULE)
347else ifneq (true,$(LOCAL_UNINSTALLABLE_MODULE))
348  # Apk and its attachments reside in its own subdir.
349  ifeq ($(LOCAL_MODULE_CLASS),APPS)
350    # framework-res.apk doesn't like the additional layer.
351    ifeq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
352      # Neither do Runtime Resource Overlay apks, which contain just the overlaid resources.
353    else ifeq ($(LOCAL_IS_RUNTIME_RESOURCE_OVERLAY),true)
354    else
355      ifneq ($(use_testcase_folder),true)
356        my_module_path := $(my_module_path)/$(LOCAL_MODULE)
357      endif
358    endif
359  endif
360  LOCAL_INSTALLED_MODULE := $(my_module_path)/$(my_installed_module_stem)
361endif
362
363# Assemble the list of targets to create PRIVATE_ variables for.
364LOCAL_INTERMEDIATE_TARGETS += $(LOCAL_BUILT_MODULE)
365
366###########################################################
367## Create .toc files from shared objects to reduce unnecessary rebuild
368# .toc files have the list of external dynamic symbols without their addresses.
369# As .KATI_RESTAT is specified to .toc files and commit-change-for-toc is used,
370# dependent binaries of a .toc file will be rebuilt only when the content of
371# the .toc file is changed.
372#
373# Don't create .toc files for Soong shared libraries, that is handled in
374# Soong and soong_cc_prebuilt.mk
375###########################################################
376ifneq ($(LOCAL_MODULE_MAKEFILE),$(SOONG_ANDROID_MK))
377ifeq ($(LOCAL_MODULE_CLASS),SHARED_LIBRARIES)
378LOCAL_INTERMEDIATE_TARGETS += $(LOCAL_BUILT_MODULE).toc
379$(LOCAL_BUILT_MODULE).toc: $(LOCAL_BUILT_MODULE)
380	$(call $(PRIVATE_2ND_ARCH_VAR_PREFIX)$(PRIVATE_PREFIX)transform-shared-lib-to-toc,$<,$@.tmp)
381	$(call commit-change-for-toc,$@)
382
383# Kati adds restat=1 to ninja. GNU make does nothing for this.
384.KATI_RESTAT: $(LOCAL_BUILT_MODULE).toc
385# Build .toc file when using mm, mma, or make $(my_register_name)
386$(my_all_targets): $(LOCAL_BUILT_MODULE).toc
387endif
388endif
389
390###########################################################
391## logtags: Add .logtags files to global list
392###########################################################
393
394logtags_sources := $(filter %.logtags,$(LOCAL_SRC_FILES)) $(LOCAL_LOGTAGS_FILES)
395
396ifneq ($(strip $(logtags_sources) $(LOCAL_SOONG_LOGTAGS_FILES)),)
397event_log_tags := $(foreach f,$(LOCAL_SOONG_LOGTAGS_FILES) $(addprefix $(LOCAL_PATH)/,$(logtags_sources)),$(call clean-path,$(f)))
398else
399event_log_tags :=
400endif
401
402###########################################################
403## make clean- targets
404###########################################################
405cleantarget := clean-$(my_register_name)
406.PHONY: $(cleantarget)
407$(cleantarget) : PRIVATE_MODULE := $(my_register_name)
408$(cleantarget) : PRIVATE_CLEAN_FILES := \
409    $(LOCAL_BUILT_MODULE) \
410    $(LOCAL_INSTALLED_MODULE) \
411    $(intermediates)
412$(cleantarget)::
413	@echo "Clean: $(PRIVATE_MODULE)"
414	$(hide) rm -rf $(PRIVATE_CLEAN_FILES)
415
416###########################################################
417## Common definitions for module.
418###########################################################
419$(LOCAL_INTERMEDIATE_TARGETS) : PRIVATE_PATH:=$(LOCAL_PATH)
420$(LOCAL_INTERMEDIATE_TARGETS) : PRIVATE_IS_HOST_MODULE := $(LOCAL_IS_HOST_MODULE)
421$(LOCAL_INTERMEDIATE_TARGETS) : PRIVATE_HOST:= $(my_host)
422$(LOCAL_INTERMEDIATE_TARGETS) : PRIVATE_PREFIX := $(my_prefix)
423$(LOCAL_INTERMEDIATE_TARGETS) : .KATI_TAGS += ;module_name=$(LOCAL_MODULE)
424ifeq ($(LOCAL_MODULE_CLASS),)
425$(error "$(LOCAL_MODULE) in $(LOCAL_PATH) does not set $(LOCAL_MODULE_CLASS)")
426else
427$(LOCAL_INTERMEDIATE_TARGETS) : .KATI_TAGS += ;module_type=$(LOCAL_MODULE_CLASS)
428endif
429
430$(LOCAL_INTERMEDIATE_TARGETS) : PRIVATE_INTERMEDIATES_DIR:= $(intermediates)
431$(LOCAL_INTERMEDIATE_TARGETS) : PRIVATE_2ND_ARCH_VAR_PREFIX := $(LOCAL_2ND_ARCH_VAR_PREFIX)
432
433# Tell the module and all of its sub-modules who it is.
434$(LOCAL_INTERMEDIATE_TARGETS) : PRIVATE_MODULE:= $(my_register_name)
435
436# Provide a short-hand for building this module.
437# We name both BUILT and INSTALLED in case
438# LOCAL_UNINSTALLABLE_MODULE is set.
439.PHONY: $(my_all_targets)
440$(my_all_targets): $(LOCAL_BUILT_MODULE) $(LOCAL_INSTALLED_MODULE) $(LOCAL_ADDITIONAL_CHECKED_MODULE)
441
442.PHONY: $(my_register_name)
443$(my_register_name): $(my_all_targets)
444
445ifneq ($(my_register_name),$(LOCAL_MODULE))
446# $(LOCAL_MODULE) covers all the multilib targets.
447.PHONY: $(LOCAL_MODULE)
448$(LOCAL_MODULE) : $(my_all_targets)
449endif
450
451# Set up phony targets that covers all modules under the given paths.
452# This allows us to build everything in given paths by running mmma/mma.
453define my_path_comp
454parent := $(patsubst %/,%,$(dir $(1)))
455parent_target := MODULES-IN-$$(subst /,-,$$(parent))
456.PHONY: $$(parent_target)
457$$(parent_target): $(2)
458ifndef $$(parent_target)
459  $$(parent_target) := true
460  ifneq (,$$(findstring /,$$(parent)))
461    $$(eval $$(call my_path_comp,$$(parent),$$(parent_target)))
462  endif
463endif
464endef
465
466_local_path := $(patsubst %/,%,$(LOCAL_PATH))
467_local_path_target := MODULES-IN-$(subst /,-,$(_local_path))
468
469.PHONY: $(_local_path_target)
470$(_local_path_target): $(my_register_name)
471
472ifndef $(_local_path_target)
473  $(_local_path_target) := true
474  ifneq (,$(findstring /,$(_local_path)))
475    $(eval $(call my_path_comp,$(_local_path),$(_local_path_target)))
476  endif
477endif
478
479_local_path :=
480_local_path_target :=
481my_path_comp :=
482
483###########################################################
484## Module installation rule
485###########################################################
486
487my_installed_symlinks :=
488
489ifneq (,$(LOCAL_SOONG_INSTALLED_MODULE))
490  # Soong already generated the copy rule, but make the installed location depend on the Make
491  # copy of the intermediates for now, as some rules that collect intermediates may expect
492  # them to exist.
493  $(LOCAL_INSTALLED_MODULE): $(LOCAL_BUILT_MODULE)
494else ifneq (true,$(LOCAL_UNINSTALLABLE_MODULE))
495  $(LOCAL_INSTALLED_MODULE): PRIVATE_POST_INSTALL_CMD := $(LOCAL_POST_INSTALL_CMD)
496  $(LOCAL_INSTALLED_MODULE): $(LOCAL_BUILT_MODULE)
497	@echo "Install: $@"
498  ifeq ($(LOCAL_MODULE_MAKEFILE),$(SOONG_ANDROID_MK))
499	$(copy-file-or-link-to-new-target)
500  else
501	$(copy-file-to-new-target)
502  endif
503	$(PRIVATE_POST_INSTALL_CMD)
504
505  # Rule to install the module's companion symlinks
506  my_installed_symlinks := $(addprefix $(my_module_path)/,$(LOCAL_MODULE_SYMLINKS) $(LOCAL_MODULE_SYMLINKS_$(my_32_64_bit_suffix)))
507  $(foreach symlink,$(my_installed_symlinks),\
508      $(call symlink-file,$(LOCAL_INSTALLED_MODULE),$(my_installed_module_stem),$(symlink))\
509      $(call declare-0p-target,$(symlink)))
510
511  $(my_all_targets) : | $(my_installed_symlinks)
512
513endif # !LOCAL_UNINSTALLABLE_MODULE
514
515# Add dependencies on LOCAL_SOONG_INSTALL_SYMLINKS if we're installing any kind of module, not just
516# ones that set LOCAL_SOONG_INSTALLED_MODULE. This is so we can have a soong module that only
517# installs symlinks (e.g. install_symlink). We can't set LOCAL_SOONG_INSTALLED_MODULE to a symlink
518# because cp commands will fail on symlinks.
519ifneq (,$(or $(LOCAL_SOONG_INSTALLED_MODULE),$(call boolean-not,$(LOCAL_UNINSTALLABLE_MODULE))))
520  $(foreach symlink, $(LOCAL_SOONG_INSTALL_SYMLINKS), $(call declare-0p-target,$(symlink)))
521  $(my_all_targets) : | $(LOCAL_SOONG_INSTALL_SYMLINKS)
522endif
523
524###########################################################
525## VINTF manifest fragment and init.rc goals
526###########################################################
527
528my_vintf_installed:=
529my_vintf_path:=
530my_vintf_pairs:=
531my_init_rc_installed :=
532my_init_rc_path :=
533my_init_rc_pairs :=
534ifneq (true,$(LOCAL_UNINSTALLABLE_MODULE))
535  ifndef LOCAL_IS_HOST_MODULE
536    # Rule to install the module's companion vintf fragments.
537    ifneq ($(strip $(LOCAL_FULL_VINTF_FRAGMENTS)),)
538      my_vintf_fragments := $(LOCAL_FULL_VINTF_FRAGMENTS)
539    else
540      my_vintf_fragments := $(foreach xml,$(LOCAL_VINTF_FRAGMENTS),$(LOCAL_PATH)/$(xml))
541    endif
542    ifneq ($(strip $(my_vintf_fragments)),)
543      # Make doesn't support recovery as an output partition, but some Soong modules installed in recovery
544      # have init.rc files that need to be installed alongside them. Manually handle the case where the
545      # output file is in the recovery partition.
546      my_vintf_path := $(if $(filter $(TARGET_RECOVERY_ROOT_OUT)/%,$(my_module_path)),$(TARGET_RECOVERY_ROOT_OUT)/system/etc,$(TARGET_OUT$(partition_tag)_ETC))
547      my_vintf_pairs := $(foreach xml,$(my_vintf_fragments),$(xml):$(my_vintf_path)/vintf/manifest/$(notdir $(xml)))
548      my_vintf_installed := $(foreach xml,$(my_vintf_pairs),$(call word-colon,2,$(xml)))
549
550      # Only set up copy rules once, even if another arch variant shares it
551      my_vintf_new_pairs := $(filter-out $(ALL_VINTF_MANIFEST_FRAGMENTS_LIST),$(my_vintf_pairs))
552      ALL_VINTF_MANIFEST_FRAGMENTS_LIST += $(my_vintf_new_pairs)
553
554      ifneq ($(LOCAL_MODULE_MAKEFILE),$(SOONG_ANDROID_MK))
555        $(call copy-many-vintf-manifest-files-checked,$(my_vintf_new_pairs))
556        $(my_all_targets) : $(my_vintf_installed)
557        # Install fragments together with the target
558        $(LOCAL_INSTALLED_MODULE) : | $(my_vintf_installed)
559     endif
560    endif # my_vintf_fragments
561
562    # Rule to install the module's companion init.rc.
563    ifneq ($(strip $(LOCAL_FULL_INIT_RC)),)
564      my_init_rc := $(LOCAL_FULL_INIT_RC)
565    else
566      my_init_rc := $(foreach rc,$(LOCAL_INIT_RC_$(my_32_64_bit_suffix)) $(LOCAL_INIT_RC),$(LOCAL_PATH)/$(rc))
567    endif
568    ifneq ($(strip $(my_init_rc)),)
569      # Make doesn't support recovery or ramdisk as an output partition,
570      # but some Soong modules installed in recovery or ramdisk
571      # have init.rc files that need to be installed alongside them.
572      # Manually handle the case where the
573      # output file is in the recovery or ramdisk partition.
574      ifneq (,$(filter $(TARGET_RECOVERY_ROOT_OUT)/%,$(my_module_path)))
575        ifneq (,$(filter $(TARGET_RECOVERY_ROOT_OUT)/first_stage_ramdisk/%,$(my_module_path)))
576            my_init_rc_path := $(TARGET_RECOVERY_ROOT_OUT)/first_stage_ramdisk/system/etc
577        else
578            my_init_rc_path := $(TARGET_RECOVERY_ROOT_OUT)/system/etc
579        endif
580      else ifneq (,$(filter $(TARGET_RAMDISK_OUT)/%,$(my_module_path)))
581        my_init_rc_path := $(TARGET_RAMDISK_OUT)/system/etc
582      else
583        my_init_rc_path := $(TARGET_OUT$(partition_tag)_ETC)
584      endif
585      my_init_rc_pairs := $(foreach rc,$(my_init_rc),$(rc):$(my_init_rc_path)/init/$(notdir $(rc)))
586      my_init_rc_installed := $(foreach rc,$(my_init_rc_pairs),$(call word-colon,2,$(rc)))
587
588      # Make sure we only set up the copy rules once, even if another arch variant
589      # shares a common LOCAL_INIT_RC.
590      my_init_rc_new_pairs := $(filter-out $(ALL_INIT_RC_INSTALLED_PAIRS),$(my_init_rc_pairs))
591      ALL_INIT_RC_INSTALLED_PAIRS += $(my_init_rc_new_pairs)
592
593      ifneq ($(LOCAL_MODULE_MAKEFILE),$(SOONG_ANDROID_MK))
594        $(call copy-many-init-script-files-checked,$(my_init_rc_new_pairs))
595        $(my_all_targets) : $(my_init_rc_installed)
596        # Install init_rc together with the target
597        $(LOCAL_INSTALLED_MODULE) : | $(my_init_rc_installed)
598      endif
599    endif # my_init_rc
600
601  endif # !LOCAL_IS_HOST_MODULE
602endif # !LOCAL_UNINSTALLABLE_MODULE
603
604###########################################################
605## CHECK_BUILD goals
606###########################################################
607my_checked_module :=
608# If nobody has defined a more specific module for the
609# checked modules, use LOCAL_BUILT_MODULE.
610ifdef LOCAL_CHECKED_MODULE
611  my_checked_module := $(LOCAL_CHECKED_MODULE)
612else
613  my_checked_module := $(LOCAL_BUILT_MODULE)
614endif
615
616my_checked_module += $(LOCAL_ADDITIONAL_CHECKED_MODULE)
617
618# If they request that this module not be checked, then don't.
619# PLEASE DON'T SET THIS.  ANY PLACES THAT SET THIS WITHOUT
620# GOOD REASON WILL HAVE IT REMOVED.
621ifdef LOCAL_DONT_CHECK_MODULE
622  my_checked_module :=
623endif
624# Don't check build target module defined for the 2nd arch
625ifndef LOCAL_IS_HOST_MODULE
626ifdef LOCAL_2ND_ARCH_VAR_PREFIX
627  my_checked_module :=
628endif
629endif
630
631###########################################################
632## Test Data
633###########################################################
634my_test_data_pairs :=
635my_installed_test_data :=
636# Source to relative dst file paths for reuse in LOCAL_COMPATIBILITY_SUITE.
637my_test_data_file_pairs :=
638
639ifneq ($(strip $(filter NATIVE_TESTS,$(LOCAL_MODULE_CLASS)) $(LOCAL_IS_FUZZ_TARGET)),)
640ifneq ($(strip $(LOCAL_TEST_DATA)),)
641ifneq (true,$(LOCAL_UNINSTALLABLE_MODULE))
642
643# Soong LOCAL_TEST_DATA is of the form <from_base>:<file>:<relative_install_path>
644# or <from_base>:<file>, to be installed to
645# <install_root>/<relative_install_path>/<file> or <install_root>/<file>,
646# respectively.
647ifeq ($(LOCAL_MODULE_MAKEFILE),$(SOONG_ANDROID_MK))
648  define copy_test_data_pairs
649    _src_base := $$(call word-colon,1,$$(td))
650    _file := $$(call word-colon,2,$$(td))
651    _relative_install_path := $$(call word-colon,3,$$(td))
652    ifeq (,$$(_relative_install_path))
653        _relative_dest_file := $$(_file)
654    else
655        _relative_dest_file := $$(call append-path,$$(_relative_install_path),$$(_file))
656    endif
657    my_test_data_pairs += $$(call append-path,$$(_src_base),$$(_file)):$$(call append-path,$$(my_module_path),$$(_relative_dest_file))
658    my_test_data_file_pairs += $$(call append-path,$$(_src_base),$$(_file)):$$(_relative_dest_file)
659  endef
660else
661  define copy_test_data_pairs
662    _src_base := $$(call word-colon,1,$$(td))
663    _file := $$(call word-colon,2,$$(td))
664    ifndef _file
665      _file := $$(_src_base)
666      _src_base := $$(LOCAL_PATH)
667    endif
668    ifneq (,$$(findstring ..,$$(_file)))
669      $$(call pretty-error,LOCAL_TEST_DATA may not include '..': $$(_file))
670    endif
671    ifneq (,$$(filter/%,$$(_src_base) $$(_file)))
672      $$(call pretty-error,LOCAL_TEST_DATA may not include absolute paths: $$(_src_base) $$(_file))
673    endif
674    my_test_data_pairs += $$(call append-path,$$(_src_base),$$(_file)):$$(call append-path,$$(my_module_path),$$(_file))
675    my_test_data_file_pairs += $$(call append-path,$$(_src_base),$$(_file)):$$(_file)
676  endef
677endif
678
679$(foreach td,$(LOCAL_TEST_DATA),$(eval $(copy_test_data_pairs)))
680
681copy_test_data_pairs :=
682
683ifneq ($(LOCAL_MODULE_MAKEFILE),$(SOONG_ANDROID_MK))
684  my_installed_test_data := $(call copy-many-files,$(my_test_data_pairs))
685  $(LOCAL_INSTALLED_MODULE): $(my_installed_test_data)
686else
687  # Skip installing test data for Soong modules, it's already been handled.
688  # Just compute my_installed_test_data.
689  my_installed_test_data := $(foreach f, $(my_test_data_pairs), $(call word-colon,2,$(f)))
690endif
691
692endif
693endif
694endif
695
696###########################################################
697## SOONG INSTALL PAIRS
698###########################################################
699# Declare dependencies for LOCAL_SOONG_INSTALL_PAIRS in soong to the module it relies on.
700ifneq (,$(LOCAL_SOONG_INSTALLED_MODULE))
701$(my_all_targets): \
702    $(foreach f, $(LOCAL_SOONG_INSTALL_PAIRS),\
703      $(word 2,$(subst :,$(space),$(f))))
704endif
705
706###########################################################
707## Compatibility suite files.
708###########################################################
709ifdef LOCAL_COMPATIBILITY_SUITE
710
711ifneq (,$(LOCAL_FULL_TEST_CONFIG))
712  test_config := $(LOCAL_FULL_TEST_CONFIG)
713else ifneq (,$(LOCAL_TEST_CONFIG))
714  test_config := $(LOCAL_PATH)/$(LOCAL_TEST_CONFIG)
715else
716  test_config := $(wildcard $(LOCAL_PATH)/AndroidTest.xml)
717endif
718
719ifeq ($(EXCLUDE_MCTS),true)
720ifeq (,$(filter $(LOCAL_MODULE),$(mcts_whitelist)))
721  ifneq (,$(test_config))
722    ifneq (,$(filter mcts-%,$(LOCAL_COMPATIBILITY_SUITE)))
723      LOCAL_COMPATIBILITY_SUITE := $(filter-out cts,$(LOCAL_COMPATIBILITY_SUITE))
724    endif
725  endif
726endif
727endif
728
729ifneq (true,$(LOCAL_UNINSTALLABLE_MODULE))
730
731# If we are building a native test or benchmark and its stem variants are not defined,
732# separate the multiple architectures into subdirectories of the testcase folder.
733arch_dir :=
734is_native :=
735multi_arch :=
736ifeq ($(LOCAL_MODULE_CLASS),NATIVE_TESTS)
737  is_native := true
738  multi_arch := true
739endif
740ifdef LOCAL_MULTILIB
741  multi_arch := true
742# These conditionals allow this functionality to be mimicked in Soong
743else ifeq ($(LOCAL_MODULE_MAKEFILE),$(SOONG_ANDROID_MK))
744  ifeq ($(LOCAL_MODULE_CLASS),SHARED_LIBRARIES)
745    multi_arch := true
746  endif
747endif
748
749ifdef multi_arch
750arch_dir := /$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)
751else
752ifeq ($(use_testcase_folder),true)
753  arch_dir := /$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)
754endif
755endif
756
757multi_arch :=
758
759my_default_test_module :=
760my_default_test_module := $($(my_prefix)OUT_TESTCASES)/$(LOCAL_MODULE)$(arch_dir)/$(my_installed_module_stem)
761ifneq ($(LOCAL_INSTALLED_MODULE),$(my_default_test_module))
762# Install into the testcase folder
763$(LOCAL_INSTALLED_MODULE) : $(my_default_test_module)
764endif
765
766# The module itself.
767$(foreach suite, $(LOCAL_COMPATIBILITY_SUITE), \
768  $(eval my_compat_dist_$(suite) := $(patsubst %:$(LOCAL_INSTALLED_MODULE),$(LOCAL_INSTALLED_MODULE):$(LOCAL_INSTALLED_MODULE),\
769    $(foreach dir, $(call compatibility_suite_dirs,$(suite),$(arch_dir)), \
770      $(LOCAL_BUILT_MODULE):$(dir)/$(my_installed_module_stem)))) \
771  $(eval my_compat_dist_config_$(suite) := ))
772
773ifneq (,$(LOCAL_SOONG_CLASSES_JAR))
774    $(foreach suite, $(LOCAL_COMPATIBILITY_SUITE), \
775      $(eval my_compat_api_map_$(suite) += $(LOCAL_SOONG_CLASSES_JAR)))
776endif
777
778# Auto-generate build config.
779ifeq (,$(test_config))
780  ifneq (true,$(is_native))
781    is_instrumentation_test := true
782    ifeq (true, $(LOCAL_IS_HOST_MODULE))
783      is_instrumentation_test := false
784    endif
785    # If LOCAL_MODULE_CLASS is not APPS, it's certainly not an instrumentation
786    # test. However, some packages for test data also have LOCAL_MODULE_CLASS
787    # set to APPS. These will require flag LOCAL_DISABLE_AUTO_GENERATE_TEST_CONFIG
788    # to disable auto-generating test config file.
789    ifneq (APPS, $(LOCAL_MODULE_CLASS))
790      is_instrumentation_test := false
791    endif
792  endif
793  # CTS modules can be used for test data, so test config files must be
794  # explicitly created using AndroidTest.xml
795  ifeq (,$(filter cts, $(LOCAL_COMPATIBILITY_SUITE)))
796    ifneq (true, $(LOCAL_DISABLE_AUTO_GENERATE_TEST_CONFIG))
797      ifeq (true, $(filter true,$(is_native) $(is_instrumentation_test)))
798        include $(BUILD_SYSTEM)/autogen_test_config.mk
799        test_config := $(autogen_test_config_file)
800        autogen_test_config_file :=
801      endif
802    endif
803  endif
804endif
805is_instrumentation_test :=
806
807# Currently this flag variable is true only for the `android_test_helper_app` type module
808# which should not have any .config file
809ifeq (true, $(LOCAL_DISABLE_TEST_CONFIG))
810  test_config :=
811endif
812
813# Make sure we only add the files once for multilib modules.
814ifdef $(my_prefix)$(LOCAL_MODULE_CLASS)_$(LOCAL_MODULE)_compat_files
815  # Sync the auto_test_config value for multilib modules.
816  ifdef $(my_prefix)$(LOCAL_MODULE_CLASS)_$(LOCAL_MODULE)_autogen
817    ALL_MODULES.$(my_register_name).auto_test_config := true
818  endif
819else
820  $(my_prefix)$(LOCAL_MODULE_CLASS)_$(LOCAL_MODULE)_compat_files := true
821  # LOCAL_COMPATIBILITY_SUPPORT_FILES is a list of <src>[:<dest>].
822  $(foreach suite, $(LOCAL_COMPATIBILITY_SUITE), \
823    $(eval my_compat_dist_$(suite) += $(foreach f, $(LOCAL_COMPATIBILITY_SUPPORT_FILES), \
824      $(eval p := $(subst :,$(space),$(f))) \
825      $(eval s := $(word 1,$(p))) \
826      $(eval n := $(or $(word 2,$(p)),$(notdir $(word 1, $(p))))) \
827      $(foreach dir, $(call compatibility_suite_dirs,$(suite)), \
828        $(s):$(dir)/$(n)))))
829
830  $(foreach suite, $(LOCAL_COMPATIBILITY_SUITE), \
831     $(eval my_compat_api_map_$(suite) += $(foreach f, $(LOCAL_COMPATIBILITY_SUPPORT_FILES), \
832       $(eval p := $(subst :,$(space),$(f))) \
833       $(eval s := $(word 1,$(p))) \
834       $(if $(filter %.apk,$(s)) $(filter %.jar,$(s)),$(s),))))
835
836  ifneq (,$(test_config))
837    $(foreach suite, $(LOCAL_COMPATIBILITY_SUITE), \
838      $(eval my_compat_dist_config_$(suite) += $(foreach dir, $(call compatibility_suite_dirs,$(suite)), \
839        $(test_config):$(dir)/$(LOCAL_MODULE).config$(LOCAL_TEST_CONFIG_SUFFIX))))
840  endif
841
842  ifneq (,$(LOCAL_EXTRA_FULL_TEST_CONFIGS))
843    $(foreach test_config_file, $(LOCAL_EXTRA_FULL_TEST_CONFIGS), \
844      $(foreach suite, $(LOCAL_COMPATIBILITY_SUITE), \
845        $(eval my_compat_dist_config_$(suite) += $(foreach dir, $(call compatibility_suite_dirs,$(suite)), \
846          $(test_config_file):$(dir)/$(basename $(notdir $(test_config_file))).config))))
847  endif
848
849  ifneq (,$(wildcard $(LOCAL_PATH)/DynamicConfig.xml))
850    $(foreach suite, $(LOCAL_COMPATIBILITY_SUITE), \
851      $(eval my_compat_dist_config_$(suite) += $(foreach dir, $(call compatibility_suite_dirs,$(suite)), \
852        $(LOCAL_PATH)/DynamicConfig.xml:$(dir)/$(LOCAL_MODULE).dynamic)))
853  endif
854
855  ifneq (,$(wildcard $(LOCAL_PATH)/$(LOCAL_MODULE)_*.config))
856  $(foreach extra_config, $(wildcard $(LOCAL_PATH)/$(LOCAL_MODULE)_*.config), \
857    $(foreach suite, $(LOCAL_COMPATIBILITY_SUITE), \
858      $(eval my_compat_dist_config_$(suite) += $(foreach dir, $(call compatibility_suite_dirs,$(suite)), \
859        $(extra_config):$(dir)/$(notdir $(extra_config))))))
860  endif
861endif # $(my_prefix)$(LOCAL_MODULE_CLASS)_$(LOCAL_MODULE)_compat_files
862
863
864ifeq ($(use_testcase_folder),true)
865ifneq ($(my_test_data_file_pairs),)
866# Filter out existng installed test data paths when collecting test data files to be installed and
867# indexed as they cause build rule conflicts. Instead put them in a separate list which is only
868# used for indexing.
869$(foreach pair, $(my_test_data_file_pairs), \
870  $(eval parts := $(subst :,$(space),$(pair))) \
871  $(eval src_path := $(word 1,$(parts))) \
872  $(eval file := $(word 2,$(parts))) \
873  $(foreach suite, $(LOCAL_COMPATIBILITY_SUITE), \
874    $(eval my_compat_dist_$(suite) += $(foreach dir, $(call compatibility_suite_dirs,$(suite),$(arch_dir)), \
875      $(call filter-copy-pair,$(src_path),$(call append-path,$(dir),$(file)),$(my_installed_test_data)))) \
876    $(eval my_compat_dist_test_data_$(suite) += \
877      $(foreach dir, $(call compatibility_suite_dirs,$(suite),$(arch_dir)), \
878        $(filter $(my_installed_test_data),$(call append-path,$(dir),$(file))))) \
879    $(eval my_compat_api_map_$(suite) += \
880      $(if $(filter %.apk,$(src_path)) $(filter %.jar,$(src_path)),$(src_path),))))
881endif
882else
883ifneq ($(my_test_data_file_pairs),)
884$(foreach pair, $(my_test_data_file_pairs), \
885  $(eval parts := $(subst :,$(space),$(pair))) \
886  $(eval src_path := $(word 1,$(parts))) \
887  $(eval file := $(word 2,$(parts))) \
888  $(foreach suite, $(LOCAL_COMPATIBILITY_SUITE), \
889    $(eval my_compat_dist_$(suite) += $(foreach dir, $(call compatibility_suite_dirs,$(suite),$(arch_dir)), \
890      $(src_path):$(call append-path,$(dir),$(file)))) \
891    $(eval my_compat_api_map_$(suite) += \
892      $(if $(filter %.apk,$(src_path)) $(filter %.jar,$(src_path)),$(src_path),))))
893endif
894endif
895
896
897
898arch_dir :=
899is_native :=
900
901$(call create-suite-dependencies)
902$(foreach suite, $(LOCAL_COMPATIBILITY_SUITE), \
903  $(eval my_compat_dist_config_$(suite) := ) \
904  $(eval my_compat_dist_test_data_$(suite) := ) \
905  $(eval my_compat_api_map_$(suite) := ))
906
907endif  # LOCAL_UNINSTALLABLE_MODULE
908
909# HACK: pretend a soong LOCAL_FULL_TEST_CONFIG is autogenerated by setting the flag in
910# module-info.json
911# TODO: (b/113029686) Add explicit flag from Soong to determine if a test was
912# autogenerated.
913ifneq (,$(filter $(SOONG_OUT_DIR)%,$(LOCAL_FULL_TEST_CONFIG)))
914  ifeq ($(LOCAL_MODULE_MAKEFILE),$(SOONG_ANDROID_MK))
915    ALL_MODULES.$(my_register_name).auto_test_config := true
916  endif
917endif
918
919endif  # LOCAL_COMPATIBILITY_SUITE
920
921my_supported_variant :=
922ifeq ($(my_host_cross),true)
923  my_supported_variant := HOST_CROSS
924else
925  ifdef LOCAL_IS_HOST_MODULE
926    my_supported_variant := HOST
927  else
928    my_supported_variant := DEVICE
929  endif
930endif
931###########################################################
932## Add test module to ALL_DISABLED_PRESUBMIT_TESTS if LOCAL_PRESUBMIT_DISABLED is set to true.
933###########################################################
934ifeq ($(LOCAL_PRESUBMIT_DISABLED),true)
935  ALL_DISABLED_PRESUBMIT_TESTS += $(LOCAL_MODULE)
936endif  # LOCAL_PRESUBMIT_DISABLED
937
938###########################################################
939## Register with ALL_MODULES
940###########################################################
941
942ifndef ALL_MODULES.$(my_register_name).PATH
943    # These keys are no longer used, they've been replaced by keys that specify
944    # target/host/host_cross (REQUIRED_FROM_TARGET / REQUIRED_FROM_HOST) and similar.
945    #
946    # Marking them obsolete to ensure that anyone using these internal variables looks for
947    # alternates.
948    $(KATI_obsolete_var ALL_MODULES.$(my_register_name).REQUIRED)
949    $(KATI_obsolete_var ALL_MODULES.$(my_register_name).EXPLICITLY_REQUIRED)
950    $(KATI_obsolete_var ALL_MODULES.$(my_register_name).HOST_REQUIRED)
951    $(KATI_obsolete_var ALL_MODULES.$(my_register_name).TARGET_REQUIRED)
952endif
953
954ALL_MODULES += $(my_register_name)
955
956# Don't use += on subvars, or else they'll end up being
957# recursively expanded.
958ALL_MODULES.$(my_register_name).CLASS := \
959    $(ALL_MODULES.$(my_register_name).CLASS) $(LOCAL_MODULE_CLASS)
960ALL_MODULES.$(my_register_name).PATH := \
961    $(ALL_MODULES.$(my_register_name).PATH) $(LOCAL_PATH)
962ALL_MODULES.$(my_register_name).TAGS := \
963    $(ALL_MODULES.$(my_register_name).TAGS) $(LOCAL_MODULE_TAGS)
964ALL_MODULES.$(my_register_name).CHECKED := \
965    $(ALL_MODULES.$(my_register_name).CHECKED) $(my_checked_module)
966ALL_MODULES.$(my_register_name).BUILT := \
967    $(ALL_MODULES.$(my_register_name).BUILT) $(LOCAL_BUILT_MODULE)
968ALL_MODULES.$(my_register_name).SOONG_MODULE_TYPE := \
969    $(ALL_MODULES.$(my_register_name).SOONG_MODULE_TYPE) $(LOCAL_SOONG_MODULE_TYPE)
970ifndef LOCAL_IS_HOST_MODULE
971ALL_MODULES.$(my_register_name).TARGET_BUILT := \
972    $(ALL_MODULES.$(my_register_name).TARGET_BUILT) $(LOCAL_BUILT_MODULE)
973endif
974ifneq (,$(LOCAL_SOONG_INSTALLED_MODULE))
975  # Store the list of paths to installed locations of files provided by this
976  # module.  Used as dependencies of the image packaging rules when the module
977  # is installed by the current product.
978  ALL_MODULES.$(my_register_name).INSTALLED := \
979    $(strip $(ALL_MODULES.$(my_register_name).INSTALLED) \
980      $(foreach f, $(LOCAL_SOONG_INSTALL_PAIRS),\
981        $(word 2,$(subst :,$(space),$(f)))) \
982      $(LOCAL_SOONG_INSTALL_SYMLINKS) \
983      $(my_init_rc_installed) \
984      $(my_installed_test_data) \
985      $(my_vintf_installed))
986
987  ALL_MODULES.$(my_register_name).INSTALLED_SYMLINKS := $(LOCAL_SOONG_INSTALL_SYMLINKS)
988
989  # Store the list of colon-separated pairs of the built and installed locations
990  # of files provided by this module.  Used by custom packaging rules like
991  # package-modules.mk that need to copy the built files to a custom install
992  # location during packaging.
993  #
994  # Translate copies from $(LOCAL_PREBUILT_MODULE_FILE) to $(LOCAL_BUILT_MODULE)
995  # so that package-modules.mk gets any transtive dependencies added to
996  # $(LOCAL_BUILT_MODULE), for example unstripped symbols files.
997  ALL_MODULES.$(my_register_name).BUILT_INSTALLED := \
998    $(strip $(ALL_MODULES.$(my_register_name).BUILT_INSTALLED) \
999      $(patsubst $(LOCAL_PREBUILT_MODULE_FILE):%,$(LOCAL_BUILT_MODULE):%,$(LOCAL_SOONG_INSTALL_PAIRS)) \
1000      $(my_init_rc_pairs) \
1001      $(my_test_data_pairs) \
1002      $(my_vintf_pairs))
1003  # Store the list of vintf/init_rc as order-only dependencies
1004  ALL_MODULES.$(my_register_name).ORDERONLY_INSTALLED := \
1005    $(strip $(ALL_MODULES.$(my_register_name).ORDERONLY_INSTALLED) \
1006      $(my_init_rc_installed) \
1007      $(my_vintf_installed))
1008else ifneq (true,$(LOCAL_UNINSTALLABLE_MODULE))
1009  ALL_MODULES.$(my_register_name).INSTALLED := \
1010    $(strip $(ALL_MODULES.$(my_register_name).INSTALLED) \
1011    $(LOCAL_INSTALLED_MODULE) $(my_init_rc_installed) $(my_installed_symlinks) \
1012    $(my_installed_test_data) $(my_vintf_installed))
1013  ALL_MODULES.$(my_register_name).BUILT_INSTALLED := \
1014    $(strip $(ALL_MODULES.$(my_register_name).BUILT_INSTALLED) \
1015    $(LOCAL_BUILT_MODULE):$(LOCAL_INSTALLED_MODULE) \
1016    $(my_init_rc_pairs) $(my_test_data_pairs) $(my_vintf_pairs))
1017  ALL_MODULES.$(my_register_name).ORDERONLY_INSTALLED := \
1018    $(strip $(ALL_MODULES.$(my_register_name).ORDERONLY_INSTALLED) \
1019      $(my_init_rc_installed) \
1020      $(my_vintf_installed))
1021endif
1022
1023# Mark LOCAL_SOONG_INSTALL_SYMLINKS as installed if we're installing any kind of module, not just
1024# ones that set LOCAL_SOONG_INSTALLED_MODULE. This is so we can have a soong module that only
1025# installs symlinks (e.g. installed_symlink). We can't set LOCAL_SOONG_INSTALLED_MODULE to a symlink
1026# because cp commands will fail on symlinks.
1027ifneq (,$(or $(LOCAL_SOONG_INSTALLED_MODULE),$(call boolean-not,$(LOCAL_UNINSTALLABLE_MODULE))))
1028  ALL_MODULES.$(my_register_name).INSTALLED += $(LOCAL_SOONG_INSTALL_SYMLINKS)
1029  ALL_MODULES.$(my_register_name).INSTALLED_SYMLINKS := $(LOCAL_SOONG_INSTALL_SYMLINKS)
1030endif
1031
1032ifdef LOCAL_PICKUP_FILES
1033# Files or directories ready to pick up by the build system
1034# when $(LOCAL_BUILT_MODULE) is done.
1035ALL_MODULES.$(my_register_name).PICKUP_FILES := \
1036    $(ALL_MODULES.$(my_register_name).PICKUP_FILES) $(LOCAL_PICKUP_FILES)
1037endif
1038# Record the platform availability of this module. Note that the availability is not
1039# meaningful for non-installable modules (e.g., static libs) or host modules.
1040# We only care about modules that are installable to the device.
1041ifeq (true,$(LOCAL_NOT_AVAILABLE_FOR_PLATFORM))
1042  ifneq (true,$(LOCAL_UNINSTALLABLE_MODULE))
1043    ifndef LOCAL_IS_HOST_MODULE
1044      ALL_MODULES.$(my_register_name).NOT_AVAILABLE_FOR_PLATFORM := true
1045    endif
1046  endif
1047endif
1048
1049my_required_modules := $(LOCAL_REQUIRED_MODULES) \
1050    $(LOCAL_REQUIRED_MODULES_$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH))
1051ifdef LOCAL_IS_HOST_MODULE
1052my_required_modules += $(LOCAL_REQUIRED_MODULES_$($(my_prefix)OS))
1053endif
1054
1055ifdef LOCAL_ACONFIG_FILES
1056  ALL_MODULES.$(my_register_name).ACONFIG_FILES := \
1057      $(ALL_MODULES.$(my_register_name).ACONFIG_FILES) $(LOCAL_ACONFIG_FILES)
1058endif
1059
1060ifndef LOCAL_SOONG_MODULE_INFO_JSON
1061  ALL_MAKE_MODULE_INFO_JSON_MODULES += $(my_register_name)
1062  ALL_MODULES.$(my_register_name).SHARED_LIBS := \
1063      $(ALL_MODULES.$(my_register_name).SHARED_LIBS) $(LOCAL_SHARED_LIBRARIES)
1064
1065  ALL_MODULES.$(my_register_name).STATIC_LIBS := \
1066      $(ALL_MODULES.$(my_register_name).STATIC_LIBS) $(LOCAL_STATIC_LIBRARIES)
1067
1068  ALL_MODULES.$(my_register_name).SYSTEM_SHARED_LIBS := \
1069      $(ALL_MODULES.$(my_register_name).SYSTEM_SHARED_LIBS) $(LOCAL_SYSTEM_SHARED_LIBRARIES)
1070
1071  ALL_MODULES.$(my_register_name).LOCAL_RUNTIME_LIBRARIES := \
1072      $(ALL_MODULES.$(my_register_name).LOCAL_RUNTIME_LIBRARIES) $(LOCAL_RUNTIME_LIBRARIES) \
1073      $(LOCAL_JAVA_LIBRARIES)
1074
1075  ALL_MODULES.$(my_register_name).LOCAL_STATIC_LIBRARIES := \
1076      $(ALL_MODULES.$(my_register_name).LOCAL_STATIC_LIBRARIES) $(LOCAL_STATIC_JAVA_LIBRARIES)
1077
1078  ifneq ($(my_test_data_file_pairs),)
1079    # Export the list of targets that are handled as data inputs and required
1080    # by tests at runtime. The format of my_test_data_file_pairs is
1081    # is $(path):$(relative_file) but for module-info, only the string after
1082    # ":" is needed.
1083    ALL_MODULES.$(my_register_name).TEST_DATA := \
1084      $(strip $(ALL_MODULES.$(my_register_name).TEST_DATA) \
1085        $(foreach f, $(my_test_data_file_pairs),\
1086          $(call word-colon,2,$(f))))
1087  endif
1088
1089  ifdef LOCAL_TEST_DATA_BINS
1090    ALL_MODULES.$(my_register_name).TEST_DATA_BINS := \
1091        $(ALL_MODULES.$(my_register_name).TEST_DATA_BINS) $(LOCAL_TEST_DATA_BINS)
1092  endif
1093
1094  ALL_MODULES.$(my_register_name).SUPPORTED_VARIANTS := \
1095      $(ALL_MODULES.$(my_register_name).SUPPORTED_VARIANTS) \
1096      $(filter-out $(ALL_MODULES.$(my_register_name).SUPPORTED_VARIANTS),$(my_supported_variant))
1097
1098  ALL_MODULES.$(my_register_name).COMPATIBILITY_SUITES := \
1099      $(ALL_MODULES.$(my_register_name).COMPATIBILITY_SUITES) $(LOCAL_COMPATIBILITY_SUITE)
1100  ALL_MODULES.$(my_register_name).MODULE_NAME := $(LOCAL_MODULE)
1101  ALL_MODULES.$(my_register_name).TEST_CONFIG := $(test_config)
1102  ALL_MODULES.$(my_register_name).EXTRA_TEST_CONFIGS := $(LOCAL_EXTRA_FULL_TEST_CONFIGS)
1103  ALL_MODULES.$(my_register_name).TEST_MAINLINE_MODULES := $(LOCAL_TEST_MAINLINE_MODULES)
1104  ifdef LOCAL_IS_UNIT_TEST
1105    ALL_MODULES.$(my_register_name).IS_UNIT_TEST := $(LOCAL_IS_UNIT_TEST)
1106  endif
1107  ifdef LOCAL_TEST_OPTIONS_TAGS
1108    ALL_MODULES.$(my_register_name).TEST_OPTIONS_TAGS := $(LOCAL_TEST_OPTIONS_TAGS)
1109  endif
1110
1111  ##########################################################
1112  # Track module-level dependencies.
1113  # (b/204397180) Unlock RECORD_ALL_DEPS was acknowledged reasonable for better Atest performance.
1114  ALL_MODULES.$(my_register_name).ALL_DEPS := \
1115    $(ALL_MODULES.$(my_register_name).ALL_DEPS) \
1116    $(LOCAL_STATIC_LIBRARIES) \
1117    $(LOCAL_WHOLE_STATIC_LIBRARIES) \
1118    $(LOCAL_SHARED_LIBRARIES) \
1119    $(LOCAL_DYLIB_LIBRARIES) \
1120    $(LOCAL_RLIB_LIBRARIES) \
1121    $(LOCAL_PROC_MACRO_LIBRARIES) \
1122    $(LOCAL_HEADER_LIBRARIES) \
1123    $(LOCAL_STATIC_JAVA_LIBRARIES) \
1124    $(LOCAL_JAVA_LIBRARIES) \
1125    $(LOCAL_JNI_SHARED_LIBRARIES)
1126
1127endif
1128ALL_MODULES.$(my_register_name).TEST_MODULE_CONFIG_BASE := $(LOCAL_TEST_MODULE_CONFIG_BASE)
1129
1130##########################################################################
1131## When compiling against API imported module, use API import stub
1132## libraries.
1133##########################################################################
1134ifneq ($(call module-in-vendor-or-product),)
1135  ifneq ($(LOCAL_MODULE_MAKEFILE),$(SOONG_ANDROID_MK))
1136    apiimport_postfix := .apiimport
1137    ifeq ($(LOCAL_IN_PRODUCT),true)
1138      apiimport_postfix := .apiimport.product
1139    else
1140      apiimport_postfix := .apiimport.vendor
1141    endif
1142
1143    my_required_modules := $(foreach l,$(my_required_modules), \
1144      $(if $(filter $(l), $(API_IMPORTED_SHARED_LIBRARIES)), $(l)$(apiimport_postfix), $(l)))
1145  endif
1146endif
1147
1148##########################################################################
1149## When compiling against the VNDK, add the .vendor or .product suffix to
1150## required modules.
1151##########################################################################
1152ifneq ($(call module-in-vendor-or-product),)
1153  #####################################################
1154  ## Soong modules may be built three times, once for
1155  ## /system, once for /vendor and once for /product.
1156  ## If we're using the VNDK, switch all soong
1157  ## libraries over to the /vendor or /product variant.
1158  #####################################################
1159  ifneq ($(LOCAL_MODULE_MAKEFILE),$(SOONG_ANDROID_MK))
1160    # We don't do this renaming for soong-defined modules since they already
1161    # have correct names (with .vendor or .product suffix when necessary) in
1162    # their LOCAL_*_LIBRARIES.
1163    ifeq ($(LOCAL_IN_PRODUCT),true)
1164      my_required_modules := $(foreach l,$(my_required_modules),\
1165        $(if $(SPLIT_PRODUCT.SHARED_LIBRARIES.$(l)),$(l).product,$(l)))
1166    else
1167      my_required_modules := $(foreach l,$(my_required_modules),\
1168        $(if $(SPLIT_VENDOR.SHARED_LIBRARIES.$(l)),$(l).vendor,$(l)))
1169    endif
1170  endif
1171endif
1172
1173ifdef LOCAL_IS_HOST_MODULE
1174    ifneq ($(my_host_cross),true)
1175        ALL_MODULES.$(my_register_name).REQUIRED_FROM_HOST := \
1176            $(strip $(ALL_MODULES.$(my_register_name).REQUIRED_FROM_HOST) $(my_required_modules))
1177        ALL_MODULES.$(my_register_name).EXPLICITLY_REQUIRED_FROM_HOST := \
1178            $(strip $(ALL_MODULES.$(my_register_name).EXPLICITLY_REQUIRED_FROM_HOST)\
1179                $(my_required_modules))
1180        ALL_MODULES.$(my_register_name).TARGET_REQUIRED_FROM_HOST := \
1181            $(strip $(ALL_MODULES.$(my_register_name).TARGET_REQUIRED_FROM_HOST)\
1182                $(LOCAL_TARGET_REQUIRED_MODULES))
1183    else
1184        ALL_MODULES.$(my_register_name).REQUIRED_FROM_HOST_CROSS := \
1185            $(strip $(ALL_MODULES.$(my_register_name).REQUIRED_FROM_HOST_CROSS) $(my_required_modules))
1186        ALL_MODULES.$(my_register_name).EXPLICITLY_REQUIRED_FROM_HOST_CROSS := \
1187            $(strip $(ALL_MODULES.$(my_register_name).EXPLICITLY_REQUIRED_FROM_HOST_CROSS)\
1188                $(my_required_modules))
1189        ifdef LOCAL_TARGET_REQUIRED_MODULES
1190            $(call pretty-error,LOCAL_TARGET_REQUIRED_MODULES may not be used from host_cross modules)
1191        endif
1192    endif
1193    ifdef LOCAL_HOST_REQUIRED_MODULES
1194        $(call pretty-error,LOCAL_HOST_REQUIRED_MODULES may not be used from host modules. Use LOCAL_REQUIRED_MODULES instead)
1195    endif
1196else
1197    ALL_MODULES.$(my_register_name).REQUIRED_FROM_TARGET := \
1198        $(strip $(ALL_MODULES.$(my_register_name).REQUIRED_FROM_TARGET) $(my_required_modules))
1199    ALL_MODULES.$(my_register_name).EXPLICITLY_REQUIRED_FROM_TARGET := \
1200        $(strip $(ALL_MODULES.$(my_register_name).EXPLICITLY_REQUIRED_FROM_TARGET)\
1201            $(my_required_modules))
1202    ALL_MODULES.$(my_register_name).HOST_REQUIRED_FROM_TARGET := \
1203        $(strip $(ALL_MODULES.$(my_register_name).HOST_REQUIRED_FROM_TARGET)\
1204            $(LOCAL_HOST_REQUIRED_MODULES))
1205    ifdef LOCAL_TARGET_REQUIRED_MODULES
1206        $(call pretty-error,LOCAL_TARGET_REQUIRED_MODULES may not be used from target modules. Use LOCAL_REQUIRED_MODULES instead)
1207    endif
1208endif
1209
1210ifdef event_log_tags
1211  ALL_MODULES.$(my_register_name).EVENT_LOG_TAGS := \
1212      $(ALL_MODULES.$(my_register_name).EVENT_LOG_TAGS) $(event_log_tags)
1213endif
1214
1215ALL_MODULES.$(my_register_name).MAKEFILE := \
1216    $(ALL_MODULES.$(my_register_name).MAKEFILE) $(LOCAL_MODULE_MAKEFILE)
1217
1218ifdef LOCAL_MODULE_OWNER
1219  ALL_MODULES.$(my_register_name).OWNER := \
1220      $(sort $(ALL_MODULES.$(my_register_name).OWNER) $(LOCAL_MODULE_OWNER))
1221endif
1222
1223ifdef LOCAL_2ND_ARCH_VAR_PREFIX
1224ALL_MODULES.$(my_register_name).FOR_2ND_ARCH := true
1225endif
1226ALL_MODULES.$(my_register_name).FOR_HOST_CROSS := $(my_host_cross)
1227ifndef LOCAL_IS_HOST_MODULE
1228ALL_MODULES.$(my_register_name).APEX_KEYS_FILE := $(LOCAL_APEX_KEY_PATH)
1229endif
1230test_config :=
1231
1232INSTALLABLE_FILES.$(LOCAL_INSTALLED_MODULE).MODULE := $(my_register_name)
1233
1234###########################################################
1235## umbrella targets used to verify builds
1236###########################################################
1237j_or_n :=
1238ifneq (,$(filter EXECUTABLES SHARED_LIBRARIES STATIC_LIBRARIES HEADER_LIBRARIES NATIVE_TESTS RLIB_LIBRARIES DYLIB_LIBRARIES PROC_MACRO_LIBRARIES,$(LOCAL_MODULE_CLASS)))
1239j_or_n := native
1240else
1241ifneq (,$(filter JAVA_LIBRARIES APPS,$(LOCAL_MODULE_CLASS)))
1242j_or_n := java
1243endif
1244endif
1245ifdef LOCAL_IS_HOST_MODULE
1246h_or_t := host
1247ifeq ($(my_host_cross),true)
1248h_or_hc_or_t := host-cross
1249else
1250h_or_hc_or_t := host
1251endif
1252else
1253h_or_hc_or_t := target
1254h_or_t := target
1255endif
1256
1257
1258ifdef j_or_n
1259$(j_or_n) $(h_or_t) $(j_or_n)-$(h_or_hc_or_t) : $(my_checked_module)
1260ifneq (,$(filter $(LOCAL_MODULE_TAGS),tests))
1261$(j_or_n)-$(h_or_t)-tests $(j_or_n)-tests $(h_or_t)-tests : $(my_checked_module)
1262endif
1263$(LOCAL_MODULE)-$(h_or_hc_or_t) : $(my_all_targets)
1264.PHONY: $(LOCAL_MODULE)-$(h_or_hc_or_t)
1265ifeq ($(j_or_n),native)
1266$(LOCAL_MODULE)-$(h_or_hc_or_t)$(my_32_64_bit_suffix) : $(my_all_targets)
1267.PHONY: $(LOCAL_MODULE)-$(h_or_hc_or_t)$(my_32_64_bit_suffix)
1268endif
1269endif
1270
1271###########################################################
1272# Ensure privileged applications always have LOCAL_PRIVILEGED_MODULE
1273###########################################################
1274ifndef LOCAL_PRIVILEGED_MODULE
1275  ifneq (,$(filter $(TARGET_OUT_APPS_PRIVILEGED)/% $(TARGET_OUT_VENDOR_APPS_PRIVILEGED)/%,$(my_module_path)))
1276    LOCAL_PRIVILEGED_MODULE := true
1277  endif
1278endif
1279
1280###########################################################
1281## NOTICE files
1282###########################################################
1283
1284include $(BUILD_NOTICE_FILE)
1285
1286###########################################################
1287## SBOM generation
1288###########################################################
1289include $(BUILD_SBOM_GEN)
1290