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