1# 2# Copyright (C) 2019 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############################################################ 18# Internal build rules for native prebuilt modules 19############################################################ 20 21prebuilt_module_classes := STATIC_LIBRARIES SHARED_LIBRARIES EXECUTABLES NATIVE_TESTS 22ifeq ($(filter $(prebuilt_module_classes),$(LOCAL_MODULE_CLASS)),) 23$(call pretty-error,cc_prebuilt_internal.mk is for $(prebuilt_module_classes) modules only) 24endif 25 26my_strip_module := $(firstword \ 27 $(LOCAL_STRIP_MODULE_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) \ 28 $(LOCAL_STRIP_MODULE)) 29 30ifeq (SHARED_LIBRARIES,$(LOCAL_MODULE_CLASS)) 31 ifeq ($(LOCAL_IS_HOST_MODULE)$(my_strip_module),) 32 # Strip but not try to add debuglink 33 my_strip_module := no_debuglink 34 endif 35endif 36 37ifneq ($(filter STATIC_LIBRARIES SHARED_LIBRARIES,$(LOCAL_MODULE_CLASS)),) 38 prebuilt_module_is_a_library := true 39else 40 prebuilt_module_is_a_library := 41endif 42 43# Don't install static libraries by default. 44ifndef LOCAL_UNINSTALLABLE_MODULE 45ifeq (STATIC_LIBRARIES,$(LOCAL_MODULE_CLASS)) 46 LOCAL_UNINSTALLABLE_MODULE := true 47endif 48endif 49 50my_check_elf_file_shared_lib_files := 51 52ifneq ($(filter true keep_symbols no_debuglink mini-debug-info,$(my_strip_module)),) 53 ifdef LOCAL_IS_HOST_MODULE 54 $(call pretty-error,Cannot strip/pack host module) 55 endif 56 ifeq ($(filter SHARED_LIBRARIES EXECUTABLES NATIVE_TESTS,$(LOCAL_MODULE_CLASS)),) 57 $(call pretty-error,Can strip/pack only shared libraries or executables) 58 endif 59 ifneq ($(LOCAL_PREBUILT_STRIP_COMMENTS),) 60 $(call pretty-error,Cannot strip/pack scripts) 61 endif 62 # Set the arch-specific variables to set up the strip rules 63 LOCAL_STRIP_MODULE_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH) := $(my_strip_module) 64 include $(BUILD_SYSTEM)/dynamic_binary.mk 65 built_module := $(linked_module) 66 67 ifneq ($(LOCAL_SDK_VERSION),) 68 # binary.mk filters out NDK_KNOWN_LIBS from my_shared_libs, thus those NDK libs are not added 69 # to DEPENDENCIES_ON_SHARED_LIBRARIES. Assign $(my_ndk_shared_libraries_fullpath) to 70 # my_check_elf_file_shared_lib_files so that check_elf_file.py can see those NDK stub libs. 71 my_check_elf_file_shared_lib_files := $(my_ndk_shared_libraries_fullpath) 72 endif 73else # my_strip_module not true 74 include $(BUILD_SYSTEM)/base_rules.mk 75 built_module := $(LOCAL_BUILT_MODULE) 76 77ifdef prebuilt_module_is_a_library 78EXPORTS_LIST += $(intermediates) 79EXPORTS.$(intermediates).FLAGS := $(foreach d,$(LOCAL_EXPORT_C_INCLUDE_DIRS),-I $(d)) 80EXPORTS.$(intermediates).DEPS := $(LOCAL_EXPORT_C_INCLUDE_DEPS) 81 82include $(BUILD_SYSTEM)/allowed_ndk_types.mk 83 84ifdef LOCAL_SDK_VERSION 85my_link_type := native:ndk:$(my_ndk_stl_family):$(my_ndk_stl_link_type) 86else ifdef LOCAL_USE_VNDK 87 _name := $(patsubst %.vendor,%,$(LOCAL_MODULE)) 88 _name := $(patsubst %.product,%,$(LOCAL_MODULE)) 89 ifneq ($(filter $(_name),$(VNDK_CORE_LIBRARIES) $(VNDK_SAMEPROCESS_LIBRARIES) $(LLNDK_LIBRARIES)),) 90 ifeq ($(filter $(_name),$(VNDK_PRIVATE_LIBRARIES)),) 91 my_link_type := native:vndk 92 else 93 my_link_type := native:vndk_private 94 endif 95 else 96 ifeq ($(LOCAL_USE_VNDK_PRODUCT),true) 97 my_link_type := native:product 98 else 99 my_link_type := native:vendor 100 endif 101 endif 102else ifneq ($(filter $(TARGET_RECOVERY_OUT)/%,$(LOCAL_MODULE_PATH)),) 103my_link_type := native:recovery 104else 105my_link_type := native:platform 106endif 107 108# TODO: check dependencies of prebuilt files 109my_link_deps := 110 111my_2nd_arch_prefix := $(LOCAL_2ND_ARCH_VAR_PREFIX) 112my_common := 113include $(BUILD_SYSTEM)/link_type.mk 114endif # prebuilt_module_is_a_library 115 116# The real dependency will be added after all Android.mks are loaded and the install paths 117# of the shared libraries are determined. 118ifdef LOCAL_INSTALLED_MODULE 119ifdef LOCAL_IS_HOST_MODULE 120 ifeq ($(LOCAL_SYSTEM_SHARED_LIBRARIES),none) 121 my_system_shared_libraries := 122 else 123 my_system_shared_libraries := $(LOCAL_SYSTEM_SHARED_LIBRARIES) 124 endif 125else 126 ifeq ($(LOCAL_SYSTEM_SHARED_LIBRARIES),none) 127 my_system_shared_libraries := libc libm libdl 128 else 129 my_system_shared_libraries := $(LOCAL_SYSTEM_SHARED_LIBRARIES) 130 my_system_shared_libraries := $(patsubst libc,libc libdl,$(my_system_shared_libraries)) 131 endif 132endif 133 134my_shared_libraries := $(strip \ 135 $(filter-out $(my_system_shared_libraries),$(LOCAL_SHARED_LIBRARIES)) \ 136 $(my_system_shared_libraries)) 137 138# Extra shared libraries introduced by LOCAL_CXX_STL (may append some libraries to 139# my_shared_libraries). 140include $(BUILD_SYSTEM)/cxx_stl_setup.mk 141 142# When compiling against API imported module, use API import stub libraries. 143apiimport_postfix := .apiimport 144 145ifneq ($(LOCAL_USE_VNDK),) 146 ifeq ($(LOCAL_USE_VNDK_PRODUCT),true) 147 apiimport_postfix := .apiimport.product 148 else 149 apiimport_postfix := .apiimport.vendor 150 endif 151endif 152 153ifdef my_shared_libraries 154my_shared_libraries := $(foreach l,$(my_shared_libraries), \ 155 $(if $(filter $(l), $(API_IMPORTED_SHARED_LIBRARIES)), $(l)$(apiimport_postfix), $(l))) 156endif #my_shared_libraries 157 158ifdef my_system_shared_libraries 159my_system_shared_libraries := $(foreach l,$(my_system_shared_libraries), \ 160 $(if $(filter $(l), $(API_IMPORTED_SHARED_LIBRARIES)), $(l)$(apiimport_postfix), $(l))) 161endif #my_system_shared_libraries 162 163ifdef my_shared_libraries 164ifdef LOCAL_USE_VNDK 165 ifeq ($(LOCAL_USE_VNDK_PRODUCT),true) 166 my_shared_libraries := $(foreach l,$(my_shared_libraries),\ 167 $(if $(SPLIT_PRODUCT.SHARED_LIBRARIES.$(l)),$(l).product,$(l))) 168 else 169 my_shared_libraries := $(foreach l,$(my_shared_libraries),\ 170 $(if $(SPLIT_VENDOR.SHARED_LIBRARIES.$(l)),$(l).vendor,$(l))) 171 endif 172endif 173$(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)DEPENDENCIES_ON_SHARED_LIBRARIES += \ 174 $(my_register_name):$(LOCAL_INSTALLED_MODULE):$(subst $(space),$(comma),$(my_shared_libraries)) 175endif # my_shared_libraries 176endif # LOCAL_INSTALLED_MODULE 177 178# We need to enclose the above export_includes and my_built_shared_libraries in 179# "my_strip_module not true" because otherwise the rules are defined in dynamic_binary.mk. 180endif # my_strip_module not true 181 182 183# Check prebuilt ELF binaries. 184include $(BUILD_SYSTEM)/check_elf_file.mk 185 186ifeq ($(NATIVE_COVERAGE),true) 187ifneq (,$(strip $(LOCAL_PREBUILT_COVERAGE_ARCHIVE))) 188 $(eval $(call copy-one-file,$(LOCAL_PREBUILT_COVERAGE_ARCHIVE),$(intermediates)/$(LOCAL_MODULE).gcnodir)) 189 ifneq ($(LOCAL_UNINSTALLABLE_MODULE),true) 190 ifdef LOCAL_IS_HOST_MODULE 191 my_coverage_path := $($(my_prefix)OUT_COVERAGE)/$(patsubst $($(my_prefix)OUT)/%,%,$(my_module_path)) 192 else 193 my_coverage_path := $(TARGET_OUT_COVERAGE)/$(patsubst $(PRODUCT_OUT)/%,%,$(my_module_path)) 194 endif 195 my_coverage_path := $(my_coverage_path)/$(patsubst %.so,%,$(my_installed_module_stem)).gcnodir 196 $(eval $(call copy-one-file,$(LOCAL_PREBUILT_COVERAGE_ARCHIVE),$(my_coverage_path))) 197 $(LOCAL_BUILT_MODULE): $(my_coverage_path) 198 endif 199else 200# Coverage information is needed when static lib is a dependency of another 201# coverage-enabled module. 202ifeq (STATIC_LIBRARIES, $(LOCAL_MODULE_CLASS)) 203GCNO_ARCHIVE := $(LOCAL_MODULE).gcnodir 204$(intermediates)/$(GCNO_ARCHIVE) : PRIVATE_ALL_OBJECTS := 205$(intermediates)/$(GCNO_ARCHIVE) : PRIVATE_ALL_WHOLE_STATIC_LIBRARIES := 206$(intermediates)/$(GCNO_ARCHIVE) : PRIVATE_PREFIX := $(my_prefix) 207$(intermediates)/$(GCNO_ARCHIVE) : PRIVATE_2ND_ARCH_VAR_PREFIX := $(LOCAL_2ND_ARCH_VAR_PREFIX) 208$(intermediates)/$(GCNO_ARCHIVE) : 209 $(transform-o-to-static-lib) 210endif 211endif 212endif 213 214$(built_module) : $(my_prebuilt_src_file) 215 $(transform-prebuilt-to-target) 216ifneq ($(filter EXECUTABLES NATIVE_TESTS,$(LOCAL_MODULE_CLASS)),) 217 $(hide) chmod +x $@ 218endif 219 220