blob: c28bb15d350cdfd640a7d621d28a6560d1a754c0 [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;
12# my_extracted_jni_libs, if we extract jni libs from prebuilt apk.
13#
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 Wang8e20ef62014-06-24 20:01:52 -070022my_extracted_jni_libs :=
23
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 += \
35 $(HISTORICAL_NDK_VERSIONS_ROOT)/current/sources/cxx-stl/stlport/libs/$(TARGET_$(my_2nd_arch_prefix)CPU_ABI)/libstlport_shared.so
36else ifeq (c++_shared,$(LOCAL_NDK_STL_VARIANT))
37my_jni_shared_libraries += \
38 $(HISTORICAL_NDK_VERSIONS_ROOT)/current/sources/cxx-stl/llvm-libc++/libs/$(TARGET_$(my_2nd_arch_prefix)CPU_ABI)/libc++_shared.so
39endif
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
Ying Wangaf9757e2014-07-17 21:24:42 -070057my_shared_library_path := $($(my_2nd_arch_prefix)TARGET_OUT$(partition_tag)_SHARED_LIBRARIES)
58$(LOCAL_INSTALLED_MODULE) : | $(addprefix $(my_shared_library_path)/, $(my_jni_filenames))
Ying Wang8e20ef62014-06-24 20:01:52 -070059
60# Create symlink in the app specific lib path
61ifdef 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)
72
73# Clear jni_shared_libraries to not embed it into the apk.
74my_jni_shared_libraries :=
75endif # $(my_jni_shared_libraries) not empty
76endif # my_embed_jni
77
78ifdef my_prebuilt_jni_libs
79# Install prebuilt JNI libs to the app specific lib path.
80# Files like @path/to/libfoo.so (path inside the apk) are JNI libs extracted from the prebuilt apk;
81# Files like path/to/libfoo.so (path relative to LOCAL_PATH) are prebuilts in the source tree.
82my_extracted_jni_libs := $(patsubst @%,%, \
83 $(filter @%, $(my_prebuilt_jni_libs)))
84ifdef my_extracted_jni_libs
85ifndef my_prebuilt_src_file
86$(error No prebuilt apk to extract prebuilt jni libraries $(my_extracted_jni_libs))
87endif
88# We use the first jni lib file as dependency.
89my_installed_prebuilt_jni := $(my_app_lib_path)/$(notdir $(firstword $(my_extracted_jni_libs)))
90$(my_installed_prebuilt_jni): PRIVATE_JNI_LIBS := $(my_extracted_jni_libs)
91$(my_installed_prebuilt_jni): $(my_prebuilt_src_file)
92 @echo "Extract JNI libs ($@ <- $<)"
93 @mkdir -p $(dir $@)
94 $(hide) unzip -j -o -d $(dir $@) $< $(PRIVATE_JNI_LIBS) && touch $@
95
96$(LOCAL_INSTALLED_MODULE) : | $(my_installed_prebuilt_jni)
97endif
98
99# prebuilt JNI exsiting as separate source files.
100my_prebuilt_jni_libs := $(addprefix $(LOCAL_PATH)/, \
101 $(filter-out @%, $(my_prebuilt_jni_libs)))
102ifdef my_prebuilt_jni_libs
Ying Wang1f58c412015-02-12 11:29:41 -0800103ifdef my_embed_jni
104# Embed my_prebuilt_jni_libs to the apk
105my_jni_shared_libraries += $(my_prebuilt_jni_libs)
106else # not my_embed_jni
107# Install my_prebuilt_jni_libs as separate files.
Ying Wang8e20ef62014-06-24 20:01:52 -0700108$(foreach lib, $(my_prebuilt_jni_libs), \
109 $(eval $(call copy-one-file, $(lib), $(my_app_lib_path)/$(notdir $(lib)))))
110
111$(LOCAL_INSTALLED_MODULE) : | $(addprefix $(my_app_lib_path)/, $(notdir $(my_prebuilt_jni_libs)))
Ying Wang1f58c412015-02-12 11:29:41 -0800112endif # my_embed_jni
Ying Wang8e20ef62014-06-24 20:01:52 -0700113endif # inner my_prebuilt_jni_libs
114endif # outer my_prebuilt_jni_libs