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