blob: b88b9e8c879d402ebd6f5346ba6b3b3595db769b [file] [log] [blame]
Dan Albert975e3032017-12-19 11:26:05 -08001# Determines the types of NDK modules the current module is allowed to link to.
2# Input variables:
3# LOCAL_MODULE
4# LOCAL_MODULE_CLASS
5# LOCAL_NDK_STL_VARIANT
6# LOCAL_SDK_VERSION
7# Output variables:
8# my_ndk_stl_family: Family of the NDK STL.
Dan Albert4297c392017-12-19 11:27:39 -08009# my_ndk_stl_link_type: STL link type, static or shared.
Dan Albert975e3032017-12-19 11:26:05 -080010# my_allowed_ndk_types: Types of NDK modules that may be linked.
11# my_warn_ndk_types: Types of NDK modules that shouldn't be linked, but are.
12
13my_allowed_ndk_types :=
14my_warn_ndk_types :=
15my_ndk_stl_family :=
Dan Albert4297c392017-12-19 11:27:39 -080016my_ndk_stl_link_type :=
Dan Albert975e3032017-12-19 11:26:05 -080017
18ifdef LOCAL_SDK_VERSION
19 ifeq ($(LOCAL_NDK_STL_VARIANT),)
20 my_ndk_stl_family := system
Dan Albert4297c392017-12-19 11:27:39 -080021 my_ndk_stl_link_type := shared
Dan Albert975e3032017-12-19 11:26:05 -080022 else ifeq ($(LOCAL_NDK_STL_VARIANT),system)
23 my_ndk_stl_family := system
Dan Albert4297c392017-12-19 11:27:39 -080024 my_ndk_stl_link_type := shared
Dan Albert975e3032017-12-19 11:26:05 -080025 else ifeq ($(LOCAL_NDK_STL_VARIANT),c++_shared)
26 my_ndk_stl_family := libc++
Dan Albert4297c392017-12-19 11:27:39 -080027 my_ndk_stl_link_type := shared
Dan Albert975e3032017-12-19 11:26:05 -080028 else ifeq ($(LOCAL_NDK_STL_VARIANT),c++_static)
29 my_ndk_stl_family := libc++
Dan Albert4297c392017-12-19 11:27:39 -080030 my_ndk_stl_link_type := static
Dan Albert975e3032017-12-19 11:26:05 -080031 else ifeq ($(LOCAL_NDK_STL_VARIANT),none)
32 my_ndk_stl_family := none
Dan Albert4297c392017-12-19 11:27:39 -080033 my_ndk_stl_link_type := none
Dan Albert975e3032017-12-19 11:26:05 -080034 else
35 $(call pretty-error,invalid LOCAL_NDK_STL_VARIANT: $(LOCAL_NDK_STL_VARIANT))
36 endif
37
Dan Albert4297c392017-12-19 11:27:39 -080038 ifeq ($(LOCAL_MODULE_CLASS),STATIC_LIBRARIES)
39 # The "none" link type indicates that nothing is actually linked. Since
40 # this is a static library, it's still up to the final use of the
41 # library whether a static or shared STL should be used.
42 my_ndk_stl_link_type := none
43 endif
44
Dan Albert975e3032017-12-19 11:26:05 -080045 # The system STL is only the C++ ABI layer, so it's compatible with any STL.
Dan Albert4297c392017-12-19 11:27:39 -080046 my_allowed_ndk_types += native:ndk:system:shared
47 my_allowed_ndk_types += native:ndk:system:none
Dan Albert975e3032017-12-19 11:26:05 -080048
49 # Libaries that don't use the STL can be linked to anything.
Dan Albert4297c392017-12-19 11:27:39 -080050 my_allowed_ndk_types += native:ndk:none:none
Dan Albert975e3032017-12-19 11:26:05 -080051
Dan Albert4297c392017-12-19 11:27:39 -080052 # And it's always okay to link a static library that uses your own STL type.
53 # Since nothing was actually linked for the static library, it is up to the
54 # first linked library in the dependency chain which gets used.
55 my_allowed_ndk_types += native:ndk:$(my_ndk_stl_family):none
Dan Albert975e3032017-12-19 11:26:05 -080056
57 ifeq ($(LOCAL_MODULE_CLASS),APPS)
58 # For an app package, it's actually okay to depend on any set of STLs.
59 # If any of the individual libraries depend on each other they've
60 # already been checked for consistency, and if they don't they'll be
61 # kept isolated by RTLD_LOCAL anyway.
62 my_allowed_ndk_types += \
Dan Albert19fbd1c2018-01-04 13:34:21 -080063 native:ndk:libc++:shared native:ndk:libc++:static
Dan Albert4297c392017-12-19 11:27:39 -080064
65 # The "none" link type that used by static libraries is intentionally
66 # omitted here. We should only be dealing with shared libraries in
67 # LOCAL_JNI_SHARED_LIBRARIES.
68 else ifeq ($(my_ndk_stl_link_type),shared)
69 # Modules linked to a shared STL can only use another shared STL.
70 my_allowed_ndk_types += native:ndk:$(my_ndk_stl_family):shared
Dan Albert975e3032017-12-19 11:26:05 -080071 endif
Dan Albert4297c392017-12-19 11:27:39 -080072 # Else we are a non-static library that uses a static STL, and are
73 # incompatible with all other shared libraries that use an STL.
Dan Albert975e3032017-12-19 11:26:05 -080074else
Dan Albert1759e2d2018-01-08 12:42:20 -080075 my_allowed_ndk_types := \
76 native:ndk:none:none \
77 native:ndk:system:none \
78 native:ndk:system:shared \
79
Dan Albert975e3032017-12-19 11:26:05 -080080 ifeq ($(LOCAL_MODULE_CLASS),APPS)
81 # CTS is bad and it should feel bad: http://b/13249737
Dan Albert4297c392017-12-19 11:27:39 -080082 my_warn_ndk_types += native:ndk:libc++:static
Dan Albert975e3032017-12-19 11:26:05 -080083 endif
84endif