blob: e7866916560b000872896232b5228ea8b30146b7 [file] [log] [blame]
Ying Wang8e20ef62014-06-24 20:01:52 -07001# Install jni libraries for one arch.
2# Input variables:
3# my_2nd_arch_prefix: indicate if this is for TARGET_2ND_ARCH.
4# my_embed_jni: indicate if we want to embed the jni libs in the apk.
5# my_prebuilt_jni_libs
6# my_installed_module_stem (from configure_module_stem.mk)
7# partition_tag (from base_rules.mk)
8# my_prebuilt_src_file (from prebuilt_internal.mk)
9#
10# Output variables:
11# my_jni_shared_libraries, my_jni_shared_libraries_abi, if we are going to embed the libraries into the apk;
Ying Wang1fb01522015-05-01 14:02:26 -070012# my_embedded_prebuilt_jni_libs, prebuilt jni libs embedded in prebuilt apk.
Ying Wang8e20ef62014-06-24 20:01:52 -070013#
14
15my_jni_shared_libraries := \
Dan Willemsen8cf6b652018-09-05 11:01:12 -070016 $(foreach lib,$(LOCAL_JNI_SHARED_LIBRARIES), \
17 $(call intermediates-dir-for,SHARED_LIBRARIES,$(lib),,,$(my_2nd_arch_prefix))/$(lib).so)
Ying Wang8e20ef62014-06-24 20:01:52 -070018
19# App-specific lib path.
Ying Wangaf9757e2014-07-17 21:24:42 -070020my_app_lib_path := $(dir $(LOCAL_INSTALLED_MODULE))lib/$(TARGET_$(my_2nd_arch_prefix)ARCH)
Ying Wang1fb01522015-05-01 14:02:26 -070021my_embedded_prebuilt_jni_libs :=
Ying Wang8e20ef62014-06-24 20:01:52 -070022
23ifdef my_embed_jni
24# App explicitly requires the prebuilt NDK stl shared libraies.
25# The NDK stl shared libraries should never go to the system image.
Dan Albert19fbd1c2018-01-04 13:34:21 -080026ifeq ($(LOCAL_NDK_STL_VARIANT),c++_shared)
Ying Wang8e20ef62014-06-24 20:01:52 -070027ifndef LOCAL_SDK_VERSION
28$(error LOCAL_SDK_VERSION must be defined with LOCAL_NDK_STL_VARIANT, \
29 LOCAL_PACKAGE_NAME=$(LOCAL_PACKAGE_NAME))
30endif
Ying Wang8e20ef62014-06-24 20:01:52 -070031my_jni_shared_libraries += \
Dan Albert609fa6c2016-08-08 17:13:31 -070032 $(HISTORICAL_NDK_VERSIONS_ROOT)/$(LOCAL_NDK_VERSION)/sources/cxx-stl/llvm-libc++/libs/$(TARGET_$(my_2nd_arch_prefix)CPU_ABI)/libc++_shared.so
Ying Wang8e20ef62014-06-24 20:01:52 -070033endif
34
35# Set the abi directory used by the local JNI shared libraries.
36# (Doesn't change how the local shared libraries are compiled, just
37# sets where they are stored in the apk.)
38ifeq ($(LOCAL_JNI_SHARED_LIBRARIES_ABI),)
39 my_jni_shared_libraries_abi := $(TARGET_$(my_2nd_arch_prefix)CPU_ABI)
40else
41 my_jni_shared_libraries_abi := $(LOCAL_JNI_SHARED_LIBRARIES_ABI)
42endif
43
44else # not my_embed_jni
45
46my_jni_shared_libraries := $(strip $(my_jni_shared_libraries))
47ifneq ($(my_jni_shared_libraries),)
48# The jni libaries will be installed to the system.img.
49my_jni_filenames := $(notdir $(my_jni_shared_libraries))
50# Make sure the JNI libraries get installed
Vishwath Mohand4dbf792017-05-16 14:27:34 -070051my_shared_library_path := $(call get_non_asan_path,\
52 $($(my_2nd_arch_prefix)TARGET_OUT$(partition_tag)_SHARED_LIBRARIES))
Ying Wangd358f822015-10-15 15:29:01 -070053# Do not use order-only dependency, because we want to rebuild the image if an jni is updated.
Anton Hansson8b7ecc02018-10-01 16:23:53 +010054my_installed_library := $(addprefix $(my_shared_library_path)/, $(my_jni_filenames))
55$(LOCAL_INSTALLED_MODULE) : $(my_installed_library)
56ALL_MODULES.$(LOCAL_MODULE).INSTALLED += $(my_installed_library)
Ying Wang8e20ef62014-06-24 20:01:52 -070057
58# Create symlink in the app specific lib path
Andreas Gampe445553f2016-12-06 17:56:29 -080059# Skip creating this symlink when running the second part of a target sanitization build.
60ifndef SANITIZE_TARGET
Ying Wang8e20ef62014-06-24 20:01:52 -070061ifdef LOCAL_POST_INSTALL_CMD
62# Add a shell command separator
63LOCAL_POST_INSTALL_CMD += ;
64endif
Ying Wangaf9757e2014-07-17 21:24:42 -070065
66my_symlink_target_dir := $(patsubst $(PRODUCT_OUT)%,%,\
67 $(my_shared_library_path))
Ying Wang8e20ef62014-06-24 20:01:52 -070068LOCAL_POST_INSTALL_CMD += \
69 mkdir -p $(my_app_lib_path) \
Ying Wangaf9757e2014-07-17 21:24:42 -070070 $(foreach lib, $(my_jni_filenames), ;ln -sf $(my_symlink_target_dir)/$(lib) $(my_app_lib_path)/$(lib))
Ying Wang8e20ef62014-06-24 20:01:52 -070071$(LOCAL_INSTALLED_MODULE): PRIVATE_POST_INSTALL_CMD := $(LOCAL_POST_INSTALL_CMD)
Andreas Gampe445553f2016-12-06 17:56:29 -080072else
73ifdef LOCAL_POST_INSTALL_CMD
74$(LOCAL_INSTALLED_MODULE): PRIVATE_POST_INSTALL_CMD := $(LOCAL_POST_INSTALL_CMD)
75endif
76endif
Ying Wang8e20ef62014-06-24 20:01:52 -070077
78# Clear jni_shared_libraries to not embed it into the apk.
79my_jni_shared_libraries :=
80endif # $(my_jni_shared_libraries) not empty
81endif # my_embed_jni
82
83ifdef my_prebuilt_jni_libs
Ying Wang1fb01522015-05-01 14:02:26 -070084# Files like @lib/<abi>/libfoo.so (path inside the apk) are JNI libs embedded prebuilt apk;
Ying Wang8e20ef62014-06-24 20:01:52 -070085# Files like path/to/libfoo.so (path relative to LOCAL_PATH) are prebuilts in the source tree.
Ying Wang1fb01522015-05-01 14:02:26 -070086my_embedded_prebuilt_jni_libs := $(patsubst @%,%, \
Ying Wang8e20ef62014-06-24 20:01:52 -070087 $(filter @%, $(my_prebuilt_jni_libs)))
Ying Wang8e20ef62014-06-24 20:01:52 -070088
89# prebuilt JNI exsiting as separate source files.
90my_prebuilt_jni_libs := $(addprefix $(LOCAL_PATH)/, \
91 $(filter-out @%, $(my_prebuilt_jni_libs)))
92ifdef my_prebuilt_jni_libs
Ying Wange66d7c12015-02-12 11:29:41 -080093ifdef my_embed_jni
94# Embed my_prebuilt_jni_libs to the apk
95my_jni_shared_libraries += $(my_prebuilt_jni_libs)
96else # not my_embed_jni
97# Install my_prebuilt_jni_libs as separate files.
Ying Wang8e20ef62014-06-24 20:01:52 -070098$(foreach lib, $(my_prebuilt_jni_libs), \
99 $(eval $(call copy-one-file, $(lib), $(my_app_lib_path)/$(notdir $(lib)))))
100
Anton Hansson8b7ecc02018-10-01 16:23:53 +0100101my_installed_library := $(addprefix $(my_app_lib_path)/, $(notdir $(my_prebuilt_jni_libs)))
102$(LOCAL_INSTALLED_MODULE) : $(my_installed_library)
103ALL_MODULES.$(LOCAL_MODULE).INSTALLED += $(my_installed_library)
Ying Wange66d7c12015-02-12 11:29:41 -0800104endif # my_embed_jni
Ying Wang8e20ef62014-06-24 20:01:52 -0700105endif # inner my_prebuilt_jni_libs
106endif # outer my_prebuilt_jni_libs
Dan Willemsenb097fbe2016-06-07 14:25:14 -0700107
108# Verify that all included libraries are built against the NDK
Dan Albert975e3032017-12-19 11:26:05 -0800109include $(BUILD_SYSTEM)/allowed_ndk_types.mk
Dan Willemsenb097fbe2016-06-07 14:25:14 -0700110ifneq ($(strip $(LOCAL_JNI_SHARED_LIBRARIES)),)
Dan Willemsenb097fbe2016-06-07 14:25:14 -0700111ifneq ($(LOCAL_SDK_VERSION),)
Dan Willemsenb47d4e92017-04-08 00:31:31 -0700112my_link_type := app:sdk
Dan Albert975e3032017-12-19 11:26:05 -0800113my_warn_types := native:platform $(my_warn_ndk_types)
114my_allowed_types := $(my_allowed_ndk_types)
Jiyong Park49a5b972018-04-12 17:10:05 +0900115 ifneq (,$(filter true,$(LOCAL_VENDOR_MODULE) $(LOCAL_ODM_MODULE) $(LOCAL_PROPRIETARY_MODULE)))
116 my_allowed_types += native:vendor native:vndk
117 endif
Dan Willemsenb097fbe2016-06-07 14:25:14 -0700118else
Dan Willemsenb47d4e92017-04-08 00:31:31 -0700119my_link_type := app:platform
Dan Albert975e3032017-12-19 11:26:05 -0800120my_warn_types := $(my_warn_ndk_types)
121my_allowed_types := $(my_allowed_ndk_types) native:platform native:vendor native:vndk native:vndk_private
Dan Willemsenb097fbe2016-06-07 14:25:14 -0700122endif
Dan Willemsenb097fbe2016-06-07 14:25:14 -0700123
Dan Willemsenb47d4e92017-04-08 00:31:31 -0700124my_link_deps := $(addprefix SHARED_LIBRARIES:,$(LOCAL_JNI_SHARED_LIBRARIES))
Dan Willemsenb097fbe2016-06-07 14:25:14 -0700125
Dan Willemsenb47d4e92017-04-08 00:31:31 -0700126my_common :=
127include $(BUILD_SYSTEM)/link_type.mk
Dan Willemsenb097fbe2016-06-07 14:25:14 -0700128endif