Dan Albert | 975e303 | 2017-12-19 11:26:05 -0800 | [diff] [blame] | 1 | # 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 Albert | 4297c39 | 2017-12-19 11:27:39 -0800 | [diff] [blame] | 9 | # my_ndk_stl_link_type: STL link type, static or shared. |
Dan Albert | 975e303 | 2017-12-19 11:26:05 -0800 | [diff] [blame] | 10 | # 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 | |
| 13 | my_allowed_ndk_types := |
| 14 | my_warn_ndk_types := |
| 15 | my_ndk_stl_family := |
Dan Albert | 4297c39 | 2017-12-19 11:27:39 -0800 | [diff] [blame] | 16 | my_ndk_stl_link_type := |
Dan Albert | 975e303 | 2017-12-19 11:26:05 -0800 | [diff] [blame] | 17 | |
| 18 | ifdef LOCAL_SDK_VERSION |
| 19 | ifeq ($(LOCAL_NDK_STL_VARIANT),) |
| 20 | my_ndk_stl_family := system |
Dan Albert | 4297c39 | 2017-12-19 11:27:39 -0800 | [diff] [blame] | 21 | my_ndk_stl_link_type := shared |
Dan Albert | 975e303 | 2017-12-19 11:26:05 -0800 | [diff] [blame] | 22 | else ifeq ($(LOCAL_NDK_STL_VARIANT),system) |
| 23 | my_ndk_stl_family := system |
Dan Albert | 4297c39 | 2017-12-19 11:27:39 -0800 | [diff] [blame] | 24 | my_ndk_stl_link_type := shared |
Dan Albert | 975e303 | 2017-12-19 11:26:05 -0800 | [diff] [blame] | 25 | else ifeq ($(LOCAL_NDK_STL_VARIANT),c++_shared) |
| 26 | my_ndk_stl_family := libc++ |
Dan Albert | 4297c39 | 2017-12-19 11:27:39 -0800 | [diff] [blame] | 27 | my_ndk_stl_link_type := shared |
Dan Albert | 975e303 | 2017-12-19 11:26:05 -0800 | [diff] [blame] | 28 | else ifeq ($(LOCAL_NDK_STL_VARIANT),c++_static) |
| 29 | my_ndk_stl_family := libc++ |
Dan Albert | 4297c39 | 2017-12-19 11:27:39 -0800 | [diff] [blame] | 30 | my_ndk_stl_link_type := static |
Dan Albert | 975e303 | 2017-12-19 11:26:05 -0800 | [diff] [blame] | 31 | else ifeq ($(LOCAL_NDK_STL_VARIANT),none) |
| 32 | my_ndk_stl_family := none |
Dan Albert | 4297c39 | 2017-12-19 11:27:39 -0800 | [diff] [blame] | 33 | my_ndk_stl_link_type := none |
Dan Albert | 975e303 | 2017-12-19 11:26:05 -0800 | [diff] [blame] | 34 | else |
| 35 | $(call pretty-error,invalid LOCAL_NDK_STL_VARIANT: $(LOCAL_NDK_STL_VARIANT)) |
| 36 | endif |
| 37 | |
Dan Albert | 4297c39 | 2017-12-19 11:27:39 -0800 | [diff] [blame] | 38 | 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 Albert | 975e303 | 2017-12-19 11:26:05 -0800 | [diff] [blame] | 45 | # The system STL is only the C++ ABI layer, so it's compatible with any STL. |
Dan Albert | 4297c39 | 2017-12-19 11:27:39 -0800 | [diff] [blame] | 46 | my_allowed_ndk_types += native:ndk:system:shared |
| 47 | my_allowed_ndk_types += native:ndk:system:none |
Dan Albert | 975e303 | 2017-12-19 11:26:05 -0800 | [diff] [blame] | 48 | |
| 49 | # Libaries that don't use the STL can be linked to anything. |
Dan Albert | 4297c39 | 2017-12-19 11:27:39 -0800 | [diff] [blame] | 50 | my_allowed_ndk_types += native:ndk:none:none |
Dan Albert | 975e303 | 2017-12-19 11:26:05 -0800 | [diff] [blame] | 51 | |
Dan Albert | 4297c39 | 2017-12-19 11:27:39 -0800 | [diff] [blame] | 52 | # 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 Albert | 975e303 | 2017-12-19 11:26:05 -0800 | [diff] [blame] | 56 | |
| 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 Albert | 19fbd1c | 2018-01-04 13:34:21 -0800 | [diff] [blame] | 63 | native:ndk:libc++:shared native:ndk:libc++:static |
Dan Albert | 4297c39 | 2017-12-19 11:27:39 -0800 | [diff] [blame] | 64 | |
| 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 Albert | 975e303 | 2017-12-19 11:26:05 -0800 | [diff] [blame] | 71 | endif |
Dan Albert | 4297c39 | 2017-12-19 11:27:39 -0800 | [diff] [blame] | 72 | # 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 Albert | 975e303 | 2017-12-19 11:26:05 -0800 | [diff] [blame] | 74 | else |
Dan Albert | 1759e2d | 2018-01-08 12:42:20 -0800 | [diff] [blame] | 75 | my_allowed_ndk_types := \ |
| 76 | native:ndk:none:none \ |
| 77 | native:ndk:system:none \ |
| 78 | native:ndk:system:shared \ |
| 79 | |
Dan Albert | 975e303 | 2017-12-19 11:26:05 -0800 | [diff] [blame] | 80 | ifeq ($(LOCAL_MODULE_CLASS),APPS) |
| 81 | # CTS is bad and it should feel bad: http://b/13249737 |
Dan Albert | 4297c39 | 2017-12-19 11:27:39 -0800 | [diff] [blame] | 82 | my_warn_ndk_types += native:ndk:libc++:static |
Dan Albert | 975e303 | 2017-12-19 11:26:05 -0800 | [diff] [blame] | 83 | endif |
| 84 | endif |