Ying Wang | 695e826 | 2014-04-17 13:38:04 -0700 | [diff] [blame] | 1 | # 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) |
Ying Wang | 7cf9f28 | 2014-04-18 20:13:41 -0700 | [diff] [blame] | 8 | # my_prebuilt_src_file (from prebuilt_internal.mk) |
Ying Wang | 695e826 | 2014-04-17 13:38:04 -0700 | [diff] [blame] | 9 | # |
| 10 | # Output variables: |
Ying Wang | 7cf9f28 | 2014-04-18 20:13:41 -0700 | [diff] [blame] | 11 | # jni_shared_libraries, 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. |
Ying Wang | 695e826 | 2014-04-17 13:38:04 -0700 | [diff] [blame] | 13 | # |
| 14 | |
| 15 | jni_shared_libraries := \ |
| 16 | $(addprefix $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_OUT_INTERMEDIATE_LIBRARIES)/, \ |
| 17 | $(addsuffix .so, \ |
| 18 | $(LOCAL_JNI_SHARED_LIBRARIES))) |
| 19 | |
| 20 | # Include RS dynamically-generated libraries as well |
| 21 | # Keep this ifneq, as the += otherwise adds spaces that need to be stripped. |
| 22 | ifneq ($(rs_compatibility_jni_libs),) |
| 23 | jni_shared_libraries += $(rs_compatibility_jni_libs) |
| 24 | endif |
| 25 | |
| 26 | my_embed_jni := |
| 27 | ifneq ($(TARGET_BUILD_APPS),) |
| 28 | my_embed_jni := true |
| 29 | endif |
| 30 | ifneq ($(filter tests samples, $(LOCAL_MODULE_TAGS)),) |
| 31 | my_embed_jni := true |
| 32 | endif |
| 33 | ifeq ($(filter $(TARGET_OUT)/% $(TARGET_OUT_VENDOR)/% $(TARGET_OUT_OEM)/%, $(my_module_path)),) |
| 34 | # If this app isn't to be installed to system partitions. |
| 35 | my_embed_jni := true |
| 36 | endif |
| 37 | |
Ying Wang | 7cf9f28 | 2014-04-18 20:13:41 -0700 | [diff] [blame] | 38 | # App-specific lib path. |
Ying Wang | 966c1e0 | 2014-05-20 14:43:51 -0700 | [diff] [blame^] | 39 | my_app_lib_path := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET$(partition_tag)_OUT_SHARED_LIBRARIES)/$(basename $(my_installed_module_stem)) |
Ying Wang | 7cf9f28 | 2014-04-18 20:13:41 -0700 | [diff] [blame] | 40 | my_extracted_jni_libs := |
| 41 | |
Ying Wang | 695e826 | 2014-04-17 13:38:04 -0700 | [diff] [blame] | 42 | ifdef my_embed_jni |
| 43 | # App explicitly requires the prebuilt NDK stl shared libraies. |
| 44 | # The NDK stl shared libraries should never go to the system image. |
| 45 | ifneq ($(filter $(LOCAL_NDK_STL_VARIANT), stlport_shared c++_shared),) |
| 46 | ifndef LOCAL_SDK_VERSION |
| 47 | $(error LOCAL_SDK_VERSION must be defined with LOCAL_NDK_STL_VARIANT, \ |
| 48 | LOCAL_PACKAGE_NAME=$(LOCAL_PACKAGE_NAME)) |
| 49 | endif |
| 50 | endif |
| 51 | ifeq (stlport_shared,$(LOCAL_NDK_STL_VARIANT)) |
| 52 | jni_shared_libraries += \ |
| 53 | $(HISTORICAL_NDK_VERSIONS_ROOT)/current/sources/cxx-stl/stlport/libs/$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)CPU_ABI)/libstlport_shared.so |
| 54 | else ifeq (c++_shared,$(LOCAL_NDK_STL_VARIANT)) |
| 55 | jni_shared_libraries += \ |
| 56 | $(HISTORICAL_NDK_VERSIONS_ROOT)/current/sources/cxx-stl/llvm-libc++/libs/$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)CPU_ABI)/libc++_shared.so |
| 57 | endif |
| 58 | |
| 59 | # Set the abi directory used by the local JNI shared libraries. |
| 60 | # (Doesn't change how the local shared libraries are compiled, just |
| 61 | # sets where they are stored in the apk.) |
| 62 | ifeq ($(LOCAL_JNI_SHARED_LIBRARIES_ABI),) |
| 63 | jni_shared_libraries_abi := $(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)CPU_ABI) |
| 64 | else |
| 65 | jni_shared_libraries_abi := $(LOCAL_JNI_SHARED_LIBRARIES_ABI) |
| 66 | endif |
| 67 | |
| 68 | else # not my_embed_jni |
| 69 | |
| 70 | jni_shared_libraries := $(strip $(jni_shared_libraries)) |
| 71 | ifneq ($(jni_shared_libraries),) |
| 72 | # The jni libaries will be installed to the system.img. |
| 73 | my_jni_filenames := $(notdir $(jni_shared_libraries)) |
| 74 | # Make sure the JNI libraries get installed |
| 75 | $(LOCAL_INSTALLED_MODULE) : | $(addprefix $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET$(partition_tag)_OUT_SHARED_LIBRARIES)/, $(my_jni_filenames)) |
| 76 | |
| 77 | # Create symlink in the app specific lib path |
| 78 | ifdef LOCAL_POST_INSTALL_CMD |
| 79 | my_leading_separator := ; |
| 80 | else |
| 81 | my_leading_separator := |
| 82 | endif |
Ying Wang | 695e826 | 2014-04-17 13:38:04 -0700 | [diff] [blame] | 83 | $(LOCAL_INSTALLED_MODULE): PRIVATE_POST_INSTALL_CMD += \ |
| 84 | $(my_leading_separator)mkdir -p $(my_app_lib_path) \ |
| 85 | $(foreach lib, $(my_jni_filenames), ;ln -sf ../$(lib) $(my_app_lib_path)/$(lib)) |
| 86 | |
| 87 | # Clear jni_shared_libraries to not embed it into the apk. |
| 88 | jni_shared_libraries := |
Ying Wang | 7cf9f28 | 2014-04-18 20:13:41 -0700 | [diff] [blame] | 89 | endif # $(jni_shared_libraries) not empty |
Ying Wang | 695e826 | 2014-04-17 13:38:04 -0700 | [diff] [blame] | 90 | endif # my_embed_jni |
Ying Wang | 7cf9f28 | 2014-04-18 20:13:41 -0700 | [diff] [blame] | 91 | |
| 92 | ifdef LOCAL_PREBUILT_JNI_LIBS |
| 93 | # Install prebuilt JNI libs to the app specific lib path. |
| 94 | # Files like @path/to/libfoo.so (path inside the apk) are JNI libs extracted from the prebuilt apk; |
| 95 | # Files like path/to/libfoo.so (path relative to LOCAL_PATH) are prebuilts in the source tree. |
| 96 | my_extracted_jni_libs := $(patsubst @%,%, \ |
| 97 | $(filter @%, $(LOCAL_PREBUILT_JNI_LIBS))) |
| 98 | ifdef my_extracted_jni_libs |
| 99 | ifndef my_prebuilt_src_file |
| 100 | $(error No prebuilt apk to extract prebuilt jni libraries $(my_extracted_jni_libs)) |
| 101 | endif |
| 102 | # We use the first jni lib file as dependency. |
| 103 | my_installed_prebuilt_jni := $(my_app_lib_path)/$(notdir $(firstword $(my_extracted_jni_libs))) |
| 104 | $(my_installed_prebuilt_jni): PRIVATE_JNI_LIBS := $(my_extracted_jni_libs) |
| 105 | $(my_installed_prebuilt_jni): $(my_prebuilt_src_file) |
| 106 | @echo "Extract JNI libs ($@ <- $<)" |
| 107 | @mkdir -p $(dir $@) |
| 108 | $(hide) unzip -j -o -d $(dir $@) $< $(PRIVATE_JNI_LIBS) && touch $@ |
| 109 | |
| 110 | $(LOCAL_INSTALLED_MODULE) : | $(my_installed_prebuilt_jni) |
| 111 | endif |
| 112 | |
| 113 | my_prebulit_jni_libs := $(addprefix $(LOCAL_PATH)/, \ |
| 114 | $(filter-out @%, $(LOCAL_PREBUILT_JNI_LIBS))) |
| 115 | ifdef my_prebulit_jni_libs |
| 116 | $(foreach lib, $(my_prebulit_jni_libs), \ |
| 117 | $(eval $(call copy-one-file, $(lib), $(my_app_lib_path)/$(notdir $(lib))))) |
| 118 | |
| 119 | $(LOCAL_INSTALLED_MODULE) : | $(addprefix $(my_app_lib_path)/, $(notdir $(my_prebulit_jni_libs))) |
| 120 | endif |
| 121 | endif # LOCAL_PREBULT_JNI_LIBS |