blob: 464a2a20eec56be5a41ad3adf4e99f379f1ee1b1 [file] [log] [blame]
Ying Wang695e8262014-04-17 13:38:04 -07001# Decides how to install the jni libraries needed by an apk.
2# Input variables:
3# LOCAL_JNI_SHARED_LIBRARIES
4# LOCAL_INSTALLED_MODULE
5# rs_compatibility_jni_libs (from java.mk)
6# my_module_path (from base_rules.mk)
7# partition_tag (from base_rules.mk)
8#
9# Output variables:
10# jni_shared_libraries, jni_shared_libraries_abi, if we are going to embed the libraries into the apk.
11#
12
13jni_shared_libraries := \
14 $(addprefix $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_OUT_INTERMEDIATE_LIBRARIES)/, \
15 $(addsuffix .so, \
16 $(LOCAL_JNI_SHARED_LIBRARIES)))
17
18# Include RS dynamically-generated libraries as well
19# Keep this ifneq, as the += otherwise adds spaces that need to be stripped.
20ifneq ($(rs_compatibility_jni_libs),)
21jni_shared_libraries += $(rs_compatibility_jni_libs)
22endif
23
24my_embed_jni :=
25ifneq ($(TARGET_BUILD_APPS),)
26my_embed_jni := true
27endif
28ifneq ($(filter tests samples, $(LOCAL_MODULE_TAGS)),)
29my_embed_jni := true
30endif
31ifeq ($(filter $(TARGET_OUT)/% $(TARGET_OUT_VENDOR)/% $(TARGET_OUT_OEM)/%, $(my_module_path)),)
32# If this app isn't to be installed to system partitions.
33my_embed_jni := true
34endif
35
36ifdef my_embed_jni
37# App explicitly requires the prebuilt NDK stl shared libraies.
38# The NDK stl shared libraries should never go to the system image.
39ifneq ($(filter $(LOCAL_NDK_STL_VARIANT), stlport_shared c++_shared),)
40ifndef LOCAL_SDK_VERSION
41$(error LOCAL_SDK_VERSION must be defined with LOCAL_NDK_STL_VARIANT, \
42 LOCAL_PACKAGE_NAME=$(LOCAL_PACKAGE_NAME))
43endif
44endif
45ifeq (stlport_shared,$(LOCAL_NDK_STL_VARIANT))
46jni_shared_libraries += \
47 $(HISTORICAL_NDK_VERSIONS_ROOT)/current/sources/cxx-stl/stlport/libs/$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)CPU_ABI)/libstlport_shared.so
48else ifeq (c++_shared,$(LOCAL_NDK_STL_VARIANT))
49jni_shared_libraries += \
50 $(HISTORICAL_NDK_VERSIONS_ROOT)/current/sources/cxx-stl/llvm-libc++/libs/$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)CPU_ABI)/libc++_shared.so
51endif
52
53# Set the abi directory used by the local JNI shared libraries.
54# (Doesn't change how the local shared libraries are compiled, just
55# sets where they are stored in the apk.)
56ifeq ($(LOCAL_JNI_SHARED_LIBRARIES_ABI),)
57 jni_shared_libraries_abi := $(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)CPU_ABI)
58else
59 jni_shared_libraries_abi := $(LOCAL_JNI_SHARED_LIBRARIES_ABI)
60endif
61
62else # not my_embed_jni
63
64jni_shared_libraries := $(strip $(jni_shared_libraries))
65ifneq ($(jni_shared_libraries),)
66# The jni libaries will be installed to the system.img.
67my_jni_filenames := $(notdir $(jni_shared_libraries))
68# Make sure the JNI libraries get installed
69$(LOCAL_INSTALLED_MODULE) : | $(addprefix $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET$(partition_tag)_OUT_SHARED_LIBRARIES)/, $(my_jni_filenames))
70
71# Create symlink in the app specific lib path
72ifdef LOCAL_POST_INSTALL_CMD
73my_leading_separator := ;
74else
75my_leading_separator :=
76endif
77my_app_lib_path := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET$(partition_tag)_OUT_SHARED_LIBRARIES)/$(basename $(LOCAL_INSTALLED_MODULE_STEM))
78$(LOCAL_INSTALLED_MODULE): PRIVATE_POST_INSTALL_CMD += \
79 $(my_leading_separator)mkdir -p $(my_app_lib_path) \
80 $(foreach lib, $(my_jni_filenames), ;ln -sf ../$(lib) $(my_app_lib_path)/$(lib))
81
82# Clear jni_shared_libraries to not embed it into the apk.
83jni_shared_libraries :=
84endif # $(jni_shared_libraries) not empty
85endif # my_embed_jni