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 |
| 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_MIGRATED_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 |
| 73 | else # my_strip_module not true |
| 74 | include $(BUILD_SYSTEM)/base_rules.mk |
| 75 | built_module := $(LOCAL_BUILT_MODULE) |
| 76 | |
| 77 | ifdef prebuilt_module_is_a_library |
| 78 | export_includes := $(intermediates)/export_includes |
| 79 | export_cflags := $(foreach d,$(LOCAL_EXPORT_C_INCLUDE_DIRS),-I $(d)) |
| 80 | $(export_includes): PRIVATE_EXPORT_CFLAGS := $(export_cflags) |
| 81 | $(export_includes): $(LOCAL_EXPORT_C_INCLUDE_DEPS) |
| 82 | @echo Export includes file: $< -- $@ |
| 83 | $(hide) mkdir -p $(dir $@) && rm -f $@ |
| 84 | ifdef export_cflags |
| 85 | $(hide) echo "$(PRIVATE_EXPORT_CFLAGS)" >$@ |
| 86 | else |
| 87 | $(hide) touch $@ |
| 88 | endif |
| 89 | export_cflags := |
| 90 | |
| 91 | include $(BUILD_SYSTEM)/allowed_ndk_types.mk |
| 92 | |
| 93 | ifdef LOCAL_SDK_VERSION |
| 94 | my_link_type := native:ndk:$(my_ndk_stl_family):$(my_ndk_stl_link_type) |
| 95 | else ifdef LOCAL_USE_VNDK |
| 96 | _name := $(patsubst %.vendor,%,$(LOCAL_MODULE)) |
| 97 | ifneq ($(filter $(_name),$(VNDK_CORE_LIBRARIES) $(VNDK_SAMEPROCESS_LIBRARIES) $(LLNDK_LIBRARIES)),) |
| 98 | ifeq ($(filter $(_name),$(VNDK_PRIVATE_LIBRARIES)),) |
| 99 | my_link_type := native:vndk |
| 100 | else |
| 101 | my_link_type := native:vndk_private |
| 102 | endif |
| 103 | else |
| 104 | my_link_type := native:vendor |
| 105 | endif |
| 106 | else ifneq ($(filter $(TARGET_RECOVERY_OUT)/%,$(LOCAL_MODULE_PATH)),) |
| 107 | my_link_type := native:recovery |
| 108 | else |
| 109 | my_link_type := native:platform |
| 110 | endif |
| 111 | |
| 112 | # TODO: check dependencies of prebuilt files |
| 113 | my_link_deps := |
| 114 | |
| 115 | my_2nd_arch_prefix := $(LOCAL_2ND_ARCH_VAR_PREFIX) |
| 116 | my_common := |
| 117 | include $(BUILD_SYSTEM)/link_type.mk |
| 118 | endif # prebuilt_module_is_a_library |
| 119 | |
| 120 | # The real dependency will be added after all Android.mks are loaded and the install paths |
| 121 | # of the shared libraries are determined. |
| 122 | ifdef LOCAL_INSTALLED_MODULE |
| 123 | ifdef LOCAL_IS_HOST_MODULE |
| 124 | ifeq ($(LOCAL_SYSTEM_SHARED_LIBRARIES),none) |
| 125 | my_system_shared_libraries := |
| 126 | else |
| 127 | my_system_shared_libraries := $(LOCAL_SYSTEM_SHARED_LIBRARIES) |
| 128 | endif |
| 129 | else |
| 130 | ifeq ($(LOCAL_SYSTEM_SHARED_LIBRARIES),none) |
| 131 | my_system_shared_libraries := libc libm libdl |
| 132 | else |
| 133 | my_system_shared_libraries := $(LOCAL_SYSTEM_SHARED_LIBRARIES) |
| 134 | my_system_shared_libraries := $(patsubst libc,libc libdl,$(my_system_shared_libraries)) |
| 135 | endif |
| 136 | endif |
| 137 | |
Logan Chien | e984ebb | 2019-07-11 14:00:04 -0700 | [diff] [blame^] | 138 | my_shared_libraries := $(strip \ |
Jaewoong Jung | f22997e | 2019-03-20 10:35:43 -0700 | [diff] [blame] | 139 | $(filter-out $(my_system_shared_libraries),$(LOCAL_SHARED_LIBRARIES)) \ |
Logan Chien | e984ebb | 2019-07-11 14:00:04 -0700 | [diff] [blame^] | 140 | $(my_system_shared_libraries)) |
Jaewoong Jung | f22997e | 2019-03-20 10:35:43 -0700 | [diff] [blame] | 141 | |
Logan Chien | a45d6f5 | 2019-07-11 15:11:04 -0700 | [diff] [blame] | 142 | # Extra shared libraries introduced by LOCAL_CXX_STL (may append some libraries to |
| 143 | # my_shared_libraries). |
Jaewoong Jung | f22997e | 2019-03-20 10:35:43 -0700 | [diff] [blame] | 144 | include $(BUILD_SYSTEM)/cxx_stl_setup.mk |
Logan Chien | a45d6f5 | 2019-07-11 15:11:04 -0700 | [diff] [blame] | 145 | |
| 146 | ifdef my_shared_libraries |
Jaewoong Jung | f22997e | 2019-03-20 10:35:43 -0700 | [diff] [blame] | 147 | ifdef LOCAL_USE_VNDK |
| 148 | my_shared_libraries := $(foreach l,$(my_shared_libraries),\ |
| 149 | $(if $(SPLIT_VENDOR.SHARED_LIBRARIES.$(l)),$(l).vendor,$(l))) |
| 150 | endif |
| 151 | $(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)DEPENDENCIES_ON_SHARED_LIBRARIES += \ |
| 152 | $(my_register_name):$(LOCAL_INSTALLED_MODULE):$(subst $(space),$(comma),$(my_shared_libraries)) |
Jaewoong Jung | f22997e | 2019-03-20 10:35:43 -0700 | [diff] [blame] | 153 | endif # my_shared_libraries |
Logan Chien | a45d6f5 | 2019-07-11 15:11:04 -0700 | [diff] [blame] | 154 | endif # LOCAL_INSTALLED_MODULE |
Jaewoong Jung | f22997e | 2019-03-20 10:35:43 -0700 | [diff] [blame] | 155 | |
| 156 | # We need to enclose the above export_includes and my_built_shared_libraries in |
| 157 | # "my_strip_module not true" because otherwise the rules are defined in dynamic_binary.mk. |
| 158 | endif # my_strip_module not true |
| 159 | |
| 160 | |
| 161 | # Check prebuilt ELF binaries. |
| 162 | include $(BUILD_SYSTEM)/check_elf_file.mk |
| 163 | |
| 164 | ifeq ($(NATIVE_COVERAGE),true) |
| 165 | ifneq (,$(strip $(LOCAL_PREBUILT_COVERAGE_ARCHIVE))) |
| 166 | $(eval $(call copy-one-file,$(LOCAL_PREBUILT_COVERAGE_ARCHIVE),$(intermediates)/$(LOCAL_MODULE).gcnodir)) |
| 167 | ifneq ($(LOCAL_UNINSTALLABLE_MODULE),true) |
| 168 | ifdef LOCAL_IS_HOST_MODULE |
| 169 | my_coverage_path := $($(my_prefix)OUT_COVERAGE)/$(patsubst $($(my_prefix)OUT)/%,%,$(my_module_path)) |
| 170 | else |
| 171 | my_coverage_path := $(TARGET_OUT_COVERAGE)/$(patsubst $(PRODUCT_OUT)/%,%,$(my_module_path)) |
| 172 | endif |
| 173 | my_coverage_path := $(my_coverage_path)/$(patsubst %.so,%,$(my_installed_module_stem)).gcnodir |
| 174 | $(eval $(call copy-one-file,$(LOCAL_PREBUILT_COVERAGE_ARCHIVE),$(my_coverage_path))) |
| 175 | $(LOCAL_BUILT_MODULE): $(my_coverage_path) |
| 176 | endif |
| 177 | else |
| 178 | # Coverage information is needed when static lib is a dependency of another |
| 179 | # coverage-enabled module. |
| 180 | ifeq (STATIC_LIBRARIES, $(LOCAL_MODULE_CLASS)) |
| 181 | GCNO_ARCHIVE := $(LOCAL_MODULE).gcnodir |
| 182 | $(intermediates)/$(GCNO_ARCHIVE) : PRIVATE_ALL_OBJECTS := |
| 183 | $(intermediates)/$(GCNO_ARCHIVE) : PRIVATE_ALL_WHOLE_STATIC_LIBRARIES := |
| 184 | $(intermediates)/$(GCNO_ARCHIVE) : PRIVATE_PREFIX := $(my_prefix) |
| 185 | $(intermediates)/$(GCNO_ARCHIVE) : PRIVATE_2ND_ARCH_VAR_PREFIX := $(LOCAL_2ND_ARCH_VAR_PREFIX) |
| 186 | $(intermediates)/$(GCNO_ARCHIVE) : |
| 187 | $(transform-o-to-static-lib) |
| 188 | endif |
| 189 | endif |
| 190 | endif |
| 191 | |
| 192 | ifneq ($(filter init%rc,$(notdir $(LOCAL_INSTALLED_MODULE)))$(filter %/etc/init,$(dir $(LOCAL_INSTALLED_MODULE))),) |
| 193 | $(eval $(call copy-init-script-file-checked,$(my_prebuilt_src_file),$(built_module))) |
| 194 | else ifneq ($(LOCAL_PREBUILT_STRIP_COMMENTS),) |
| 195 | $(built_module) : $(my_prebuilt_src_file) |
| 196 | $(transform-prebuilt-to-target-strip-comments) |
| 197 | else |
| 198 | $(built_module) : $(my_prebuilt_src_file) |
| 199 | $(transform-prebuilt-to-target) |
| 200 | endif |
| 201 | ifneq ($(filter EXECUTABLES NATIVE_TESTS,$(LOCAL_MODULE_CLASS)),) |
| 202 | $(hide) chmod +x $@ |
| 203 | endif |
| 204 | |