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