1 ########################################################### 2 ## Standard rules for copying files that are prebuilt 3 ## 4 ## Additional inputs from base_rules.make: 5 ## None. 6 ## 7 ########################################################### 8 9 include $(BUILD_SYSTEM)/use_lld_setup.mk 10 11 ifneq ($(LOCAL_PREBUILT_LIBS),) 12 $(call pretty-error,dont use LOCAL_PREBUILT_LIBS anymore) 13 endif 14 ifneq ($(LOCAL_PREBUILT_EXECUTABLES),) 15 $(call pretty-error,dont use LOCAL_PREBUILT_EXECUTABLES anymore) 16 endif 17 ifneq ($(LOCAL_PREBUILT_JAVA_LIBRARIES),) 18 $(call pretty-error,dont use LOCAL_PREBUILT_JAVA_LIBRARIES anymore) 19 endif 20 21 my_32_64_bit_suffix := $(if $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)IS_64_BIT),64,32) 22 23 ifdef LOCAL_PREBUILT_MODULE_FILE 24 my_prebuilt_src_file := $(LOCAL_PREBUILT_MODULE_FILE) 25 else 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) := 28 else 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) := 31 else ifdef LOCAL_SRC_FILES 32 my_prebuilt_src_file := $(LOCAL_PATH)/$(LOCAL_SRC_FILES) 33 LOCAL_SRC_FILES := 34 else ifdef LOCAL_REPLACE_PREBUILT_APK_INSTALLED 35 # This is handled specially below 36 else 37 $(call pretty-error,No source files specified) 38 endif 39 40 LOCAL_CHECKED_MODULE := $(my_prebuilt_src_file) 41 42 ifeq (APPS,$(LOCAL_MODULE_CLASS)) 43 include $(BUILD_SYSTEM)/app_prebuilt_internal.mk 44 else 45 # 46 # Non-APPS prebuilt modules handling almost to the end of the file 47 # 48 49 my_strip_module := $(firstword \ 50 $(LOCAL_STRIP_MODULE_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) \ 51 $(LOCAL_STRIP_MODULE)) 52 53 ifeq (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 58 endif 59 60 ifneq ($(filter STATIC_LIBRARIES SHARED_LIBRARIES,$(LOCAL_MODULE_CLASS)),) 61 prebuilt_module_is_a_library := true 62 else 63 prebuilt_module_is_a_library := 64 endif 65 66 # Don't install static libraries by default. 67 ifndef LOCAL_UNINSTALLABLE_MODULE 68 ifeq (STATIC_LIBRARIES,$(LOCAL_MODULE_CLASS)) 69 LOCAL_UNINSTALLABLE_MODULE := true 70 endif 71 endif 72 73 ifeq (JAVA_LIBRARIES,$(LOCAL_IS_HOST_MODULE)$(LOCAL_MODULE_CLASS)$(filter true,$(LOCAL_UNINSTALLABLE_MODULE))) 74 prebuilt_module_is_dex_javalib := true 75 else 76 prebuilt_module_is_dex_javalib := 77 endif 78 79 ifdef LOCAL_COMPRESSED_MODULE 80 $(error $(LOCAL_MODULE) : LOCAL_COMPRESSED_MODULE can only be defined for module class APPS) 81 endif # LOCAL_COMPRESSED_MODULE 82 83 my_check_elf_file_shared_lib_files := 84 85 ifneq ($(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 106 else # my_strip_module not true 107 include $(BUILD_SYSTEM)/base_rules.mk 108 built_module := $(LOCAL_BUILT_MODULE) 109 110 ifdef prebuilt_module_is_a_library 111 export_includes := $(intermediates)/export_includes 112 export_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 $@ 117 ifdef export_cflags 118 $(hide) echo "$(PRIVATE_EXPORT_CFLAGS)" >$@ 119 else 120 $(hide) touch $@ 121 endif 122 export_cflags := 123 124 include $(BUILD_SYSTEM)/allowed_ndk_types.mk 125 126 ifdef LOCAL_SDK_VERSION 127 my_link_type := native:ndk:$(my_ndk_stl_family):$(my_ndk_stl_link_type) 128 else 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 139 else ifneq ($(filter $(TARGET_RECOVERY_OUT)/%,$(LOCAL_MODULE_PATH)),) 140 my_link_type := native:recovery 141 else 142 my_link_type := native:platform 143 endif 144 145 # TODO: check dependencies of prebuilt files 146 my_link_deps := 147 148 my_2nd_arch_prefix := $(LOCAL_2ND_ARCH_VAR_PREFIX) 149 my_common := 150 include $(BUILD_SYSTEM)/link_type.mk 151 endif # 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. 155 ifdef LOCAL_INSTALLED_MODULE 156 ifdef 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 162 else 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 169 endif 170 171 my_shared_libraries := \ 172 $(filter-out $(my_system_shared_libraries),$(LOCAL_SHARED_LIBRARIES)) \ 173 $(my_system_shared_libraries) 174 175 ifdef my_shared_libraries 176 # Extra shared libraries introduced by LOCAL_CXX_STL. 177 include $(BUILD_SYSTEM)/cxx_stl_setup.mk 178 ifdef LOCAL_USE_VNDK 179 my_shared_libraries := $(foreach l,$(my_shared_libraries),\ 180 $(if $(SPLIT_VENDOR.SHARED_LIBRARIES.$(l)),$(l).vendor,$(l))) 181 endif 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)) 184 endif 185 endif # 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. 189 endif # my_strip_module not true 190 191 # Check prebuilt ELF binaries. 192 include $(BUILD_SYSTEM)/check_elf_file.mk 193 194 ifeq ($(NATIVE_COVERAGE),true) 195 ifneq (,$(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 207 else 208 # Coverage information is needed when static lib is a dependency of another 209 # coverage-enabled module. 210 ifeq (STATIC_LIBRARIES, $(LOCAL_MODULE_CLASS)) 211 GCNO_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) 218 endif 219 endif 220 endif 221 222 ifeq ($(prebuilt_module_is_dex_javalib),true) 223 my_dex_jar := $(my_prebuilt_src_file) 224 # This is a target shared library, i.e. a jar with classes.dex. 225 226 ifneq ($(filter $(LOCAL_MODULE),$(PRODUCT_BOOT_JARS)),) 227 $(call pretty-error,Modules in PRODUCT_BOOT_JARS must be defined in Android.bp files) 228 endif 229 230 ####################################### 231 # defines built_odex along with rule to install odex 232 include $(BUILD_SYSTEM)/dex_preopt_odex_install.mk 233 ####################################### 234 ifdef 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 243 else # ! LOCAL_DEX_PREOPT 244 $(built_module) : $(my_prebuilt_src_file) 245 $(call copy-file-to-target) 246 endif # LOCAL_DEX_PREOPT 247 248 else # ! prebuilt_module_is_dex_javalib 249 ifneq ($(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))) 251 else ifneq ($(LOCAL_PREBUILT_STRIP_COMMENTS),) 252 $(built_module) : $(my_prebuilt_src_file) 253 $(transform-prebuilt-to-target-strip-comments) 254 else 255 $(built_module) : $(my_prebuilt_src_file) 256 $(transform-prebuilt-to-target) 257 endif 258 ifneq ($(filter EXECUTABLES NATIVE_TESTS,$(LOCAL_MODULE_CLASS)),) 259 $(hide) chmod +x $@ 260 endif 261 endif # ! prebuilt_module_is_dex_javalib 262 263 ifeq ($(LOCAL_MODULE_CLASS),JAVA_LIBRARIES) 264 my_src_jar := $(my_prebuilt_src_file) 265 266 ifdef 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. 269 common_classes_jar := $(intermediates.COMMON)/classes.jar 270 common_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 278 ifneq ($(TURBINE_ENABLED),false) 279 $(common_header_jar) : $(my_src_jar) 280 $(transform-prebuilt-to-target) 281 endif 282 283 else # !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. 286 common_classes_jar := $(intermediates.COMMON)/classes.jar 287 common_header_jar := $(intermediates.COMMON)/classes-header.jar 288 common_classes_pre_proguard_jar := $(intermediates.COMMON)/classes-pre-proguard.jar 289 common_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 294 ifeq ($(LOCAL_SDK_VERSION),system_current) 295 my_link_type := java:system 296 else ifneq (,$(call has-system-sdk-version,$(LOCAL_SDK_VERSION))) 297 my_link_type := java:system 298 else ifeq ($(LOCAL_SDK_VERSION),core_current) 299 my_link_type := java:core 300 else ifneq ($(LOCAL_SDK_VERSION),) 301 my_link_type := java:sdk 302 else 303 my_link_type := java:platform 304 endif 305 306 # TODO: check dependencies of prebuilt files 307 my_link_deps := 308 309 my_2nd_arch_prefix := $(LOCAL_2ND_ARCH_VAR_PREFIX) 310 my_common := COMMON 311 include $(BUILD_SYSTEM)/link_type.mk 312 313 ifeq ($(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 318 else # ! prebuilt_module_is_dex_javalib 319 320 my_src_aar := $(filter %.aar, $(my_prebuilt_src_file)) 321 ifneq ($(my_src_aar),) 322 # This is .aar file, archive of classes.jar and Android resources. 323 324 # run Jetifier if needed 325 LOCAL_JETIFIER_INPUT_FILE := $(my_src_aar) 326 include $(BUILD_SYSTEM)/jetifier.mk 327 my_src_aar := $(LOCAL_JETIFIER_OUTPUT_FILE) 328 329 my_src_jar := $(intermediates.COMMON)/aar/classes.jar 330 my_src_proguard_options := $(intermediates.COMMON)/aar/proguard.txt 331 my_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 345 my_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 349 else 350 351 # run Jetifier if needed 352 LOCAL_JETIFIER_INPUT_FILE := $(my_src_jar) 353 include $(BUILD_SYSTEM)/jetifier.mk 354 my_src_jar := $(LOCAL_JETIFIER_OUTPUT_FILE) 355 356 endif 357 358 $(common_classes_jar) : $(my_src_jar) 359 $(transform-prebuilt-to-target) 360 361 ifneq ($(TURBINE_ENABLED),false) 362 $(common_header_jar) : $(my_src_jar) 363 $(transform-prebuilt-to-target) 364 endif 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 372 include $(BUILD_SYSTEM)/force_aapt2.mk 373 374 ifdef LOCAL_AAPT2_ONLY 375 LOCAL_USE_AAPT2 := true 376 endif 377 378 ifeq ($(LOCAL_USE_AAPT2),true) 379 ifneq ($(my_src_aar),) 380 381 $(intermediates.COMMON)/export_proguard_flags : $(my_src_proguard_options) 382 $(transform-prebuilt-to-target) 383 384 LOCAL_SDK_RES_VERSION:=$(strip $(LOCAL_SDK_RES_VERSION)) 385 ifeq ($(LOCAL_SDK_RES_VERSION),) 386 LOCAL_SDK_RES_VERSION:=$(LOCAL_SDK_VERSION) 387 endif 388 389 framework_res_package_export := 390 # Please refer to package.mk 391 ifneq ($(LOCAL_NO_STANDARD_LIBRARIES),true) 392 ifneq ($(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))),) 393 framework_res_package_export := \ 394 $(call resolve-prebuilt-sdk-jar-path,$(LOCAL_SDK_RES_VERSION)) 395 else 396 framework_res_package_export := \ 397 $(call intermediates-dir-for,APPS,framework-res,,COMMON)/package-export.apk 398 endif 399 endif 400 401 my_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 418 full_android_manifest := 419 my_res_resources := 420 my_overlay_resources := 421 my_compiled_res_base_dir := $(intermediates.COMMON)/flat-res 422 R_file_stamp := 423 proguard_options_file := 424 my_generated_res_dirs := $(intermediates.COMMON)/aar/res 425 my_generated_res_dirs_deps := $(my_src_jar) 426 include $(BUILD_SYSTEM)/aapt2.mk 427 428 # Make sure my_res_package is created when you run mm/mmm. 429 $(built_module) : $(my_res_package) 430 endif # $(my_src_aar) 431 endif # 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 435 my_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 444 endif # ! prebuilt_module_is_dex_javalib 445 endif # LOCAL_IS_HOST_MODULE is not set 446 447 endif # JAVA_LIBRARIES 448 449 endif # APPS 450 451 $(built_module) : $(LOCAL_ADDITIONAL_DEPENDENCIES) 452 453 my_prebuilt_src_file := 454 my_preopt_for_extracted_apk := 455