github.com/westcoastroms/westcoastroms-build@v0.0.0-20190928114312-2350e5a73030/build/make/core/install_jni_libs_internal.mk (about)

     1  # 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_embedded_prebuilt_jni_libs, prebuilt jni libs embedded in prebuilt apk.
    13  #
    14  
    15  my_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.
    21  my_app_lib_path := $(dir $(LOCAL_INSTALLED_MODULE))lib/$(TARGET_$(my_2nd_arch_prefix)ARCH)
    22  my_embedded_prebuilt_jni_libs :=
    23  
    24  ifdef 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.
    27  ifeq ($(LOCAL_NDK_STL_VARIANT),c++_shared)
    28  ifndef LOCAL_SDK_VERSION
    29  $(error LOCAL_SDK_VERSION must be defined with LOCAL_NDK_STL_VARIANT, \
    30      LOCAL_PACKAGE_NAME=$(LOCAL_PACKAGE_NAME))
    31  endif
    32  my_jni_shared_libraries += \
    33      $(HISTORICAL_NDK_VERSIONS_ROOT)/$(LOCAL_NDK_VERSION)/sources/cxx-stl/llvm-libc++/libs/$(TARGET_$(my_2nd_arch_prefix)CPU_ABI)/libc++_shared.so
    34  endif
    35  
    36  # Set the abi directory used by the local JNI shared libraries.
    37  # (Doesn't change how the local shared libraries are compiled, just
    38  # sets where they are stored in the apk.)
    39  ifeq ($(LOCAL_JNI_SHARED_LIBRARIES_ABI),)
    40      my_jni_shared_libraries_abi := $(TARGET_$(my_2nd_arch_prefix)CPU_ABI)
    41  else
    42      my_jni_shared_libraries_abi := $(LOCAL_JNI_SHARED_LIBRARIES_ABI)
    43  endif
    44  
    45  else  # not my_embed_jni
    46  
    47  my_jni_shared_libraries := $(strip $(my_jni_shared_libraries))
    48  ifneq ($(my_jni_shared_libraries),)
    49  # The jni libaries will be installed to the system.img.
    50  my_jni_filenames := $(notdir $(my_jni_shared_libraries))
    51  # Make sure the JNI libraries get installed
    52  my_shared_library_path := $(call get_non_asan_path,\
    53    $($(my_2nd_arch_prefix)TARGET_OUT$(partition_tag)_SHARED_LIBRARIES))
    54  # Do not use order-only dependency, because we want to rebuild the image if an jni is updated.
    55  $(LOCAL_INSTALLED_MODULE) : $(addprefix $(my_shared_library_path)/, $(my_jni_filenames))
    56  
    57  # Create symlink in the app specific lib path
    58  # Skip creating this symlink when running the second part of a target sanitization build.
    59  ifndef SANITIZE_TARGET
    60  ifdef LOCAL_POST_INSTALL_CMD
    61  # Add a shell command separator
    62  LOCAL_POST_INSTALL_CMD += ;
    63  endif
    64  
    65  my_symlink_target_dir := $(patsubst $(PRODUCT_OUT)%,%,\
    66      $(my_shared_library_path))
    67  LOCAL_POST_INSTALL_CMD += \
    68    mkdir -p $(my_app_lib_path) \
    69    $(foreach lib, $(my_jni_filenames), ;ln -sf $(my_symlink_target_dir)/$(lib) $(my_app_lib_path)/$(lib))
    70  $(LOCAL_INSTALLED_MODULE): PRIVATE_POST_INSTALL_CMD := $(LOCAL_POST_INSTALL_CMD)
    71  else
    72  ifdef LOCAL_POST_INSTALL_CMD
    73  $(LOCAL_INSTALLED_MODULE): PRIVATE_POST_INSTALL_CMD := $(LOCAL_POST_INSTALL_CMD)
    74  endif
    75  endif
    76  
    77  # Clear jni_shared_libraries to not embed it into the apk.
    78  my_jni_shared_libraries :=
    79  endif  # $(my_jni_shared_libraries) not empty
    80  endif  # my_embed_jni
    81  
    82  ifdef my_prebuilt_jni_libs
    83  # Files like @lib/<abi>/libfoo.so (path inside the apk) are JNI libs embedded prebuilt apk;
    84  # Files like path/to/libfoo.so (path relative to LOCAL_PATH) are prebuilts in the source tree.
    85  my_embedded_prebuilt_jni_libs := $(patsubst @%,%, \
    86      $(filter @%, $(my_prebuilt_jni_libs)))
    87  
    88  # prebuilt JNI exsiting as separate source files.
    89  my_prebuilt_jni_libs := $(addprefix $(LOCAL_PATH)/, \
    90      $(filter-out @%, $(my_prebuilt_jni_libs)))
    91  ifdef my_prebuilt_jni_libs
    92  ifdef my_embed_jni
    93  # Embed my_prebuilt_jni_libs to the apk
    94  my_jni_shared_libraries += $(my_prebuilt_jni_libs)
    95  else # not my_embed_jni
    96  # Install my_prebuilt_jni_libs as separate files.
    97  $(foreach lib, $(my_prebuilt_jni_libs), \
    98      $(eval $(call copy-one-file, $(lib), $(my_app_lib_path)/$(notdir $(lib)))))
    99  
   100  $(LOCAL_INSTALLED_MODULE) : $(addprefix $(my_app_lib_path)/, $(notdir $(my_prebuilt_jni_libs)))
   101  endif  # my_embed_jni
   102  endif  # inner my_prebuilt_jni_libs
   103  endif  # outer my_prebuilt_jni_libs
   104  
   105  # Verify that all included libraries are built against the NDK
   106  include $(BUILD_SYSTEM)/allowed_ndk_types.mk
   107  ifneq ($(strip $(LOCAL_JNI_SHARED_LIBRARIES)),)
   108  ifneq ($(LOCAL_SDK_VERSION),)
   109  my_link_type := app:sdk
   110  my_warn_types := native:platform $(my_warn_ndk_types)
   111  my_allowed_types := $(my_allowed_ndk_types)
   112      ifneq (,$(filter true,$(LOCAL_VENDOR_MODULE) $(LOCAL_ODM_MODULE) $(LOCAL_PROPRIETARY_MODULE)))
   113          my_allowed_types += native:vendor native:vndk
   114      endif
   115  else
   116  my_link_type := app:platform
   117  my_warn_types := $(my_warn_ndk_types)
   118  my_allowed_types := $(my_allowed_ndk_types) native:platform native:vendor native:vndk native:vndk_private
   119  endif
   120  
   121  my_link_deps := $(addprefix SHARED_LIBRARIES:,$(LOCAL_JNI_SHARED_LIBRARIES))
   122  
   123  my_common :=
   124  include $(BUILD_SYSTEM)/link_type.mk
   125  endif