1 # This file is dual licensed under the MIT and the University of Illinois Open 2 # Source Licenses. See LICENSE.TXT for details. 3 4 LOCAL_PATH := $(call my-dir) 5 6 # Normally, we distribute the NDK with prebuilt binaries of libc++ 7 # in $LOCAL_PATH/libs/<abi>/. However, 8 # 9 10 LIBCXX_FORCE_REBUILD := $(strip $(LIBCXX_FORCE_REBUILD)) 11 ifndef LIBCXX_FORCE_REBUILD 12 ifeq (,$(strip $(wildcard $(LOCAL_PATH)/libs/$(TARGET_ARCH_ABI)/libc++_static$(TARGET_LIB_EXTENSION)))) 13 $(call __ndk_info,WARNING: Rebuilding libc++ libraries from sources!) 14 $(call __ndk_info,You might want to use $$NDK/build/tools/build-cxx-stl.sh --stl=libc++) 15 $(call __ndk_info,in order to build prebuilt versions to speed up your builds!) 16 LIBCXX_FORCE_REBUILD := true 17 endif 18 endif 19 20 libcxx_includes := $(LOCAL_PATH)/include 21 libcxx_export_includes := $(libcxx_includes) 22 libcxx_sources := \ 23 algorithm.cpp \ 24 any.cpp \ 25 bind.cpp \ 26 chrono.cpp \ 27 condition_variable.cpp \ 28 debug.cpp \ 29 exception.cpp \ 30 functional.cpp \ 31 future.cpp \ 32 hash.cpp \ 33 ios.cpp \ 34 iostream.cpp \ 35 locale.cpp \ 36 memory.cpp \ 37 mutex.cpp \ 38 new.cpp \ 39 optional.cpp \ 40 random.cpp \ 41 regex.cpp \ 42 shared_mutex.cpp \ 43 stdexcept.cpp \ 44 string.cpp \ 45 strstream.cpp \ 46 system_error.cpp \ 47 thread.cpp \ 48 typeinfo.cpp \ 49 utility.cpp \ 50 valarray.cpp \ 51 variant.cpp \ 52 vector.cpp \ 53 54 libcxx_sources := $(libcxx_sources:%=src/%) 55 56 libcxx_export_cxxflags := 57 58 ifeq (,$(filter clang%,$(NDK_TOOLCHAIN_VERSION))) 59 # Add -fno-strict-aliasing because __list_imp::_end_ breaks TBAA rules by declaring 60 # simply as __list_node_base then casted to __list_node derived from that. See 61 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61571 for details 62 libcxx_export_cxxflags += -fno-strict-aliasing 63 endif 64 65 libcxx_cxxflags := \ 66 -std=c++1z \ 67 -DLIBCXX_BUILDING_LIBCXXABI \ 68 -D_LIBCPP_BUILDING_LIBRARY \ 69 -D_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS \ 70 -D__STDC_FORMAT_MACROS \ 71 $(libcxx_export_cxxflags) \ 72 73 libcxx_ldflags := 74 libcxx_export_ldflags := 75 # Need to make sure the unwinder is always linked with hidden visibility. 76 ifneq (,$(filter armeabi%,$(TARGET_ARCH_ABI))) 77 libcxx_ldflags += -Wl,--exclude-libs,libunwind.a 78 libcxx_export_ldflags += -Wl,--exclude-libs,libunwind.a 79 endif 80 81 ifneq ($(LIBCXX_FORCE_REBUILD),true) 82 83 $(call ndk_log,Using prebuilt libc++ libraries) 84 85 libcxxabi_c_includes := $(LOCAL_PATH)/../llvm-libc++abi/include 86 87 include $(CLEAR_VARS) 88 LOCAL_MODULE := c++_static 89 LOCAL_SRC_FILES := libs/$(TARGET_ARCH_ABI)/lib$(LOCAL_MODULE)$(TARGET_LIB_EXTENSION) 90 LOCAL_EXPORT_C_INCLUDES := $(libcxx_export_includes) 91 LOCAL_EXPORT_CPPFLAGS := $(libcxx_export_cxxflags) 92 LOCAL_EXPORT_LDFLAGS := $(libcxx_export_ldflags) 93 94 # We use the LLVM unwinder for all the 32-bit ARM targets. 95 ifneq (,$(filter armeabi%,$(TARGET_ARCH_ABI))) 96 LOCAL_EXPORT_STATIC_LIBRARIES += libunwind 97 endif 98 include $(PREBUILT_STATIC_LIBRARY) 99 100 include $(CLEAR_VARS) 101 LOCAL_MODULE := c++_shared 102 LOCAL_SRC_FILES := libs/$(TARGET_ARCH_ABI)/lib$(LOCAL_MODULE)$(TARGET_SONAME_EXTENSION) 103 LOCAL_EXPORT_C_INCLUDES := \ 104 $(libcxx_export_includes) \ 105 $(libcxxabi_c_includes) \ 106 107 # This doesn't affect the prebuilt itself since this is a prebuilt library, but 108 # the build system needs to know about the dependency so we can sort the 109 # exported includes properly. 110 LOCAL_STATIC_LIBRARIES := libandroid_support 111 LOCAL_EXPORT_CPPFLAGS := $(libcxx_export_cxxflags) 112 LOCAL_EXPORT_LDFLAGS := $(libcxx_export_ldflags) 113 114 # We use the LLVM unwinder for all the 32-bit ARM targets. 115 ifneq (,$(filter armeabi%,$(TARGET_ARCH_ABI))) 116 LOCAL_EXPORT_STATIC_LIBRARIES += libunwind 117 endif 118 include $(PREBUILT_SHARED_LIBRARY) 119 120 ifneq (,$(filter armeabi%,$(TARGET_ARCH_ABI))) 121 # We define this module here rather than in a separate cxx-stl/libunwind because 122 # we don't actually want to make the API available (yet). 123 include $(CLEAR_VARS) 124 LOCAL_MODULE := libunwind 125 LOCAL_SRC_FILES := libs/$(TARGET_ARCH_ABI)/$(LOCAL_MODULE)$(TARGET_LIB_EXTENSION) 126 include $(PREBUILT_STATIC_LIBRARY) 127 endif 128 129 $(call import-module, cxx-stl/llvm-libc++abi) 130 131 else 132 # LIBCXX_FORCE_REBUILD == true 133 134 $(call ndk_log,Rebuilding libc++ libraries from sources) 135 136 include $(CLEAR_VARS) 137 LOCAL_MODULE := c++_static 138 LOCAL_SRC_FILES := $(libcxx_sources) 139 LOCAL_C_INCLUDES := $(libcxx_includes) 140 LOCAL_CPPFLAGS := $(libcxx_cxxflags) 141 LOCAL_CPP_FEATURES := rtti exceptions 142 LOCAL_EXPORT_C_INCLUDES := $(libcxx_export_includes) 143 LOCAL_EXPORT_CPPFLAGS := $(libcxx_export_cxxflags) 144 LOCAL_EXPORT_LDFLAGS := $(libcxx_export_ldflags) 145 LOCAL_STATIC_LIBRARIES := libc++abi android_support 146 147 # We use the LLVM unwinder for all the 32-bit ARM targets. 148 ifneq (,$(filter armeabi%,$(TARGET_ARCH_ABI))) 149 LOCAL_STATIC_LIBRARIES += libunwind 150 LOCAL_EXPORT_STATIC_LIBRARIES += libunwind 151 endif 152 153 include $(BUILD_STATIC_LIBRARY) 154 155 include $(CLEAR_VARS) 156 LOCAL_MODULE := c++_shared 157 LOCAL_WHOLE_STATIC_LIBRARIES := c++_static libc++abi 158 LOCAL_EXPORT_C_INCLUDES := $(libcxx_export_includes) 159 LOCAL_EXPORT_CPPFLAGS := $(libcxx_export_cxxflags) 160 LOCAL_EXPORT_LDFLAGS := $(libcxx_export_ldflags) 161 LOCAL_STATIC_LIBRARIES := android_support 162 LOCAL_LDFLAGS := $(libcxx_ldflags) 163 # Use --as-needed to strip the DT_NEEDED on libstdc++.so (bionic's) that the 164 # driver always links for C++ but we don't use. 165 # See https://github.com/android-ndk/ndk/issues/105 166 LOCAL_LDFLAGS += -Wl,--as-needed 167 168 # We use the LLVM unwinder for all the 32-bit ARM targets. 169 ifneq (,$(filter armeabi%,$(TARGET_ARCH_ABI))) 170 LOCAL_STATIC_LIBRARIES += libunwind 171 LOCAL_EXPORT_STATIC_LIBRARIES += libunwind 172 endif 173 174 # But only need -latomic for armeabi. 175 ifeq ($(TARGET_ARCH_ABI),armeabi) 176 LOCAL_LDLIBS += -latomic 177 endif 178 include $(BUILD_SHARED_LIBRARY) 179 180 $(call import-add-path, $(LOCAL_PATH)/../..) 181 $(call import-module, external/libcxxabi) 182 183 endif # LIBCXX_FORCE_REBUILD == true 184 185 $(call import-module, android/support) 186