blob: a8930d5998ccced45add4cdd3d4960a51a84371b [file] [log] [blame]
Jaewoong Jungf22997e2019-03-20 10:35:43 -07001#
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 Han36c1f672019-05-28 17:17:47 +090021prebuilt_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
Jaewoong Jungf22997e2019-03-20 10:35:43 -070026my_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_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
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
Dan Willemsen18ffd582019-07-31 10:31:20 -070078EXPORTS_LIST := $(EXPORTS_LIST) $(intermediates)
79EXPORTS.$(intermediates).FLAGS := $(foreach d,$(LOCAL_EXPORT_C_INCLUDE_DIRS),-I $(d))
80EXPORTS.$(intermediates).DEPS := $(LOCAL_EXPORT_C_INCLUDE_DEPS)
Jaewoong Jungf22997e2019-03-20 10:35:43 -070081
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 ifneq ($(filter $(_name),$(VNDK_CORE_LIBRARIES) $(VNDK_SAMEPROCESS_LIBRARIES) $(LLNDK_LIBRARIES)),)
89 ifeq ($(filter $(_name),$(VNDK_PRIVATE_LIBRARIES)),)
90 my_link_type := native:vndk
91 else
92 my_link_type := native:vndk_private
93 endif
94 else
95 my_link_type := native:vendor
96 endif
97else ifneq ($(filter $(TARGET_RECOVERY_OUT)/%,$(LOCAL_MODULE_PATH)),)
98my_link_type := native:recovery
99else
100my_link_type := native:platform
101endif
102
103# TODO: check dependencies of prebuilt files
104my_link_deps :=
105
106my_2nd_arch_prefix := $(LOCAL_2ND_ARCH_VAR_PREFIX)
107my_common :=
108include $(BUILD_SYSTEM)/link_type.mk
109endif # prebuilt_module_is_a_library
110
111# The real dependency will be added after all Android.mks are loaded and the install paths
112# of the shared libraries are determined.
113ifdef LOCAL_INSTALLED_MODULE
114ifdef LOCAL_IS_HOST_MODULE
115 ifeq ($(LOCAL_SYSTEM_SHARED_LIBRARIES),none)
116 my_system_shared_libraries :=
117 else
118 my_system_shared_libraries := $(LOCAL_SYSTEM_SHARED_LIBRARIES)
119 endif
120else
121 ifeq ($(LOCAL_SYSTEM_SHARED_LIBRARIES),none)
122 my_system_shared_libraries := libc libm libdl
123 else
124 my_system_shared_libraries := $(LOCAL_SYSTEM_SHARED_LIBRARIES)
125 my_system_shared_libraries := $(patsubst libc,libc libdl,$(my_system_shared_libraries))
126 endif
127endif
128
Logan Chiene984ebb2019-07-11 14:00:04 -0700129my_shared_libraries := $(strip \
Jaewoong Jungf22997e2019-03-20 10:35:43 -0700130 $(filter-out $(my_system_shared_libraries),$(LOCAL_SHARED_LIBRARIES)) \
Logan Chiene984ebb2019-07-11 14:00:04 -0700131 $(my_system_shared_libraries))
Jaewoong Jungf22997e2019-03-20 10:35:43 -0700132
Logan Chiena45d6f52019-07-11 15:11:04 -0700133# Extra shared libraries introduced by LOCAL_CXX_STL (may append some libraries to
134# my_shared_libraries).
Jaewoong Jungf22997e2019-03-20 10:35:43 -0700135include $(BUILD_SYSTEM)/cxx_stl_setup.mk
Logan Chiena45d6f52019-07-11 15:11:04 -0700136
137ifdef my_shared_libraries
Jaewoong Jungf22997e2019-03-20 10:35:43 -0700138ifdef LOCAL_USE_VNDK
139 my_shared_libraries := $(foreach l,$(my_shared_libraries),\
140 $(if $(SPLIT_VENDOR.SHARED_LIBRARIES.$(l)),$(l).vendor,$(l)))
141endif
142$(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)DEPENDENCIES_ON_SHARED_LIBRARIES += \
143 $(my_register_name):$(LOCAL_INSTALLED_MODULE):$(subst $(space),$(comma),$(my_shared_libraries))
Jaewoong Jungf22997e2019-03-20 10:35:43 -0700144endif # my_shared_libraries
Logan Chiena45d6f52019-07-11 15:11:04 -0700145endif # LOCAL_INSTALLED_MODULE
Jaewoong Jungf22997e2019-03-20 10:35:43 -0700146
147# We need to enclose the above export_includes and my_built_shared_libraries in
148# "my_strip_module not true" because otherwise the rules are defined in dynamic_binary.mk.
149endif # my_strip_module not true
150
151
152# Check prebuilt ELF binaries.
153include $(BUILD_SYSTEM)/check_elf_file.mk
154
155ifeq ($(NATIVE_COVERAGE),true)
156ifneq (,$(strip $(LOCAL_PREBUILT_COVERAGE_ARCHIVE)))
157 $(eval $(call copy-one-file,$(LOCAL_PREBUILT_COVERAGE_ARCHIVE),$(intermediates)/$(LOCAL_MODULE).gcnodir))
158 ifneq ($(LOCAL_UNINSTALLABLE_MODULE),true)
159 ifdef LOCAL_IS_HOST_MODULE
160 my_coverage_path := $($(my_prefix)OUT_COVERAGE)/$(patsubst $($(my_prefix)OUT)/%,%,$(my_module_path))
161 else
162 my_coverage_path := $(TARGET_OUT_COVERAGE)/$(patsubst $(PRODUCT_OUT)/%,%,$(my_module_path))
163 endif
164 my_coverage_path := $(my_coverage_path)/$(patsubst %.so,%,$(my_installed_module_stem)).gcnodir
165 $(eval $(call copy-one-file,$(LOCAL_PREBUILT_COVERAGE_ARCHIVE),$(my_coverage_path)))
166 $(LOCAL_BUILT_MODULE): $(my_coverage_path)
167 endif
168else
169# Coverage information is needed when static lib is a dependency of another
170# coverage-enabled module.
171ifeq (STATIC_LIBRARIES, $(LOCAL_MODULE_CLASS))
172GCNO_ARCHIVE := $(LOCAL_MODULE).gcnodir
173$(intermediates)/$(GCNO_ARCHIVE) : PRIVATE_ALL_OBJECTS :=
174$(intermediates)/$(GCNO_ARCHIVE) : PRIVATE_ALL_WHOLE_STATIC_LIBRARIES :=
175$(intermediates)/$(GCNO_ARCHIVE) : PRIVATE_PREFIX := $(my_prefix)
176$(intermediates)/$(GCNO_ARCHIVE) : PRIVATE_2ND_ARCH_VAR_PREFIX := $(LOCAL_2ND_ARCH_VAR_PREFIX)
177$(intermediates)/$(GCNO_ARCHIVE) :
178 $(transform-o-to-static-lib)
179endif
180endif
181endif
182
183ifneq ($(filter init%rc,$(notdir $(LOCAL_INSTALLED_MODULE)))$(filter %/etc/init,$(dir $(LOCAL_INSTALLED_MODULE))),)
184 $(eval $(call copy-init-script-file-checked,$(my_prebuilt_src_file),$(built_module)))
185else ifneq ($(LOCAL_PREBUILT_STRIP_COMMENTS),)
186$(built_module) : $(my_prebuilt_src_file)
187 $(transform-prebuilt-to-target-strip-comments)
188else
189$(built_module) : $(my_prebuilt_src_file)
190 $(transform-prebuilt-to-target)
191endif
192ifneq ($(filter EXECUTABLES NATIVE_TESTS,$(LOCAL_MODULE_CLASS)),)
193 $(hide) chmod +x $@
194endif
195