summaryrefslogtreecommitdiffstats
path: root/core/install_jni_libs_internal.mk
diff options
context:
space:
mode:
authorYing Wang <wangying@google.com>2014-06-24 20:01:52 -0700
committerYing Wang <wangying@google.com>2014-06-25 09:07:01 -0700
commit8e20ef6205b3c96135b1c1e4484d523dbecb1b98 (patch)
tree506b1e36c6460dba960e092d3414d3a65b4f17f9 /core/install_jni_libs_internal.mk
parentb0c6ea9f290261c12b6cb127b7bcd53f8ecc2d60 (diff)
downloadbuild-8e20ef6205b3c96135b1c1e4484d523dbecb1b98.zip
build-8e20ef6205b3c96135b1c1e4484d523dbecb1b98.tar.gz
build-8e20ef6205b3c96135b1c1e4484d523dbecb1b98.tar.bz2
Support to add JNI of both archs in multilib build.
Use "LOCAL_MULTILIB := both" to install jni libraries of both archs in multilib build. The build system will package jni of both archs to the apk, or install them to the right location on the system image and create symlinks, extract .so files from prebuilt apk, etc if appropriate. Bug: 15849902 Change-Id: I7e147b5a47db476584c38250de7b36c75ea40d81
Diffstat (limited to 'core/install_jni_libs_internal.mk')
-rw-r--r--core/install_jni_libs_internal.mk104
1 files changed, 104 insertions, 0 deletions
diff --git a/core/install_jni_libs_internal.mk b/core/install_jni_libs_internal.mk
new file mode 100644
index 0000000..b50c21e
--- /dev/null
+++ b/core/install_jni_libs_internal.mk
@@ -0,0 +1,104 @@
+# Install jni libraries for one arch.
+# Input variables:
+# my_2nd_arch_prefix: indicate if this is for TARGET_2ND_ARCH.
+# my_embed_jni: indicate if we want to embed the jni libs in the apk.
+# my_prebuilt_jni_libs
+# my_installed_module_stem (from configure_module_stem.mk)
+# partition_tag (from base_rules.mk)
+# my_prebuilt_src_file (from prebuilt_internal.mk)
+#
+# Output variables:
+# my_jni_shared_libraries, my_jni_shared_libraries_abi, if we are going to embed the libraries into the apk;
+# my_extracted_jni_libs, if we extract jni libs from prebuilt apk.
+#
+
+my_jni_shared_libraries := \
+ $(addprefix $($(my_2nd_arch_prefix)TARGET_OUT_INTERMEDIATE_LIBRARIES)/, \
+ $(addsuffix .so, \
+ $(LOCAL_JNI_SHARED_LIBRARIES)))
+
+# App-specific lib path.
+my_app_lib_path := $($(my_2nd_arch_prefix)TARGET$(partition_tag)_OUT_SHARED_LIBRARIES)/$(basename $(my_installed_module_stem))
+my_extracted_jni_libs :=
+
+ifdef my_embed_jni
+# App explicitly requires the prebuilt NDK stl shared libraies.
+# The NDK stl shared libraries should never go to the system image.
+ifneq ($(filter $(LOCAL_NDK_STL_VARIANT), stlport_shared c++_shared),)
+ifndef LOCAL_SDK_VERSION
+$(error LOCAL_SDK_VERSION must be defined with LOCAL_NDK_STL_VARIANT, \
+ LOCAL_PACKAGE_NAME=$(LOCAL_PACKAGE_NAME))
+endif
+endif
+ifeq (stlport_shared,$(LOCAL_NDK_STL_VARIANT))
+my_jni_shared_libraries += \
+ $(HISTORICAL_NDK_VERSIONS_ROOT)/current/sources/cxx-stl/stlport/libs/$(TARGET_$(my_2nd_arch_prefix)CPU_ABI)/libstlport_shared.so
+else ifeq (c++_shared,$(LOCAL_NDK_STL_VARIANT))
+my_jni_shared_libraries += \
+ $(HISTORICAL_NDK_VERSIONS_ROOT)/current/sources/cxx-stl/llvm-libc++/libs/$(TARGET_$(my_2nd_arch_prefix)CPU_ABI)/libc++_shared.so
+endif
+
+# Set the abi directory used by the local JNI shared libraries.
+# (Doesn't change how the local shared libraries are compiled, just
+# sets where they are stored in the apk.)
+ifeq ($(LOCAL_JNI_SHARED_LIBRARIES_ABI),)
+ my_jni_shared_libraries_abi := $(TARGET_$(my_2nd_arch_prefix)CPU_ABI)
+else
+ my_jni_shared_libraries_abi := $(LOCAL_JNI_SHARED_LIBRARIES_ABI)
+endif
+
+else # not my_embed_jni
+
+my_jni_shared_libraries := $(strip $(my_jni_shared_libraries))
+ifneq ($(my_jni_shared_libraries),)
+# The jni libaries will be installed to the system.img.
+my_jni_filenames := $(notdir $(my_jni_shared_libraries))
+# Make sure the JNI libraries get installed
+$(LOCAL_INSTALLED_MODULE) : | $(addprefix $($(my_2nd_arch_prefix)TARGET$(partition_tag)_OUT_SHARED_LIBRARIES)/, $(my_jni_filenames))
+
+# Create symlink in the app specific lib path
+ifdef LOCAL_POST_INSTALL_CMD
+# Add a shell command separator
+LOCAL_POST_INSTALL_CMD += ;
+endif
+LOCAL_POST_INSTALL_CMD += \
+ mkdir -p $(my_app_lib_path) \
+ $(foreach lib, $(my_jni_filenames), ;ln -sf ../$(lib) $(my_app_lib_path)/$(lib))
+$(LOCAL_INSTALLED_MODULE): PRIVATE_POST_INSTALL_CMD := $(LOCAL_POST_INSTALL_CMD)
+
+# Clear jni_shared_libraries to not embed it into the apk.
+my_jni_shared_libraries :=
+endif # $(my_jni_shared_libraries) not empty
+endif # my_embed_jni
+
+ifdef my_prebuilt_jni_libs
+# Install prebuilt JNI libs to the app specific lib path.
+# Files like @path/to/libfoo.so (path inside the apk) are JNI libs extracted from the prebuilt apk;
+# Files like path/to/libfoo.so (path relative to LOCAL_PATH) are prebuilts in the source tree.
+my_extracted_jni_libs := $(patsubst @%,%, \
+ $(filter @%, $(my_prebuilt_jni_libs)))
+ifdef my_extracted_jni_libs
+ifndef my_prebuilt_src_file
+$(error No prebuilt apk to extract prebuilt jni libraries $(my_extracted_jni_libs))
+endif
+# We use the first jni lib file as dependency.
+my_installed_prebuilt_jni := $(my_app_lib_path)/$(notdir $(firstword $(my_extracted_jni_libs)))
+$(my_installed_prebuilt_jni): PRIVATE_JNI_LIBS := $(my_extracted_jni_libs)
+$(my_installed_prebuilt_jni): $(my_prebuilt_src_file)
+ @echo "Extract JNI libs ($@ <- $<)"
+ @mkdir -p $(dir $@)
+ $(hide) unzip -j -o -d $(dir $@) $< $(PRIVATE_JNI_LIBS) && touch $@
+
+$(LOCAL_INSTALLED_MODULE) : | $(my_installed_prebuilt_jni)
+endif
+
+# prebuilt JNI exsiting as separate source files.
+my_prebuilt_jni_libs := $(addprefix $(LOCAL_PATH)/, \
+ $(filter-out @%, $(my_prebuilt_jni_libs)))
+ifdef my_prebuilt_jni_libs
+$(foreach lib, $(my_prebuilt_jni_libs), \
+ $(eval $(call copy-one-file, $(lib), $(my_app_lib_path)/$(notdir $(lib)))))
+
+$(LOCAL_INSTALLED_MODULE) : | $(addprefix $(my_app_lib_path)/, $(notdir $(my_prebuilt_jni_libs)))
+endif # inner my_prebuilt_jni_libs
+endif # outer my_prebuilt_jni_libs