blob: 265d4824108565649d89b93b72d6f2ac9d6a3ce1 [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 := \
16 $(addprefix $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/, \
17 $(addsuffix .so, \
18 $(LOCAL_JNI_SHARED_LIBRARIES)))
19
20# App-specific lib path.
Ying Wangaf9757e2014-07-17 21:24:42 -070021my_app_lib_path := $(dir $(LOCAL_INSTALLED_MODULE))lib/$(TARGET_$(my_2nd_arch_prefix)ARCH)
Ying Wang1fb01522015-05-01 14:02:26 -070022my_embedded_prebuilt_jni_libs :=
Ying Wang8e20ef62014-06-24 20:01:52 -070023
24ifdef my_embed_jni
25# App explicitly requires the prebuilt NDK stl shared libraies.
26# The NDK stl shared libraries should never go to the system image.
27ifneq ($(filter $(LOCAL_NDK_STL_VARIANT), stlport_shared c++_shared),)
28ifndef LOCAL_SDK_VERSION
29$(error LOCAL_SDK_VERSION must be defined with LOCAL_NDK_STL_VARIANT, \
30 LOCAL_PACKAGE_NAME=$(LOCAL_PACKAGE_NAME))
31endif
32endif
33ifeq (stlport_shared,$(LOCAL_NDK_STL_VARIANT))
34my_jni_shared_libraries += \
Dan Albert609fa6c2016-08-08 17:13:31 -070035 $(HISTORICAL_NDK_VERSIONS_ROOT)/$(LOCAL_NDK_VERSION)/sources/cxx-stl/stlport/libs/$(TARGET_$(my_2nd_arch_prefix)CPU_ABI)/libstlport_shared.so
Ying Wang8e20ef62014-06-24 20:01:52 -070036else ifeq (c++_shared,$(LOCAL_NDK_STL_VARIANT))
37my_jni_shared_libraries += \
Dan Albert609fa6c2016-08-08 17:13:31 -070038 $(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 -070039endif
40
41# Set the abi directory used by the local JNI shared libraries.
42# (Doesn't change how the local shared libraries are compiled, just
43# sets where they are stored in the apk.)
44ifeq ($(LOCAL_JNI_SHARED_LIBRARIES_ABI),)
45 my_jni_shared_libraries_abi := $(TARGET_$(my_2nd_arch_prefix)CPU_ABI)
46else
47 my_jni_shared_libraries_abi := $(LOCAL_JNI_SHARED_LIBRARIES_ABI)
48endif
49
50else # not my_embed_jni
51
52my_jni_shared_libraries := $(strip $(my_jni_shared_libraries))
53ifneq ($(my_jni_shared_libraries),)
54# The jni libaries will be installed to the system.img.
55my_jni_filenames := $(notdir $(my_jni_shared_libraries))
56# Make sure the JNI libraries get installed
Vishwath Mohand4dbf792017-05-16 14:27:34 -070057my_shared_library_path := $(call get_non_asan_path,\
58 $($(my_2nd_arch_prefix)TARGET_OUT$(partition_tag)_SHARED_LIBRARIES))
Ying Wangd358f822015-10-15 15:29:01 -070059# Do not use order-only dependency, because we want to rebuild the image if an jni is updated.
60$(LOCAL_INSTALLED_MODULE) : $(addprefix $(my_shared_library_path)/, $(my_jni_filenames))
Ying Wang8e20ef62014-06-24 20:01:52 -070061
62# Create symlink in the app specific lib path
Andreas Gampe445553f2016-12-06 17:56:29 -080063# Skip creating this symlink when running the second part of a target sanitization build.
64ifndef SANITIZE_TARGET
Ying Wang8e20ef62014-06-24 20:01:52 -070065ifdef LOCAL_POST_INSTALL_CMD
66# Add a shell command separator
67LOCAL_POST_INSTALL_CMD += ;
68endif
Ying Wangaf9757e2014-07-17 21:24:42 -070069
70my_symlink_target_dir := $(patsubst $(PRODUCT_OUT)%,%,\
71 $(my_shared_library_path))
Ying Wang8e20ef62014-06-24 20:01:52 -070072LOCAL_POST_INSTALL_CMD += \
73 mkdir -p $(my_app_lib_path) \
Ying Wangaf9757e2014-07-17 21:24:42 -070074 $(foreach lib, $(my_jni_filenames), ;ln -sf $(my_symlink_target_dir)/$(lib) $(my_app_lib_path)/$(lib))
Ying Wang8e20ef62014-06-24 20:01:52 -070075$(LOCAL_INSTALLED_MODULE): PRIVATE_POST_INSTALL_CMD := $(LOCAL_POST_INSTALL_CMD)
Andreas Gampe445553f2016-12-06 17:56:29 -080076else
77ifdef LOCAL_POST_INSTALL_CMD
78$(LOCAL_INSTALLED_MODULE): PRIVATE_POST_INSTALL_CMD := $(LOCAL_POST_INSTALL_CMD)
79endif
80endif
Ying Wang8e20ef62014-06-24 20:01:52 -070081
82# Clear jni_shared_libraries to not embed it into the apk.
83my_jni_shared_libraries :=
84endif # $(my_jni_shared_libraries) not empty
85endif # my_embed_jni
86
87ifdef my_prebuilt_jni_libs
Ying Wang1fb01522015-05-01 14:02:26 -070088# Files like @lib/<abi>/libfoo.so (path inside the apk) are JNI libs embedded prebuilt apk;
Ying Wang8e20ef62014-06-24 20:01:52 -070089# Files like path/to/libfoo.so (path relative to LOCAL_PATH) are prebuilts in the source tree.
Ying Wang1fb01522015-05-01 14:02:26 -070090my_embedded_prebuilt_jni_libs := $(patsubst @%,%, \
Ying Wang8e20ef62014-06-24 20:01:52 -070091 $(filter @%, $(my_prebuilt_jni_libs)))
Ying Wang8e20ef62014-06-24 20:01:52 -070092
93# prebuilt JNI exsiting as separate source files.
94my_prebuilt_jni_libs := $(addprefix $(LOCAL_PATH)/, \
95 $(filter-out @%, $(my_prebuilt_jni_libs)))
96ifdef my_prebuilt_jni_libs
Ying Wange66d7c12015-02-12 11:29:41 -080097ifdef my_embed_jni
98# Embed my_prebuilt_jni_libs to the apk
99my_jni_shared_libraries += $(my_prebuilt_jni_libs)
100else # not my_embed_jni
101# Install my_prebuilt_jni_libs as separate files.
Ying Wang8e20ef62014-06-24 20:01:52 -0700102$(foreach lib, $(my_prebuilt_jni_libs), \
103 $(eval $(call copy-one-file, $(lib), $(my_app_lib_path)/$(notdir $(lib)))))
104
Ying Wangd358f822015-10-15 15:29:01 -0700105$(LOCAL_INSTALLED_MODULE) : $(addprefix $(my_app_lib_path)/, $(notdir $(my_prebuilt_jni_libs)))
Ying Wange66d7c12015-02-12 11:29:41 -0800106endif # my_embed_jni
Ying Wang8e20ef62014-06-24 20:01:52 -0700107endif # inner my_prebuilt_jni_libs
108endif # outer my_prebuilt_jni_libs
Dan Willemsenb097fbe2016-06-07 14:25:14 -0700109
110# Verify that all included libraries are built against the NDK
111ifneq ($(strip $(LOCAL_JNI_SHARED_LIBRARIES)),)
Dan Willemsenb097fbe2016-06-07 14:25:14 -0700112ifneq ($(LOCAL_SDK_VERSION),)
Dan Willemsenb47d4e92017-04-08 00:31:31 -0700113my_link_type := app:sdk
114my_warn_types := native:platform
115my_allowed_types := native:ndk
Dan Willemsenb097fbe2016-06-07 14:25:14 -0700116else
Dan Willemsenb47d4e92017-04-08 00:31:31 -0700117my_link_type := app:platform
118my_warn_types :=
Jiyong Parka3fb1582017-08-16 18:28:12 +0900119my_allowed_types := native:ndk native:platform native:vendor native:vndk native:vndk_private
Dan Willemsenb097fbe2016-06-07 14:25:14 -0700120endif
Dan Willemsenb097fbe2016-06-07 14:25:14 -0700121
Dan Willemsenb47d4e92017-04-08 00:31:31 -0700122my_link_deps := $(addprefix SHARED_LIBRARIES:,$(LOCAL_JNI_SHARED_LIBRARIES))
Dan Willemsenb097fbe2016-06-07 14:25:14 -0700123
Dan Willemsenb47d4e92017-04-08 00:31:31 -0700124my_common :=
125include $(BUILD_SYSTEM)/link_type.mk
Dan Willemsenb097fbe2016-06-07 14:25:14 -0700126endif