2014-06-25 03:01:52 +00:00
# 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;
2015-05-01 21:02:26 +00:00
# my_embedded_prebuilt_jni_libs, prebuilt jni libs embedded in prebuilt apk.
2014-06-25 03:01:52 +00:00
#
my_jni_shared_libraries := \
$( addprefix $( $( my_2nd_arch_prefix) TARGET_OUT_INTERMEDIATE_LIBRARIES) /, \
$( addsuffix .so, \
$( LOCAL_JNI_SHARED_LIBRARIES) ) )
# App-specific lib path.
2014-07-18 04:24:42 +00:00
my_app_lib_path := $( dir $( LOCAL_INSTALLED_MODULE) ) lib/$( TARGET_$( my_2nd_arch_prefix) ARCH)
2015-05-01 21:02:26 +00:00
my_embedded_prebuilt_jni_libs :=
2014-06-25 03:01:52 +00:00
i f d e f m y _ e m b e d _ j n i
# App explicitly requires the prebuilt NDK stl shared libraies.
# The NDK stl shared libraries should never go to the system image.
i f n e q ( $( filter $ ( LOCAL_NDK_STL_VARIANT ) , stlport_shared c ++_shared ) , )
i f n d e f L O C A L _ S D K _ V E R S I O N
$( error LOCAL_SDK_VERSION must be defined with LOCAL_NDK_STL_VARIANT , \
LOCAL_PACKAGE_NAME = $( LOCAL_PACKAGE_NAME) )
e n d i f
e n d i f
i f e q ( s t l p o r t _ s h a r e d , $( LOCAL_NDK_STL_VARIANT ) )
my_jni_shared_libraries += \
2016-08-09 00:13:31 +00:00
$( HISTORICAL_NDK_VERSIONS_ROOT) /$( LOCAL_NDK_VERSION) /sources/cxx-stl/stlport/libs/$( TARGET_$( my_2nd_arch_prefix) CPU_ABI) /libstlport_shared.so
2014-06-25 03:01:52 +00:00
e l s e i f e q ( c + + _ s h a r e d , $( LOCAL_NDK_STL_VARIANT ) )
my_jni_shared_libraries += \
2016-08-09 00:13:31 +00:00
$( HISTORICAL_NDK_VERSIONS_ROOT) /$( LOCAL_NDK_VERSION) /sources/cxx-stl/llvm-libc++/libs/$( TARGET_$( my_2nd_arch_prefix) CPU_ABI) /libc++_shared.so
2014-06-25 03:01:52 +00:00
e n d i f
# 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.)
i f e q ( $( LOCAL_JNI_SHARED_LIBRARIES_ABI ) , )
my_jni_shared_libraries_abi := $( TARGET_$( my_2nd_arch_prefix) CPU_ABI)
e l s e
my_jni_shared_libraries_abi := $( LOCAL_JNI_SHARED_LIBRARIES_ABI)
e n d i f
e l s e # not my_embed_jni
my_jni_shared_libraries := $( strip $( my_jni_shared_libraries) )
i f n e q ( $( 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
2014-07-18 04:24:42 +00:00
my_shared_library_path := $( $( my_2nd_arch_prefix) TARGET_OUT$( partition_tag) _SHARED_LIBRARIES)
2015-10-15 22:29:01 +00:00
# Do not use order-only dependency, because we want to rebuild the image if an jni is updated.
$(LOCAL_INSTALLED_MODULE) : $( addprefix $ ( my_shared_library_path ) /, $ ( my_jni_filenames ) )
2014-06-25 03:01:52 +00:00
# Create symlink in the app specific lib path
i f d e f L O C A L _ P O S T _ I N S T A L L _ C M D
# Add a shell command separator
LOCAL_POST_INSTALL_CMD += ;
e n d i f
2014-07-18 04:24:42 +00:00
my_symlink_target_dir := $( patsubst $( PRODUCT_OUT) %,%,\
$( my_shared_library_path) )
2014-06-25 03:01:52 +00:00
LOCAL_POST_INSTALL_CMD += \
mkdir -p $( my_app_lib_path) \
2014-07-18 04:24:42 +00:00
$( foreach lib, $( my_jni_filenames) , ; ln -sf $( my_symlink_target_dir) /$( lib) $( my_app_lib_path) /$( lib) )
2014-06-25 03:01:52 +00:00
$(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 :=
e n d i f # $(my_jni_shared_libraries) not empty
e n d i f # my_embed_jni
i f d e f m y _ p r e b u i l t _ j n i _ l i b s
2015-05-01 21:02:26 +00:00
# Files like @lib/<abi>/libfoo.so (path inside the apk) are JNI libs embedded prebuilt apk;
2014-06-25 03:01:52 +00:00
# Files like path/to/libfoo.so (path relative to LOCAL_PATH) are prebuilts in the source tree.
2015-05-01 21:02:26 +00:00
my_embedded_prebuilt_jni_libs := $( patsubst @%,%, \
2014-06-25 03:01:52 +00:00
$( filter @%, $( my_prebuilt_jni_libs) ) )
# prebuilt JNI exsiting as separate source files.
my_prebuilt_jni_libs := $( addprefix $( LOCAL_PATH) /, \
$( filter-out @%, $( my_prebuilt_jni_libs) ) )
i f d e f m y _ p r e b u i l t _ j n i _ l i b s
2015-02-12 19:29:41 +00:00
i f d e f m y _ e m b e d _ j n i
# Embed my_prebuilt_jni_libs to the apk
my_jni_shared_libraries += $( my_prebuilt_jni_libs)
e l s e # not my_embed_jni
# Install my_prebuilt_jni_libs as separate files.
2014-06-25 03:01:52 +00:00
$( foreach lib , $ ( my_prebuilt_jni_libs ) , \
$( eval $( call copy-one-file, $( lib) , $( my_app_lib_path) /$( notdir $( lib) ) ) ) )
2015-10-15 22:29:01 +00:00
$(LOCAL_INSTALLED_MODULE) : $( addprefix $ ( my_app_lib_path ) /, $ ( notdir $ ( my_prebuilt_jni_libs ) ) )
2015-02-12 19:29:41 +00:00
e n d i f # my_embed_jni
2014-06-25 03:01:52 +00:00
e n d i f # inner my_prebuilt_jni_libs
e n d i f # outer my_prebuilt_jni_libs
2016-06-07 21:25:14 +00:00
# Verify that all included libraries are built against the NDK
i f n e q ( $( strip $ ( LOCAL_JNI_SHARED_LIBRARIES ) ) , )
my_link_type := $( call intermediates-dir-for,APPS,$( LOCAL_MODULE) ) /$( my_2nd_arch_prefix) jni_link_type
my_link_type_deps := $( strip \
$( foreach l,$( LOCAL_JNI_SHARED_LIBRARIES) ,\
$( call intermediates-dir-for,SHARED_LIBRARIES,$( l) ,,,$( my_2nd_arch_prefix) ) /link_type) )
i f n e q ( $( LOCAL_SDK_VERSION ) , )
$(my_link_type) : PRIVATE_LINK_TYPE := sdk
$(my_link_type) : PRIVATE_ALLOWED_TYPES := ndk
e l s e
$(my_link_type) : PRIVATE_LINK_TYPE := platform
$(my_link_type) : PRIVATE_ALLOWED_TYPES := (ndk | platform )
e n d i f
$(my_link_type) : PRIVATE_DEPS := $( my_link_type_deps )
$(my_link_type) : PRIVATE_MODULE := $( LOCAL_MODULE )
$(my_link_type) : PRIVATE_MAKEFILE := $( LOCAL_MODULE_MAKEFILE )
$(my_link_type) : $( my_link_type_deps )
@echo Check JNI module types: $@
$( hide) mkdir -p $( dir $@ )
$( hide) rm -f $@
$( hide) for f in $( PRIVATE_DEPS) ; do \
grep -qE '^$(PRIVATE_ALLOWED_TYPES)$$' $$ f || \
$( call echo-warning," $( PRIVATE_MAKEFILE) : $( PRIVATE_MODULE) ( $( PRIVATE_LINK_TYPE) ) should not link to $$ (basename $$ {f%_intermediates/link_type}) ( $$ (cat $$ f)) " ) ; \
done
$( hide) touch $@
$(LOCAL_BUILT_MODULE) : | $( my_link_type )
my_link_type :=
my_link_type_deps :=
e n d i f