1########################################################### 2## Standard rules for copying files that are prebuilt 3## 4## Additional inputs from base_rules.make: 5## None. 6## 7########################################################### 8 9include $(BUILD_SYSTEM)/use_lld_setup.mk 10 11ifneq ($(LOCAL_PREBUILT_LIBS),) 12$(call pretty-error,dont use LOCAL_PREBUILT_LIBS anymore) 13endif 14ifneq ($(LOCAL_PREBUILT_EXECUTABLES),) 15$(call pretty-error,dont use LOCAL_PREBUILT_EXECUTABLES anymore) 16endif 17ifneq ($(LOCAL_PREBUILT_JAVA_LIBRARIES),) 18$(call pretty-error,dont use LOCAL_PREBUILT_JAVA_LIBRARIES anymore) 19endif 20 21my_32_64_bit_suffix := $(if $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)IS_64_BIT),64,32) 22 23ifdef LOCAL_PREBUILT_MODULE_FILE 24 my_prebuilt_src_file := $(LOCAL_PREBUILT_MODULE_FILE) 25else ifdef LOCAL_SRC_FILES_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH) 26 my_prebuilt_src_file := $(LOCAL_PATH)/$(LOCAL_SRC_FILES_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) 27 LOCAL_SRC_FILES_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH) := 28else ifdef LOCAL_SRC_FILES_$(my_32_64_bit_suffix) 29 my_prebuilt_src_file := $(LOCAL_PATH)/$(LOCAL_SRC_FILES_$(my_32_64_bit_suffix)) 30 LOCAL_SRC_FILES_$(my_32_64_bit_suffix) := 31else ifdef LOCAL_SRC_FILES 32 my_prebuilt_src_file := $(LOCAL_PATH)/$(LOCAL_SRC_FILES) 33 LOCAL_SRC_FILES := 34else ifdef LOCAL_REPLACE_PREBUILT_APK_INSTALLED 35 # This is handled specially below 36else 37 $(call pretty-error,No source files specified) 38endif 39 40LOCAL_CHECKED_MODULE := $(my_prebuilt_src_file) 41 42ifeq (APPS,$(LOCAL_MODULE_CLASS)) 43include $(BUILD_SYSTEM)/app_prebuilt_internal.mk 44else 45# 46# Non-APPS prebuilt modules handling almost to the end of the file 47# 48 49my_strip_module := $(firstword \ 50 $(LOCAL_STRIP_MODULE_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) \ 51 $(LOCAL_STRIP_MODULE)) 52 53ifeq (SHARED_LIBRARIES,$(LOCAL_MODULE_CLASS)) 54 ifeq ($(LOCAL_IS_HOST_MODULE)$(my_strip_module),) 55 # Strip but not try to add debuglink 56 my_strip_module := no_debuglink 57 endif 58endif 59 60ifneq ($(filter STATIC_LIBRARIES SHARED_LIBRARIES,$(LOCAL_MODULE_CLASS)),) 61 prebuilt_module_is_a_library := true 62else 63 prebuilt_module_is_a_library := 64endif 65 66# Don't install static libraries by default. 67ifndef LOCAL_UNINSTALLABLE_MODULE 68ifeq (STATIC_LIBRARIES,$(LOCAL_MODULE_CLASS)) 69 LOCAL_UNINSTALLABLE_MODULE := true 70endif 71endif 72 73ifeq (JAVA_LIBRARIES,$(LOCAL_IS_HOST_MODULE)$(LOCAL_MODULE_CLASS)$(filter true,$(LOCAL_UNINSTALLABLE_MODULE))) 74 prebuilt_module_is_dex_javalib := true 75else 76 prebuilt_module_is_dex_javalib := 77endif 78 79ifdef LOCAL_COMPRESSED_MODULE 80$(error $(LOCAL_MODULE) : LOCAL_COMPRESSED_MODULE can only be defined for module class APPS) 81endif # LOCAL_COMPRESSED_MODULE 82 83my_check_elf_file_shared_lib_files := 84 85ifneq ($(filter true keep_symbols no_debuglink mini-debug-info,$(my_strip_module)),) 86 ifdef LOCAL_IS_HOST_MODULE 87 $(call pretty-error,Cannot strip/pack host module) 88 endif 89 ifeq ($(filter SHARED_LIBRARIES EXECUTABLES NATIVE_TESTS,$(LOCAL_MODULE_CLASS)),) 90 $(call pretty-error,Can strip/pack only shared libraries or executables) 91 endif 92 ifneq ($(LOCAL_PREBUILT_STRIP_COMMENTS),) 93 $(call pretty-error,Cannot strip/pack scripts) 94 endif 95 # Set the arch-specific variables to set up the strip rules 96 LOCAL_STRIP_MODULE_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH) := $(my_strip_module) 97 include $(BUILD_SYSTEM)/dynamic_binary.mk 98 built_module := $(linked_module) 99 100 ifneq ($(LOCAL_SDK_VERSION),) 101 # binary.mk filters out NDK_MIGRATED_LIBS from my_shared_libs, thus those NDK libs are not added 102 # to DEPENDENCIES_ON_SHARED_LIBRARIES. Assign $(my_ndk_shared_libraries_fullpath) to 103 # my_check_elf_file_shared_lib_files so that check_elf_file.py can see those NDK stub libs. 104 my_check_elf_file_shared_lib_files := $(my_ndk_shared_libraries_fullpath) 105 endif 106else # my_strip_module not true 107 include $(BUILD_SYSTEM)/base_rules.mk 108 built_module := $(LOCAL_BUILT_MODULE) 109 110ifdef prebuilt_module_is_a_library 111export_includes := $(intermediates)/export_includes 112export_cflags := $(foreach d,$(LOCAL_EXPORT_C_INCLUDE_DIRS),-I $(d)) 113$(export_includes): PRIVATE_EXPORT_CFLAGS := $(export_cflags) 114$(export_includes): $(LOCAL_EXPORT_C_INCLUDE_DEPS) 115 @echo Export includes file: $< -- $@ 116 $(hide) mkdir -p $(dir $@) && rm -f $@ 117ifdef export_cflags 118 $(hide) echo "$(PRIVATE_EXPORT_CFLAGS)" >$@ 119else 120 $(hide) touch $@ 121endif 122export_cflags := 123 124include $(BUILD_SYSTEM)/allowed_ndk_types.mk 125 126ifdef LOCAL_SDK_VERSION 127my_link_type := native:ndk:$(my_ndk_stl_family):$(my_ndk_stl_link_type) 128else ifdef LOCAL_USE_VNDK 129 _name := $(patsubst %.vendor,%,$(LOCAL_MODULE)) 130 ifneq ($(filter $(_name),$(VNDK_CORE_LIBRARIES) $(VNDK_SAMEPROCESS_LIBRARIES) $(LLNDK_LIBRARIES)),) 131 ifeq ($(filter $(_name),$(VNDK_PRIVATE_LIBRARIES)),) 132 my_link_type := native:vndk 133 else 134 my_link_type := native:vndk_private 135 endif 136 else 137 my_link_type := native:vendor 138 endif 139else ifneq ($(filter $(TARGET_RECOVERY_OUT)/%,$(LOCAL_MODULE_PATH)),) 140my_link_type := native:recovery 141else 142my_link_type := native:platform 143endif 144 145# TODO: check dependencies of prebuilt files 146my_link_deps := 147 148my_2nd_arch_prefix := $(LOCAL_2ND_ARCH_VAR_PREFIX) 149my_common := 150include $(BUILD_SYSTEM)/link_type.mk 151endif # prebuilt_module_is_a_library 152 153# The real dependency will be added after all Android.mks are loaded and the install paths 154# of the shared libraries are determined. 155ifdef LOCAL_INSTALLED_MODULE 156ifdef LOCAL_IS_HOST_MODULE 157 ifeq ($(LOCAL_SYSTEM_SHARED_LIBRARIES),none) 158 my_system_shared_libraries := 159 else 160 my_system_shared_libraries := $(LOCAL_SYSTEM_SHARED_LIBRARIES) 161 endif 162else 163 ifeq ($(LOCAL_SYSTEM_SHARED_LIBRARIES),none) 164 my_system_shared_libraries := libc libm libdl 165 else 166 my_system_shared_libraries := $(LOCAL_SYSTEM_SHARED_LIBRARIES) 167 my_system_shared_libraries := $(patsubst libc,libc libdl,$(my_system_shared_libraries)) 168 endif 169endif 170 171my_shared_libraries := \ 172 $(filter-out $(my_system_shared_libraries),$(LOCAL_SHARED_LIBRARIES)) \ 173 $(my_system_shared_libraries) 174 175ifdef my_shared_libraries 176# Extra shared libraries introduced by LOCAL_CXX_STL. 177include $(BUILD_SYSTEM)/cxx_stl_setup.mk 178ifdef LOCAL_USE_VNDK 179 my_shared_libraries := $(foreach l,$(my_shared_libraries),\ 180 $(if $(SPLIT_VENDOR.SHARED_LIBRARIES.$(l)),$(l).vendor,$(l))) 181endif 182$(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)DEPENDENCIES_ON_SHARED_LIBRARIES += \ 183 $(my_register_name):$(LOCAL_INSTALLED_MODULE):$(subst $(space),$(comma),$(my_shared_libraries)) 184endif 185endif # my_shared_libraries 186 187# We need to enclose the above export_includes and my_built_shared_libraries in 188# "my_strip_module not true" because otherwise the rules are defined in dynamic_binary.mk. 189endif # my_strip_module not true 190 191# Check prebuilt ELF binaries. 192include $(BUILD_SYSTEM)/check_elf_file.mk 193 194ifeq ($(NATIVE_COVERAGE),true) 195ifneq (,$(strip $(LOCAL_PREBUILT_COVERAGE_ARCHIVE))) 196 $(eval $(call copy-one-file,$(LOCAL_PREBUILT_COVERAGE_ARCHIVE),$(intermediates)/$(LOCAL_MODULE).gcnodir)) 197 ifneq ($(LOCAL_UNINSTALLABLE_MODULE),true) 198 ifdef LOCAL_IS_HOST_MODULE 199 my_coverage_path := $($(my_prefix)OUT_COVERAGE)/$(patsubst $($(my_prefix)OUT)/%,%,$(my_module_path)) 200 else 201 my_coverage_path := $(TARGET_OUT_COVERAGE)/$(patsubst $(PRODUCT_OUT)/%,%,$(my_module_path)) 202 endif 203 my_coverage_path := $(my_coverage_path)/$(patsubst %.so,%,$(my_installed_module_stem)).gcnodir 204 $(eval $(call copy-one-file,$(LOCAL_PREBUILT_COVERAGE_ARCHIVE),$(my_coverage_path))) 205 $(LOCAL_BUILT_MODULE): $(my_coverage_path) 206 endif 207else 208# Coverage information is needed when static lib is a dependency of another 209# coverage-enabled module. 210ifeq (STATIC_LIBRARIES, $(LOCAL_MODULE_CLASS)) 211GCNO_ARCHIVE := $(LOCAL_MODULE).gcnodir 212$(intermediates)/$(GCNO_ARCHIVE) : PRIVATE_ALL_OBJECTS := 213$(intermediates)/$(GCNO_ARCHIVE) : PRIVATE_ALL_WHOLE_STATIC_LIBRARIES := 214$(intermediates)/$(GCNO_ARCHIVE) : PRIVATE_PREFIX := $(my_prefix) 215$(intermediates)/$(GCNO_ARCHIVE) : PRIVATE_2ND_ARCH_VAR_PREFIX := $(LOCAL_2ND_ARCH_VAR_PREFIX) 216$(intermediates)/$(GCNO_ARCHIVE) : 217 $(transform-o-to-static-lib) 218endif 219endif 220endif 221 222ifeq ($(prebuilt_module_is_dex_javalib),true) 223my_dex_jar := $(my_prebuilt_src_file) 224# This is a target shared library, i.e. a jar with classes.dex. 225 226ifneq ($(filter $(LOCAL_MODULE),$(PRODUCT_BOOT_JARS)),) 227 $(call pretty-error,Modules in PRODUCT_BOOT_JARS must be defined in Android.bp files) 228endif 229 230####################################### 231# defines built_odex along with rule to install odex 232include $(BUILD_SYSTEM)/dex_preopt_odex_install.mk 233####################################### 234ifdef LOCAL_DEX_PREOPT 235 236$(built_module): PRIVATE_STRIP_SCRIPT := $(intermediates)/strip.sh 237$(built_module): $(intermediates)/strip.sh 238$(built_module): | $(DEXPREOPT_STRIP_DEPS) 239$(built_module): .KATI_DEPFILE := $(built_module).d 240$(built_module): $(my_prebuilt_src_file) 241 $(PRIVATE_STRIP_SCRIPT) $< $@ 242 243else # ! LOCAL_DEX_PREOPT 244$(built_module) : $(my_prebuilt_src_file) 245 $(call copy-file-to-target) 246endif # LOCAL_DEX_PREOPT 247 248else # ! prebuilt_module_is_dex_javalib 249ifneq ($(filter init%rc,$(notdir $(LOCAL_INSTALLED_MODULE)))$(filter %/etc/init,$(dir $(LOCAL_INSTALLED_MODULE))),) 250 $(eval $(call copy-init-script-file-checked,$(my_prebuilt_src_file),$(built_module))) 251else ifneq ($(LOCAL_PREBUILT_STRIP_COMMENTS),) 252$(built_module) : $(my_prebuilt_src_file) 253 $(transform-prebuilt-to-target-strip-comments) 254else 255$(built_module) : $(my_prebuilt_src_file) 256 $(transform-prebuilt-to-target) 257endif 258ifneq ($(filter EXECUTABLES NATIVE_TESTS,$(LOCAL_MODULE_CLASS)),) 259 $(hide) chmod +x $@ 260endif 261endif # ! prebuilt_module_is_dex_javalib 262 263ifeq ($(LOCAL_MODULE_CLASS),JAVA_LIBRARIES) 264my_src_jar := $(my_prebuilt_src_file) 265 266ifdef LOCAL_IS_HOST_MODULE 267# for host java libraries deps should be in the common dir, so we make a copy in 268# the common dir. 269common_classes_jar := $(intermediates.COMMON)/classes.jar 270common_header_jar := $(intermediates.COMMON)/classes-header.jar 271 272$(common_classes_jar): PRIVATE_MODULE := $(LOCAL_MODULE) 273$(common_classes_jar): PRIVATE_PREFIX := $(my_prefix) 274 275$(common_classes_jar) : $(my_src_jar) 276 $(transform-prebuilt-to-target) 277 278ifneq ($(TURBINE_ENABLED),false) 279$(common_header_jar) : $(my_src_jar) 280 $(transform-prebuilt-to-target) 281endif 282 283else # !LOCAL_IS_HOST_MODULE 284# for target java libraries, the LOCAL_BUILT_MODULE is in a product-specific dir, 285# while the deps should be in the common dir, so we make a copy in the common dir. 286common_classes_jar := $(intermediates.COMMON)/classes.jar 287common_header_jar := $(intermediates.COMMON)/classes-header.jar 288common_classes_pre_proguard_jar := $(intermediates.COMMON)/classes-pre-proguard.jar 289common_javalib_jar := $(intermediates.COMMON)/javalib.jar 290 291$(common_classes_jar) $(common_classes_pre_proguard_jar) $(common_javalib_jar): PRIVATE_MODULE := $(LOCAL_MODULE) 292$(common_classes_jar) $(common_classes_pre_proguard_jar) $(common_javalib_jar): PRIVATE_PREFIX := $(my_prefix) 293 294ifeq ($(LOCAL_SDK_VERSION),system_current) 295my_link_type := java:system 296else ifneq (,$(call has-system-sdk-version,$(LOCAL_SDK_VERSION))) 297my_link_type := java:system 298else ifeq ($(LOCAL_SDK_VERSION),core_current) 299my_link_type := java:core 300else ifneq ($(LOCAL_SDK_VERSION),) 301my_link_type := java:sdk 302else 303my_link_type := java:platform 304endif 305 306# TODO: check dependencies of prebuilt files 307my_link_deps := 308 309my_2nd_arch_prefix := $(LOCAL_2ND_ARCH_VAR_PREFIX) 310my_common := COMMON 311include $(BUILD_SYSTEM)/link_type.mk 312 313ifeq ($(prebuilt_module_is_dex_javalib),true) 314# For prebuilt shared Java library we don't have classes.jar. 315$(common_javalib_jar) : $(my_src_jar) 316 $(transform-prebuilt-to-target) 317 318else # ! prebuilt_module_is_dex_javalib 319 320my_src_aar := $(filter %.aar, $(my_prebuilt_src_file)) 321ifneq ($(my_src_aar),) 322# This is .aar file, archive of classes.jar and Android resources. 323 324# run Jetifier if needed 325LOCAL_JETIFIER_INPUT_FILE := $(my_src_aar) 326include $(BUILD_SYSTEM)/jetifier.mk 327my_src_aar := $(LOCAL_JETIFIER_OUTPUT_FILE) 328 329my_src_jar := $(intermediates.COMMON)/aar/classes.jar 330my_src_proguard_options := $(intermediates.COMMON)/aar/proguard.txt 331my_src_android_manifest := $(intermediates.COMMON)/aar/AndroidManifest.xml 332 333$(my_src_jar) : .KATI_IMPLICIT_OUTPUTS := $(my_src_proguard_options) 334$(my_src_jar) : .KATI_IMPLICIT_OUTPUTS += $(my_src_android_manifest) 335$(my_src_jar) : $(my_src_aar) 336 $(hide) rm -rf $(dir $@) && mkdir -p $(dir $@) $(dir $@)/res 337 $(hide) unzip -qo -d $(dir $@) $< 338 # Make sure the extracted classes.jar has a new timestamp. 339 $(hide) touch $@ 340 # Make sure the proguard and AndroidManifest.xml files exist 341 # and have a new timestamp. 342 $(hide) touch $(dir $@)/proguard.txt 343 $(hide) touch $(dir $@)/AndroidManifest.xml 344 345my_prebuilt_android_manifest := $(intermediates.COMMON)/manifest/AndroidManifest.xml 346$(eval $(call copy-one-file,$(my_src_android_manifest),$(my_prebuilt_android_manifest))) 347$(call add-dependency,$(LOCAL_BUILT_MODULE),$(my_prebuilt_android_manifest)) 348 349else 350 351# run Jetifier if needed 352LOCAL_JETIFIER_INPUT_FILE := $(my_src_jar) 353include $(BUILD_SYSTEM)/jetifier.mk 354my_src_jar := $(LOCAL_JETIFIER_OUTPUT_FILE) 355 356endif 357 358$(common_classes_jar) : $(my_src_jar) 359 $(transform-prebuilt-to-target) 360 361ifneq ($(TURBINE_ENABLED),false) 362$(common_header_jar) : $(my_src_jar) 363 $(transform-prebuilt-to-target) 364endif 365 366$(common_classes_pre_proguard_jar) : $(my_src_jar) 367 $(transform-prebuilt-to-target) 368 369$(common_javalib_jar) : $(common_classes_jar) 370 $(transform-prebuilt-to-target) 371 372include $(BUILD_SYSTEM)/force_aapt2.mk 373 374ifdef LOCAL_AAPT2_ONLY 375LOCAL_USE_AAPT2 := true 376endif 377 378ifeq ($(LOCAL_USE_AAPT2),true) 379ifneq ($(my_src_aar),) 380 381$(intermediates.COMMON)/export_proguard_flags : $(my_src_proguard_options) 382 $(transform-prebuilt-to-target) 383 384LOCAL_SDK_RES_VERSION:=$(strip $(LOCAL_SDK_RES_VERSION)) 385ifeq ($(LOCAL_SDK_RES_VERSION),) 386 LOCAL_SDK_RES_VERSION:=$(LOCAL_SDK_VERSION) 387endif 388 389framework_res_package_export := 390# Please refer to package.mk 391ifneq ($(LOCAL_NO_STANDARD_LIBRARIES),true) 392ifneq ($(filter-out current system_current test_current,$(LOCAL_SDK_RES_VERSION))$(if $(TARGET_BUILD_APPS),$(filter current system_current test_current,$(LOCAL_SDK_RES_VERSION))),) 393framework_res_package_export := \ 394 $(call resolve-prebuilt-sdk-jar-path,$(LOCAL_SDK_RES_VERSION)) 395else 396framework_res_package_export := \ 397 $(call intermediates-dir-for,APPS,framework-res,,COMMON)/package-export.apk 398endif 399endif 400 401my_res_package := $(intermediates.COMMON)/package-res.apk 402 403# We needed only very few PRIVATE variables and aapt2.mk input variables. Reset the unnecessary ones. 404$(my_res_package): PRIVATE_AAPT2_CFLAGS := 405$(my_res_package): PRIVATE_AAPT_FLAGS := --static-lib --no-static-lib-packages --auto-add-overlay 406$(my_res_package): PRIVATE_ANDROID_MANIFEST := $(my_src_android_manifest) 407$(my_res_package): PRIVATE_AAPT_INCLUDES := $(framework_res_package_export) 408$(my_res_package): PRIVATE_SOURCE_INTERMEDIATES_DIR := 409$(my_res_package): PRIVATE_PROGUARD_OPTIONS_FILE := 410$(my_res_package): PRIVATE_DEFAULT_APP_TARGET_SDK := 411$(my_res_package): PRIVATE_DEFAULT_APP_TARGET_SDK := 412$(my_res_package): PRIVATE_PRODUCT_AAPT_CONFIG := 413$(my_res_package): PRIVATE_PRODUCT_AAPT_PREF_CONFIG := 414$(my_res_package): PRIVATE_TARGET_AAPT_CHARACTERISTICS := 415$(my_res_package) : $(framework_res_package_export) 416$(my_res_package) : $(my_src_android_manifest) 417 418full_android_manifest := 419my_res_resources := 420my_overlay_resources := 421my_compiled_res_base_dir := $(intermediates.COMMON)/flat-res 422R_file_stamp := 423proguard_options_file := 424my_generated_res_dirs := $(intermediates.COMMON)/aar/res 425my_generated_res_dirs_deps := $(my_src_jar) 426include $(BUILD_SYSTEM)/aapt2.mk 427 428# Make sure my_res_package is created when you run mm/mmm. 429$(built_module) : $(my_res_package) 430endif # $(my_src_aar) 431endif # LOCAL_USE_AAPT2 432# make sure the classes.jar and javalib.jar are built before $(LOCAL_BUILT_MODULE) 433$(built_module) : $(common_javalib_jar) 434 435my_exported_sdk_libs_file := $(intermediates.COMMON)/exported-sdk-libs 436$(my_exported_sdk_libs_file): PRIVATE_EXPORTED_SDK_LIBS := $(LOCAL_EXPORT_SDK_LIBRARIES) 437$(my_exported_sdk_libs_file): 438 @echo "Export SDK libs $@" 439 $(hide) mkdir -p $(dir $@) && rm -f $@ 440 $(if $(PRIVATE_EXPORTED_SDK_LIBS),\ 441 $(hide) echo $(PRIVATE_EXPORTED_SDK_LIBS) | tr ' ' '\n' > $@,\ 442 $(hide) touch $@) 443 444endif # ! prebuilt_module_is_dex_javalib 445endif # LOCAL_IS_HOST_MODULE is not set 446 447endif # JAVA_LIBRARIES 448 449endif # APPS 450 451$(built_module) : $(LOCAL_ADDITIONAL_DEPENDENCIES) 452 453my_prebuilt_src_file := 454my_preopt_for_extracted_apk := 455