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$(if $(base-rules-hook),) 24endif 25 26########################################################### 27## Common instructions for a generic module. 28########################################################### 29 30LOCAL_MODULE := $(strip $(LOCAL_MODULE)) 31ifeq ($(LOCAL_MODULE),) 32 $(error $(LOCAL_PATH): LOCAL_MODULE is not defined) 33endif 34 35LOCAL_IS_HOST_MODULE := $(strip $(LOCAL_IS_HOST_MODULE)) 36LOCAL_IS_AUX_MODULE := $(strip $(LOCAL_IS_AUX_MODULE)) 37ifdef LOCAL_IS_HOST_MODULE 38 ifneq ($(LOCAL_IS_HOST_MODULE),true) 39 $(error $(LOCAL_PATH): LOCAL_IS_HOST_MODULE must be "true" or empty, not "$(LOCAL_IS_HOST_MODULE)") 40 endif 41 ifeq ($(LOCAL_HOST_PREFIX),) 42 my_prefix := HOST_ 43 else 44 my_prefix := $(LOCAL_HOST_PREFIX) 45 endif 46 my_host := host- 47 my_kind := HOST 48else 49 ifdef LOCAL_IS_AUX_MODULE 50 ifneq ($(LOCAL_IS_AUX_MODULE),true) 51 $(error $(LOCAL_PATH): LOCAL_IS_AUX_MODULE must be "true" or empty, not "$(LOCAL_IS_AUX_MODULE)") 52 endif 53 my_prefix := AUX_ 54 my_kind := AUX 55 else 56 my_prefix := TARGET_ 57 my_kind := 58 endif 59 my_host := 60endif 61 62ifeq ($(my_prefix),HOST_CROSS_) 63 my_host_cross := true 64else 65 my_host_cross := 66endif 67 68_path := $(LOCAL_MODULE_PATH) $(LOCAL_MODULE_PATH_32) $(LOCAL_MODULE_PATH_64) 69ifneq ($(filter $(TARGET_OUT_VENDOR)%,$(_path)),) 70LOCAL_VENDOR_MODULE := true 71else ifneq ($(filter $(TARGET_OUT_OEM)/%,$(_path)),) 72LOCAL_OEM_MODULE := true 73else ifneq ($(filter $(TARGET_OUT_ODM)/%,$(_path)),) 74LOCAL_ODM_MODULE := true 75else ifneq ($(filter $(TARGET_OUT_PRODUCT)/%,$(_path)),) 76LOCAL_PRODUCT_MODULE := true 77endif 78_path := 79 80ifndef LOCAL_PROPRIETARY_MODULE 81 LOCAL_PROPRIETARY_MODULE := $(LOCAL_VENDOR_MODULE) 82endif 83ifndef LOCAL_VENDOR_MODULE 84 LOCAL_VENDOR_MODULE := $(LOCAL_PROPRIETARY_MODULE) 85endif 86ifneq ($(filter-out $(LOCAL_PROPRIETARY_MODULE),$(LOCAL_VENDOR_MODULE))$(filter-out $(LOCAL_VENDOR_MODULE),$(LOCAL_PROPRIETARY_MODULE)),) 87$(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) 88endif 89 90include $(BUILD_SYSTEM)/local_vndk.mk 91include $(BUILD_SYSTEM)/local_systemsdk.mk 92 93my_module_tags := $(LOCAL_MODULE_TAGS) 94ifeq ($(my_host_cross),true) 95 my_module_tags := 96endif 97ifeq ($(TARGET_TRANSLATE_2ND_ARCH),true) 98ifdef LOCAL_2ND_ARCH_VAR_PREFIX 99# Don't pull in modules by tags if this is for translation TARGET_2ND_ARCH. 100 my_module_tags := 101endif 102endif 103 104# Ninja has an implicit dependency on the command being run, and kati will 105# regenerate the ninja manifest if any read makefile changes, so there is no 106# need to have dependencies on makefiles. 107# This won't catch all the cases where LOCAL_ADDITIONAL_DEPENDENCIES contains 108# a .mk file, because a few users of LOCAL_ADDITIONAL_DEPENDENCIES don't include 109# base_rules.mk, but it will fix the most common ones. 110LOCAL_ADDITIONAL_DEPENDENCIES := $(filter-out %.mk,$(LOCAL_ADDITIONAL_DEPENDENCIES)) 111 112my_bad_deps := $(strip $(foreach dep,$(filter-out | ||,$(LOCAL_ADDITIONAL_DEPENDENCIES)),\ 113 $(if $(findstring /,$(dep)),,$(dep)))) 114ifneq ($(my_bad_deps),) 115$(call pretty-warning,"Bad LOCAL_ADDITIONAL_DEPENDENCIES: $(my_bad_deps)") 116$(call pretty-error,"LOCAL_ADDITIONAL_DEPENDENCIES must only contain paths (not module names)") 117endif 118 119########################################################### 120## Validate and define fallbacks for input LOCAL_* variables. 121########################################################### 122 123## Dump a .csv file of all modules and their tags 124#ifneq ($(tag-list-first-time),false) 125#$(shell rm -f tag-list.csv) 126#tag-list-first-time := false 127#endif 128#$(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) 129 130LOCAL_UNINSTALLABLE_MODULE := $(strip $(LOCAL_UNINSTALLABLE_MODULE)) 131my_module_tags := $(sort $(my_module_tags)) 132ifeq (,$(my_module_tags)) 133 my_module_tags := optional 134endif 135 136# User tags are not allowed anymore. Fail early because it will not be installed 137# like it used to be. 138ifneq ($(filter $(my_module_tags),user),) 139 $(warning *** Module name: $(LOCAL_MODULE)) 140 $(warning *** Makefile location: $(LOCAL_MODULE_MAKEFILE)) 141 $(warning * ) 142 $(warning * Module is attempting to use the 'user' tag. This) 143 $(warning * used to cause the module to be installed automatically.) 144 $(warning * Now, the module must be listed in the PRODUCT_PACKAGES) 145 $(warning * section of a product makefile to have it installed.) 146 $(warning * ) 147 $(error user tag detected on module.) 148endif 149 150# Only the tags mentioned in this test are expected to be set by module 151# makefiles. Anything else is either a typo or a source of unexpected 152# behaviors. 153ifneq ($(filter-out debug eng tests optional samples,$(my_module_tags)),) 154$(call pretty-error,unusual tags: $(filter-out debug eng tests optional samples,$(my_module_tags))) 155endif 156 157# Add implicit tags. 158# 159# If the local directory or one of its parents contains a MODULE_LICENSE_GPL 160# file, tag the module as "gnu". Search for "*_GPL*", "*_LGPL*" and "*_MPL*" 161# so that we can also find files like MODULE_LICENSE_GPL_AND_AFL 162# 163license_files := $(call find-parent-file,$(LOCAL_PATH),MODULE_LICENSE*) 164gpl_license_file := $(call find-parent-file,$(LOCAL_PATH),MODULE_LICENSE*_GPL* MODULE_LICENSE*_MPL* MODULE_LICENSE*_LGPL*) 165ifneq ($(gpl_license_file),) 166 my_module_tags += gnu 167 ALL_GPL_MODULE_LICENSE_FILES := $(sort $(ALL_GPL_MODULE_LICENSE_FILES) $(gpl_license_file)) 168endif 169 170LOCAL_MODULE_CLASS := $(strip $(LOCAL_MODULE_CLASS)) 171ifneq ($(words $(LOCAL_MODULE_CLASS)),1) 172 $(error $(LOCAL_PATH): LOCAL_MODULE_CLASS must contain exactly one word, not "$(LOCAL_MODULE_CLASS)") 173endif 174 175my_32_64_bit_suffix := $(if $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)IS_64_BIT),64,32) 176 177ifneq (true,$(LOCAL_UNINSTALLABLE_MODULE)) 178ifeq ($(TARGET_TRANSLATE_2ND_ARCH),true) 179# When in TARGET_TRANSLATE_2ND_ARCH both TARGET_ARCH and TARGET_2ND_ARCH are 32-bit, 180# to avoid path conflict we force using LOCAL_MODULE_PATH_64 for the first arch. 181ifdef LOCAL_2ND_ARCH_VAR_PREFIX 182my_multilib_module_path := $(LOCAL_MODULE_PATH_32) 183else # ! LOCAL_2ND_ARCH_VAR_PREFIX 184my_multilib_module_path := $(LOCAL_MODULE_PATH_64) 185endif # ! LOCAL_2ND_ARCH_VAR_PREFIX 186else # ! TARGET_TRANSLATE_2ND_ARCH 187my_multilib_module_path := $(strip $(LOCAL_MODULE_PATH_$(my_32_64_bit_suffix))) 188endif # ! TARGET_TRANSLATE_2ND_ARCH 189ifdef my_multilib_module_path 190my_module_path := $(my_multilib_module_path) 191else 192my_module_path := $(strip $(LOCAL_MODULE_PATH)) 193endif 194my_module_path := $(patsubst %/,%,$(my_module_path)) 195my_module_relative_path := $(strip $(LOCAL_MODULE_RELATIVE_PATH)) 196ifdef LOCAL_IS_HOST_MODULE 197 partition_tag := 198else 199ifeq (true,$(LOCAL_VENDOR_MODULE)) 200 partition_tag := _VENDOR 201else ifeq (true,$(LOCAL_OEM_MODULE)) 202 partition_tag := _OEM 203else ifeq (true,$(LOCAL_ODM_MODULE)) 204 partition_tag := _ODM 205else ifeq (true,$(LOCAL_PRODUCT_MODULE)) 206 partition_tag := _PRODUCT 207else ifeq (NATIVE_TESTS,$(LOCAL_MODULE_CLASS)) 208 partition_tag := _DATA 209else 210 # The definition of should-install-to-system will be different depending 211 # on which goal (e.g., sdk or just droid) is being built. 212 partition_tag := $(if $(call should-install-to-system,$(my_module_tags)),,_DATA) 213endif 214endif 215ifeq ($(my_module_path),) 216 install_path_var := $(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)OUT$(partition_tag)_$(LOCAL_MODULE_CLASS) 217 ifeq (true,$(LOCAL_PRIVILEGED_MODULE)) 218 install_path_var := $(install_path_var)_PRIVILEGED 219 endif 220 221 my_module_path := $($(install_path_var)) 222 ifeq ($(strip $(my_module_path)),) 223 $(error $(LOCAL_PATH): unhandled install path "$(install_path_var) for $(LOCAL_MODULE)") 224 endif 225endif 226ifneq ($(my_module_relative_path),) 227 my_module_path := $(my_module_path)/$(my_module_relative_path) 228endif 229endif # not LOCAL_UNINSTALLABLE_MODULE 230 231ifneq ($(strip $(LOCAL_BUILT_MODULE)$(LOCAL_INSTALLED_MODULE)),) 232 $(error $(LOCAL_PATH): LOCAL_BUILT_MODULE and LOCAL_INSTALLED_MODULE must not be defined by component makefiles) 233endif 234 235my_register_name := $(LOCAL_MODULE) 236ifeq ($(my_host_cross),true) 237 my_register_name := host_cross_$(LOCAL_MODULE) 238endif 239ifdef LOCAL_2ND_ARCH_VAR_PREFIX 240ifndef LOCAL_NO_2ND_ARCH_MODULE_SUFFIX 241my_register_name := $(my_register_name)$($(my_prefix)2ND_ARCH_MODULE_SUFFIX) 242endif 243endif 244 245ifeq ($(my_host_cross),true) 246 my_all_targets := host_cross_$(my_register_name)_all_targets 247else ifneq ($(LOCAL_IS_HOST_MODULE),) 248 my_all_targets := host_$(my_register_name)_all_targets 249else 250 my_all_targets := device_$(my_register_name)_all_targets 251endif 252 253# variant is enough to make nano class unique; it serves as a key to lookup (OS,ARCH) tuple 254aux_class := $($(my_prefix)OS_VARIANT) 255# Make sure that this IS_HOST/CLASS/MODULE combination is unique. 256module_id := MODULE.$(if \ 257 $(LOCAL_IS_HOST_MODULE),$($(my_prefix)OS),$(if \ 258 $(LOCAL_IS_AUX_MODULE),$(aux_class),TARGET)).$(LOCAL_MODULE_CLASS).$(my_register_name) 259ifdef $(module_id) 260$(error $(LOCAL_PATH): $(module_id) already defined by $($(module_id))) 261endif 262$(module_id) := $(LOCAL_PATH) 263 264intermediates := $(call local-intermediates-dir,,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross)) 265intermediates.COMMON := $(call local-intermediates-dir,COMMON) 266generated_sources_dir := $(call local-generated-sources-dir) 267 268ifneq ($(LOCAL_OVERRIDES_MODULES),) 269 ifeq ($(LOCAL_MODULE_CLASS),EXECUTABLES) 270 ifndef LOCAL_IS_HOST_MODULE 271 EXECUTABLES.$(LOCAL_MODULE).OVERRIDES := $(strip $(LOCAL_OVERRIDES_MODULES)) 272 else 273 $(call pretty-error,host modules cannot use LOCAL_OVERRIDES_MODULES) 274 endif 275 else 276 $(call pretty-error,LOCAL_MODULE_CLASS := $(LOCAL_MODULE_CLASS) cannot use LOCAL_OVERRIDES_MODULES) 277 endif 278endif 279 280########################################################### 281# Pick a name for the intermediate and final targets 282########################################################### 283include $(BUILD_SYSTEM)/configure_module_stem.mk 284 285LOCAL_BUILT_MODULE := $(intermediates)/$(my_built_module_stem) 286 287# OVERRIDE_BUILT_MODULE_PATH is only allowed to be used by the 288# internal SHARED_LIBRARIES build files. 289OVERRIDE_BUILT_MODULE_PATH := $(strip $(OVERRIDE_BUILT_MODULE_PATH)) 290ifdef OVERRIDE_BUILT_MODULE_PATH 291 ifneq ($(LOCAL_MODULE_CLASS),SHARED_LIBRARIES) 292 $(error $(LOCAL_PATH): Illegal use of OVERRIDE_BUILT_MODULE_PATH) 293 endif 294 $(eval $(call copy-one-file,$(LOCAL_BUILT_MODULE),$(OVERRIDE_BUILT_MODULE_PATH)/$(my_built_module_stem))) 295endif 296 297ifneq (true,$(LOCAL_UNINSTALLABLE_MODULE)) 298 # Apk and its attachments reside in its own subdir. 299 ifeq ($(LOCAL_MODULE_CLASS),APPS) 300 # framework-res.apk doesn't like the additional layer. 301 ifeq ($(LOCAL_NO_STANDARD_LIBRARIES),true) 302 # Neither do Runtime Resource Overlay apks, which contain just the overlaid resources. 303 else ifeq ($(LOCAL_IS_RUNTIME_RESOURCE_OVERLAY),true) 304 else 305 my_module_path := $(my_module_path)/$(LOCAL_MODULE) 306 endif 307 endif 308 LOCAL_INSTALLED_MODULE := $(my_module_path)/$(my_installed_module_stem) 309endif 310 311# Assemble the list of targets to create PRIVATE_ variables for. 312LOCAL_INTERMEDIATE_TARGETS += $(LOCAL_BUILT_MODULE) 313 314########################################################### 315## Create .toc files from shared objects to reduce unnecessary rebuild 316# .toc files have the list of external dynamic symbols without their addresses. 317# As .KATI_RESTAT is specified to .toc files and commit-change-for-toc is used, 318# dependent binaries of a .toc file will be rebuilt only when the content of 319# the .toc file is changed. 320########################################################### 321ifeq ($(LOCAL_MODULE_CLASS),SHARED_LIBRARIES) 322LOCAL_INTERMEDIATE_TARGETS += $(LOCAL_BUILT_MODULE).toc 323$(LOCAL_BUILT_MODULE).toc: $(LOCAL_BUILT_MODULE) 324 $(call $(PRIVATE_2ND_ARCH_VAR_PREFIX)$(PRIVATE_PREFIX)transform-shared-lib-to-toc,$<,$@.tmp) 325 $(call commit-change-for-toc,$@) 326 327# Kati adds restat=1 to ninja. GNU make does nothing for this. 328.KATI_RESTAT: $(LOCAL_BUILT_MODULE).toc 329# Build .toc file when using mm, mma, or make $(my_register_name) 330$(my_all_targets): $(LOCAL_BUILT_MODULE).toc 331 332ifdef OVERRIDE_BUILT_MODULE_PATH 333$(eval $(call copy-one-file,$(LOCAL_BUILT_MODULE).toc,$(OVERRIDE_BUILT_MODULE_PATH)/$(my_built_module_stem).toc)) 334$(OVERRIDE_BUILT_MODULE_PATH)/$(my_built_module_stem).toc: $(OVERRIDE_BUILT_MODULE_PATH)/$(my_built_module_stem) 335endif 336endif 337 338########################################################### 339## logtags: Add .logtags files to global list 340########################################################### 341 342logtags_sources := $(filter %.logtags,$(LOCAL_SRC_FILES)) $(LOCAL_LOGTAGS_FILES) 343 344ifneq ($(strip $(logtags_sources)),) 345event_log_tags := $(addprefix $(LOCAL_PATH)/,$(logtags_sources)) 346else 347event_log_tags := 348endif 349 350########################################################### 351## make clean- targets 352########################################################### 353cleantarget := clean-$(my_register_name) 354$(cleantarget) : PRIVATE_MODULE := $(my_register_name) 355$(cleantarget) : PRIVATE_CLEAN_FILES := \ 356 $(LOCAL_BUILT_MODULE) \ 357 $(LOCAL_INSTALLED_MODULE) \ 358 $(intermediates) 359$(cleantarget):: 360 @echo "Clean: $(PRIVATE_MODULE)" 361 $(hide) rm -rf $(PRIVATE_CLEAN_FILES) 362 363########################################################### 364## Common definitions for module. 365########################################################### 366$(LOCAL_INTERMEDIATE_TARGETS) : PRIVATE_PATH:=$(LOCAL_PATH) 367$(LOCAL_INTERMEDIATE_TARGETS) : PRIVATE_IS_HOST_MODULE := $(LOCAL_IS_HOST_MODULE) 368$(LOCAL_INTERMEDIATE_TARGETS) : PRIVATE_IS_AUX_MODULE := $(LOCAL_IS_AUX_MODULE) 369$(LOCAL_INTERMEDIATE_TARGETS) : PRIVATE_HOST:= $(my_host) 370$(LOCAL_INTERMEDIATE_TARGETS) : PRIVATE_PREFIX := $(my_prefix) 371 372$(LOCAL_INTERMEDIATE_TARGETS) : PRIVATE_INTERMEDIATES_DIR:= $(intermediates) 373$(LOCAL_INTERMEDIATE_TARGETS) : PRIVATE_2ND_ARCH_VAR_PREFIX := $(LOCAL_2ND_ARCH_VAR_PREFIX) 374 375# Tell the module and all of its sub-modules who it is. 376$(LOCAL_INTERMEDIATE_TARGETS) : PRIVATE_MODULE:= $(my_register_name) 377 378# Provide a short-hand for building this module. 379# We name both BUILT and INSTALLED in case 380# LOCAL_UNINSTALLABLE_MODULE is set. 381.PHONY: $(my_all_targets) 382$(my_all_targets): $(LOCAL_BUILT_MODULE) $(LOCAL_INSTALLED_MODULE) 383 384.PHONY: $(my_register_name) 385$(my_register_name): $(my_all_targets) 386 387ifneq ($(my_register_name),$(LOCAL_MODULE)) 388# $(LOCAL_MODULE) covers all the multilib targets. 389.PHONY: $(LOCAL_MODULE) 390$(LOCAL_MODULE) : $(my_all_targets) 391endif 392 393# Set up phony targets that covers all modules under the given paths. 394# This allows us to build everything in given paths by running mmma/mma. 395my_path_components := $(subst /,$(space),$(LOCAL_PATH)) 396my_path_prefix := MODULES-IN 397$(foreach c, $(my_path_components),\ 398 $(eval my_path_prefix := $(my_path_prefix)-$(c))\ 399 $(eval .PHONY : $(my_path_prefix))\ 400 $(eval $(my_path_prefix) : $(my_all_targets))) 401 402########################################################### 403## Module installation rule 404########################################################### 405 406my_init_rc_installed := 407my_init_rc_pairs := 408my_installed_symlinks := 409ifneq (true,$(LOCAL_UNINSTALLABLE_MODULE)) 410$(LOCAL_INSTALLED_MODULE): PRIVATE_POST_INSTALL_CMD := $(LOCAL_POST_INSTALL_CMD) 411$(LOCAL_INSTALLED_MODULE): $(LOCAL_BUILT_MODULE) 412 @echo "Install: $@" 413 $(copy-file-to-new-target) 414 $(PRIVATE_POST_INSTALL_CMD) 415 416ifndef LOCAL_IS_HOST_MODULE 417# Rule to install the module's companion init.rc. 418my_init_rc := $(LOCAL_INIT_RC_$(my_32_64_bit_suffix)) $(LOCAL_INIT_RC) 419ifneq ($(strip $(my_init_rc)),) 420my_init_rc_pairs := $(foreach rc,$(my_init_rc),$(LOCAL_PATH)/$(rc):$(TARGET_OUT$(partition_tag)_ETC)/init/$(notdir $(rc))) 421my_init_rc_installed := $(foreach rc,$(my_init_rc_pairs),$(call word-colon,2,$(rc))) 422 423# Make sure we only set up the copy rules once, even if another arch variant 424# shares a common LOCAL_INIT_RC. 425my_init_rc_new_pairs := $(filter-out $(ALL_INIT_RC_INSTALLED_PAIRS),$(my_init_rc_pairs)) 426my_init_rc_new_installed := $(call copy-many-files,$(my_init_rc_new_pairs)) 427ALL_INIT_RC_INSTALLED_PAIRS += $(my_init_rc_new_pairs) 428 429$(my_all_targets) : $(my_init_rc_installed) 430endif # my_init_rc 431endif # !LOCAL_IS_HOST_MODULE 432 433# Rule to install the module's companion symlinks 434my_installed_symlinks := $(addprefix $(my_module_path)/,$(LOCAL_MODULE_SYMLINKS) $(LOCAL_MODULE_SYMLINKS_$(my_32_64_bit_suffix))) 435$(foreach symlink,$(my_installed_symlinks),\ 436 $(call symlink-file,$(LOCAL_INSTALLED_MODULE),$(my_installed_module_stem),$(symlink))) 437 438$(my_all_targets) : | $(my_installed_symlinks) 439 440endif # !LOCAL_UNINSTALLABLE_MODULE 441 442########################################################### 443## CHECK_BUILD goals 444########################################################### 445my_checked_module := 446# If nobody has defined a more specific module for the 447# checked modules, use LOCAL_BUILT_MODULE. 448ifdef LOCAL_CHECKED_MODULE 449 my_checked_module := $(LOCAL_CHECKED_MODULE) 450else 451 my_checked_module := $(LOCAL_BUILT_MODULE) 452endif 453 454# If they request that this module not be checked, then don't. 455# PLEASE DON'T SET THIS. ANY PLACES THAT SET THIS WITHOUT 456# GOOD REASON WILL HAVE IT REMOVED. 457ifdef LOCAL_DONT_CHECK_MODULE 458 my_checked_module := 459endif 460# Don't check build target module defined for the 2nd arch 461ifndef LOCAL_IS_HOST_MODULE 462ifdef LOCAL_2ND_ARCH_VAR_PREFIX 463 my_checked_module := 464endif 465endif 466 467########################################################### 468## Test Data 469########################################################### 470my_test_data_pairs := 471my_installed_test_data := 472# Source to relative dst file paths for reuse in LOCAL_COMPATIBILITY_SUITE. 473my_test_data_file_pairs := 474 475ifneq ($(filter NATIVE_TESTS,$(LOCAL_MODULE_CLASS)),) 476ifneq ($(strip $(LOCAL_TEST_DATA)),) 477ifneq (true,$(LOCAL_UNINSTALLABLE_MODULE)) 478 479my_test_data_pairs := $(strip $(foreach td,$(LOCAL_TEST_DATA), \ 480 $(eval _file := $(call word-colon,2,$(td))) \ 481 $(if $(_file), \ 482 $(eval _src_base := $(call word-colon,1,$(td))), \ 483 $(eval _src_base := $(LOCAL_PATH)) \ 484 $(eval _file := $(call word-colon,1,$(td)))) \ 485 $(if $(findstring ..,$(_file)),$(error $(LOCAL_MODULE_MAKEFILE): LOCAL_TEST_DATA may not include '..': $(_file))) \ 486 $(if $(filter /%,$(_src_base) $(_file)),$(error $(LOCAL_MODULE_MAKEFILE): LOCAL_TEST_DATA may not include absolute paths: $(_src_base) $(_file))) \ 487 $(eval my_test_data_file_pairs := $(my_test_data_file_pairs) $(call append-path,$(_src_base),$(_file)):$(_file)) \ 488 $(call append-path,$(_src_base),$(_file)):$(call append-path,$(my_module_path),$(_file)))) 489 490my_installed_test_data := $(call copy-many-files,$(my_test_data_pairs)) 491$(LOCAL_INSTALLED_MODULE): $(my_installed_test_data) 492 493endif 494endif 495endif 496 497# For test modules that lack a suite tag, set null-suite as the default. 498# We only support adding a default suite to native tests, native benchmarks, and instrumentation tests. 499# This is because they are the only tests we currently auto-generate test configs for. 500ifndef LOCAL_COMPATIBILITY_SUITE 501ifneq ($(filter NATIVE_TESTS NATIVE_BENCHMARK, $(LOCAL_MODULE_CLASS)),) 502LOCAL_COMPATIBILITY_SUITE := null-suite 503endif 504ifneq ($(filter APPS, $(LOCAL_MODULE_CLASS)),) 505ifneq ($(filter $(my_module_tags),tests),) 506LOCAL_COMPATIBILITY_SUITE := null-suite 507endif 508endif 509endif 510 511########################################################### 512## Compatibility suite files. 513########################################################### 514ifdef LOCAL_COMPATIBILITY_SUITE 515 516# If we are building a native test or benchmark and its stem variants are not defined, 517# separate the multiple architectures into subdirectories of the testcase folder. 518arch_dir := 519is_native := 520multi_arch := 521ifeq ($(LOCAL_MODULE_CLASS),NATIVE_TESTS) 522 is_native := true 523 multi_arch := true 524endif 525ifeq ($(LOCAL_MODULE_CLASS),NATIVE_BENCHMARK) 526 is_native := true 527 multi_arch := true 528endif 529ifdef LOCAL_MULTILIB 530 multi_arch := true 531endif 532ifdef multi_arch 533 arch_dir := /$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH) 534endif 535multi_arch := 536 537# The module itself. 538$(foreach suite, $(LOCAL_COMPATIBILITY_SUITE), \ 539 $(eval my_compat_dist_$(suite) := $(foreach dir, $(call compatibility_suite_dirs,$(suite),$(arch_dir)), \ 540 $(LOCAL_BUILT_MODULE):$(dir)/$(my_installed_module_stem)))) 541 542# Make sure we only add the files once for multilib modules. 543ifndef $(my_prefix)$(LOCAL_MODULE_CLASS)_$(LOCAL_MODULE)_compat_files 544$(my_prefix)$(LOCAL_MODULE_CLASS)_$(LOCAL_MODULE)_compat_files := true 545 546# LOCAL_COMPATIBILITY_SUPPORT_FILES is a list of <src>[:<dest>]. 547$(foreach suite, $(LOCAL_COMPATIBILITY_SUITE), \ 548 $(eval my_compat_dist_$(suite) += $(foreach f, $(LOCAL_COMPATIBILITY_SUPPORT_FILES), \ 549 $(eval p := $(subst :,$(space),$(f))) \ 550 $(eval s := $(word 1,$(p))) \ 551 $(eval n := $(or $(word 2,$(p)),$(notdir $(word 1, $(p))))) \ 552 $(foreach dir, $(call compatibility_suite_dirs,$(suite)), \ 553 $(s):$(dir)/$(n))))) 554 555test_config := $(wildcard $(LOCAL_PATH)/AndroidTest.xml) 556ifeq (,$(test_config)) 557 ifneq (true,$(is_native)) 558 is_instrumentation_test := true 559 ifeq (true, $(LOCAL_IS_HOST_MODULE)) 560 is_instrumentation_test := false 561 endif 562 # If LOCAL_MODULE_CLASS is not APPS, it's certainly not an instrumentation 563 # test. However, some packages for test data also have LOCAL_MODULE_CLASS 564 # set to APPS. These will require flag LOCAL_DISABLE_AUTO_GENERATE_TEST_CONFIG 565 # to disable auto-generating test config file. 566 ifneq (APPS, $(LOCAL_MODULE_CLASS)) 567 is_instrumentation_test := false 568 endif 569 endif 570 # CTS modules can be used for test data, so test config files must be 571 # explicitly created using AndroidTest.xml 572 ifeq (,$(filter cts, $(LOCAL_COMPATIBILITY_SUITE))) 573 ifneq (true, $(LOCAL_DISABLE_AUTO_GENERATE_TEST_CONFIG)) 574 ifeq (true, $(filter true,$(is_native) $(is_instrumentation_test))) 575 include $(BUILD_SYSTEM)/autogen_test_config.mk 576 test_config := $(autogen_test_config_file) 577 autogen_test_config_file := 578 endif 579 endif 580 endif 581endif 582 583is_instrumentation_test := 584 585ifneq (,$(test_config)) 586$(foreach suite, $(LOCAL_COMPATIBILITY_SUITE), \ 587 $(eval my_compat_dist_$(suite) += $(foreach dir, $(call compatibility_suite_dirs,$(suite)), \ 588 $(test_config):$(dir)/$(LOCAL_MODULE).config))) 589endif 590 591test_config := 592 593ifneq (,$(wildcard $(LOCAL_PATH)/DynamicConfig.xml)) 594$(foreach suite, $(LOCAL_COMPATIBILITY_SUITE), \ 595 $(eval my_compat_dist_$(suite) += $(foreach dir, $(call compatibility_suite_dirs,$(suite)), \ 596 $(LOCAL_PATH)/DynamicConfig.xml:$(dir)/$(LOCAL_MODULE).dynamic))) 597endif 598 599ifneq (,$(wildcard $(LOCAL_PATH)/$(LOCAL_MODULE)_*.config)) 600$(foreach extra_config, $(wildcard $(LOCAL_PATH)/$(LOCAL_MODULE)_*.config), \ 601 $(foreach suite, $(LOCAL_COMPATIBILITY_SUITE), \ 602 $(eval my_compat_dist_$(suite) += $(foreach dir, $(call compatibility_suite_dirs,$(suite)), \ 603 $(extra_config):$(dir)/$(notdir $(extra_config)))))) 604endif 605endif # $(my_prefix)$(LOCAL_MODULE_CLASS)_$(LOCAL_MODULE)_compat_files 606 607ifneq ($(my_test_data_file_pairs),) 608$(foreach pair, $(my_test_data_file_pairs), \ 609 $(eval parts := $(subst :,$(space),$(pair))) \ 610 $(eval src_path := $(word 1,$(parts))) \ 611 $(eval file := $(word 2,$(parts))) \ 612 $(foreach suite, $(LOCAL_COMPATIBILITY_SUITE), \ 613 $(eval my_compat_dist_$(suite) += $(foreach dir, $(call compatibility_suite_dirs,$(suite),$(arch_dir)), \ 614 $(src_path):$(call append-path,$(dir),$(file)))))) 615endif 616 617arch_dir := 618is_native := 619 620$(call create-suite-dependencies) 621 622endif # LOCAL_COMPATIBILITY_SUITE 623 624########################################################### 625## Register with ALL_MODULES 626########################################################### 627 628ALL_MODULES += $(my_register_name) 629 630# Don't use += on subvars, or else they'll end up being 631# recursively expanded. 632ALL_MODULES.$(my_register_name).CLASS := \ 633 $(ALL_MODULES.$(my_register_name).CLASS) $(LOCAL_MODULE_CLASS) 634ALL_MODULES.$(my_register_name).PATH := \ 635 $(ALL_MODULES.$(my_register_name).PATH) $(LOCAL_PATH) 636ALL_MODULES.$(my_register_name).TAGS := \ 637 $(ALL_MODULES.$(my_register_name).TAGS) $(my_module_tags) 638ALL_MODULES.$(my_register_name).CHECKED := \ 639 $(ALL_MODULES.$(my_register_name).CHECKED) $(my_checked_module) 640ALL_MODULES.$(my_register_name).BUILT := \ 641 $(ALL_MODULES.$(my_register_name).BUILT) $(LOCAL_BUILT_MODULE) 642ifneq (true,$(LOCAL_UNINSTALLABLE_MODULE)) 643ALL_MODULES.$(my_register_name).INSTALLED := \ 644 $(strip $(ALL_MODULES.$(my_register_name).INSTALLED) \ 645 $(LOCAL_INSTALLED_MODULE) $(my_init_rc_installed) $(my_installed_symlinks) \ 646 $(my_installed_test_data)) 647ALL_MODULES.$(my_register_name).BUILT_INSTALLED := \ 648 $(strip $(ALL_MODULES.$(my_register_name).BUILT_INSTALLED) \ 649 $(LOCAL_BUILT_MODULE):$(LOCAL_INSTALLED_MODULE) \ 650 $(my_init_rc_pairs) $(my_test_data_pairs)) 651endif 652ifdef LOCAL_PICKUP_FILES 653# Files or directories ready to pick up by the build system 654# when $(LOCAL_BUILT_MODULE) is done. 655ALL_MODULES.$(my_register_name).PICKUP_FILES := \ 656 $(ALL_MODULES.$(my_register_name).PICKUP_FILES) $(LOCAL_PICKUP_FILES) 657endif 658my_required_modules := $(LOCAL_REQUIRED_MODULES) \ 659 $(LOCAL_REQUIRED_MODULES_$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) 660ifdef LOCAL_IS_HOST_MODULE 661my_required_modules += $(LOCAL_REQUIRED_MODULES_$($(my_prefix)OS)) 662endif 663ALL_MODULES.$(my_register_name).REQUIRED := \ 664 $(strip $(ALL_MODULES.$(my_register_name).REQUIRED) $(my_required_modules)) 665ALL_MODULES.$(my_register_name).EXPLICITLY_REQUIRED := \ 666 $(strip $(ALL_MODULES.$(my_register_name).EXPLICITLY_REQUIRED)\ 667 $(my_required_modules)) 668ALL_MODULES.$(my_register_name).TARGET_REQUIRED := \ 669 $(strip $(ALL_MODULES.$(my_register_name).TARGET_REQUIRED)\ 670 $(LOCAL_TARGET_REQUIRED_MODULES)) 671ALL_MODULES.$(my_register_name).HOST_REQUIRED := \ 672 $(strip $(ALL_MODULES.$(my_register_name).HOST_REQUIRED)\ 673 $(LOCAL_HOST_REQUIRED_MODULES)) 674ALL_MODULES.$(my_register_name).EVENT_LOG_TAGS := \ 675 $(ALL_MODULES.$(my_register_name).EVENT_LOG_TAGS) $(event_log_tags) 676ALL_MODULES.$(my_register_name).MAKEFILE := \ 677 $(ALL_MODULES.$(my_register_name).MAKEFILE) $(LOCAL_MODULE_MAKEFILE) 678ifdef LOCAL_MODULE_OWNER 679ALL_MODULES.$(my_register_name).OWNER := \ 680 $(sort $(ALL_MODULES.$(my_register_name).OWNER) $(LOCAL_MODULE_OWNER)) 681endif 682ifdef LOCAL_2ND_ARCH_VAR_PREFIX 683ALL_MODULES.$(my_register_name).FOR_2ND_ARCH := true 684endif 685ALL_MODULES.$(my_register_name).FOR_HOST_CROSS := $(my_host_cross) 686ALL_MODULES.$(my_register_name).COMPATIBILITY_SUITES := $(LOCAL_COMPATIBILITY_SUITE) 687 688INSTALLABLE_FILES.$(LOCAL_INSTALLED_MODULE).MODULE := $(my_register_name) 689 690########################################################## 691# Track module-level dependencies. 692# Use $(LOCAL_MODULE) instead of $(my_register_name) to ignore module's bitness. 693ALL_DEPS.MODULES := $(sort $(ALL_DEPS.MODULES) $(LOCAL_MODULE)) 694ALL_DEPS.$(LOCAL_MODULE).ALL_DEPS := $(sort \ 695 $(ALL_MODULES.$(LOCAL_MODULE).ALL_DEPS) \ 696 $(LOCAL_STATIC_LIBRARIES) \ 697 $(LOCAL_WHOLE_STATIC_LIBRARIES) \ 698 $(LOCAL_SHARED_LIBRARIES) \ 699 $(LOCAL_HEADER_LIBRARIES) \ 700 $(LOCAL_STATIC_JAVA_LIBRARIES) \ 701 $(LOCAL_JAVA_LIBRARIES)\ 702 $(LOCAL_JNI_SHARED_LIBRARIES)) 703 704ALL_DEPS.$(LOCAL_MODULE).LICENSE := $(sort $(ALL_DEPS.$(LOCAL_MODULE).LICENSE) $(license_files)) 705 706########################################################### 707## Take care of my_module_tags 708########################################################### 709 710# Keep track of all the tags we've seen. 711ALL_MODULE_TAGS := $(sort $(ALL_MODULE_TAGS) $(my_module_tags)) 712 713# Add this module name to the tag list of each specified tag. 714$(foreach tag,$(my_module_tags),\ 715 $(eval ALL_MODULE_NAME_TAGS.$(tag) := $$(ALL_MODULE_NAME_TAGS.$(tag)) $(my_register_name))) 716 717########################################################### 718## umbrella targets used to verify builds 719########################################################### 720j_or_n := 721ifneq (,$(filter EXECUTABLES SHARED_LIBRARIES STATIC_LIBRARIES HEADER_LIBRARIES NATIVE_TESTS,$(LOCAL_MODULE_CLASS))) 722j_or_n := native 723else 724ifneq (,$(filter JAVA_LIBRARIES APPS,$(LOCAL_MODULE_CLASS))) 725j_or_n := java 726endif 727endif 728ifdef LOCAL_IS_HOST_MODULE 729h_or_t := host 730ifeq ($(my_host_cross),true) 731h_or_hc_or_t := host-cross 732else 733h_or_hc_or_t := host 734endif 735else 736h_or_hc_or_t := target 737h_or_t := target 738endif 739 740 741ifdef j_or_n 742$(j_or_n) $(h_or_t) $(j_or_n)-$(h_or_hc_or_t) : $(my_checked_module) 743ifneq (,$(filter $(my_module_tags),tests)) 744$(j_or_n)-$(h_or_t)-tests $(j_or_n)-tests $(h_or_t)-tests : $(my_checked_module) 745endif 746$(LOCAL_MODULE)-$(h_or_hc_or_t) : $(my_all_targets) 747ifeq ($(j_or_n),native) 748$(LOCAL_MODULE)-$(h_or_hc_or_t)$(my_32_64_bit_suffix) : $(my_all_targets) 749endif 750endif 751 752########################################################### 753# Ensure privileged applications always have LOCAL_PRIVILEGED_MODULE 754########################################################### 755ifndef LOCAL_PRIVILEGED_MODULE 756 ifneq (,$(filter $(TARGET_OUT_APPS_PRIVILEGED)/% $(TARGET_OUT_VENDOR_APPS_PRIVILEGED)/%,$(my_module_path))) 757 LOCAL_PRIVILEGED_MODULE := true 758 endif 759endif 760 761########################################################### 762## NOTICE files 763########################################################### 764 765include $(BUILD_NOTICE_FILE) 766