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 llvm_libc++_includes := $(LOCAL_PATH)/libcxx/include 21 llvm_libc++_export_includes := $(llvm_libc++_includes) 22 llvm_libc++_sources := \ 23 algorithm.cpp \ 24 bind.cpp \ 25 chrono.cpp \ 26 condition_variable.cpp \ 27 debug.cpp \ 28 exception.cpp \ 29 future.cpp \ 30 hash.cpp \ 31 ios.cpp \ 32 iostream.cpp \ 33 locale.cpp \ 34 memory.cpp \ 35 mutex.cpp \ 36 new.cpp \ 37 optional.cpp \ 38 random.cpp \ 39 regex.cpp \ 40 shared_mutex.cpp \ 41 stdexcept.cpp \ 42 string.cpp \ 43 strstream.cpp \ 44 system_error.cpp \ 45 thread.cpp \ 46 typeinfo.cpp \ 47 utility.cpp \ 48 valarray.cpp \ 49 support/android/locale_android.cpp 50 51 llvm_libc++_sources := $(llvm_libc++_sources:%=libcxx/src/%) 52 53 # For now, this library can only be used to build C++11 binaries. 54 llvm_libc++_export_cxxflags := -std=c++11 55 56 ifeq (,$(filter clang%,$(NDK_TOOLCHAIN_VERSION))) 57 # Add -fno-strict-aliasing because __list_imp::_end_ breaks TBAA rules by declaring 58 # simply as __list_node_base then casted to __list_node derived from that. See 59 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61571 for details 60 llvm_libc++_export_cxxflags += -fno-strict-aliasing 61 endif 62 63 llvm_libc++_cxxflags := $(llvm_libc++_export_cxxflags) 64 llvm_libc++_cflags := 65 66 libcxxabi_sources_dir := $(strip $(wildcard $(LOCAL_PATH)/../llvm-libc++abi)) 67 ifdef libcxxabi_sources_dir 68 libcxxabi_sources_prefix := ../llvm-libc++abi 69 else 70 libcxxabi_sources_dir := $(strip $(wildcard $(NDK_ROOT)/sources/cxx-stl/llvm-libc++abi)) 71 ifndef libcxxabi_sources_dir 72 $(error Can't find libcxxabi sources directory!!) 73 endif 74 libcxxabi_sources_prefix := $(libcxxabi_sources_dir) 75 endif 76 77 include $(libcxxabi_sources_dir)/sources.mk 78 79 ifneq (,$(filter armeabi%,$(TARGET_ARCH_ABI))) 80 # for armeabi*, use llvm libunwind 81 llvm_libc++_sources += $(addprefix $(libcxxabi_sources_prefix:%/=%)/,$(libcxxabi_src_files)) 82 llvm_libc++_cxxflags += -DLIBCXXABI_USE_LLVM_UNWINDER=1 -D__STDC_FORMAT_MACROS 83 else 84 llvm_libc++_sources += $(addprefix $(libcxxabi_sources_prefix:%/=%)/,$(libcxxabi_src_base_files)) 85 llvm_libc++_cxxflags += -DLIBCXXABI_USE_LLVM_UNWINDER=0 86 endif 87 88 llvm_libc++_includes += $(libcxxabi_c_includes) 89 llvm_libc++_export_includes += $(libcxxabi_c_includes) 90 llvm_libc++_cflags += -D__STDC_FORMAT_MACROS 91 92 ifeq (clang3.5,$(NDK_TOOLCHAIN_VERSION)) 93 # Workaround an issue of integrated-as (default in clang3.5) where it fails to compile 94 # llvm-libc++abi/libcxxabi/src/Unwind/UnwindRegistersRestore.S 95 llvm_libc++_cflags += -no-integrated-as 96 endif 97 98 ifneq ($(LIBCXX_FORCE_REBUILD),true) 99 100 $(call ndk_log,Using prebuilt libc++ libraries) 101 102 android_support_c_includes := $(LOCAL_PATH)/../../android/support/include 103 104 include $(CLEAR_VARS) 105 LOCAL_MODULE := c++_static 106 LOCAL_SRC_FILES := libs/$(TARGET_ARCH_ABI)/lib$(LOCAL_MODULE)$(TARGET_LIB_EXTENSION) 107 # For armeabi*, choose thumb mode unless LOCAL_ARM_MODE := arm 108 ifneq (,$(filter armeabi%,$(TARGET_ARCH_ABI))) 109 ifneq (arm,$(LOCAL_ARM_MODE)) 110 ifneq (arm,$(TARGET_ARM_MODE)) 111 LOCAL_SRC_FILES := libs/$(TARGET_ARCH_ABI)/thumb/lib$(LOCAL_MODULE)$(TARGET_LIB_EXTENSION) 112 endif 113 endif 114 endif 115 LOCAL_EXPORT_C_INCLUDES := $(llvm_libc++_export_includes) $(android_support_c_includes) 116 LOCAL_EXPORT_CPPFLAGS := $(llvm_libc++_export_cxxflags) 117 include $(PREBUILT_STATIC_LIBRARY) 118 119 include $(CLEAR_VARS) 120 LOCAL_MODULE := c++_shared 121 LOCAL_SRC_FILES := libs/$(TARGET_ARCH_ABI)/lib$(LOCAL_MODULE)$(TARGET_SONAME_EXTENSION) 122 # For armeabi*, choose thumb mode unless LOCAL_ARM_MODE := arm 123 ifneq (,$(filter armeabi%,$(TARGET_ARCH_ABI))) 124 ifneq (arm,$(LOCAL_ARM_MODE)) 125 ifneq (arm,$(TARGET_ARM_MODE)) 126 LOCAL_SRC_FILES := libs/$(TARGET_ARCH_ABI)/thumb/lib$(LOCAL_MODULE)$(TARGET_SONAME_EXTENSION) 127 endif 128 endif 129 endif 130 LOCAL_EXPORT_C_INCLUDES := $(llvm_libc++_export_includes) $(android_support_c_includes) 131 LOCAL_EXPORT_CPPFLAGS := $(llvm_libc++_export_cxxflags) 132 include $(PREBUILT_SHARED_LIBRARY) 133 134 else 135 # LIBCXX_FORCE_REBUILD == true 136 137 $(call ndk_log,Rebuilding libc++ libraries from sources) 138 139 include $(CLEAR_VARS) 140 LOCAL_MODULE := c++_static 141 LOCAL_SRC_FILES := $(llvm_libc++_sources) 142 LOCAL_C_INCLUDES := $(android_support_c_includes) $(llvm_libc++_includes) 143 LOCAL_CFLAGS := $(llvm_libc++_cflags) 144 LOCAL_CPPFLAGS := $(llvm_libc++_cxxflags) 145 LOCAL_CPP_FEATURES := rtti exceptions 146 LOCAL_EXPORT_C_INCLUDES := $(llvm_libc++_export_includes) 147 LOCAL_EXPORT_CPPFLAGS := $(llvm_libc++_export_cxxflags) 148 LOCAL_STATIC_LIBRARIES := android_support 149 include $(BUILD_STATIC_LIBRARY) 150 151 include $(CLEAR_VARS) 152 LOCAL_MODULE := c++_shared 153 LOCAL_SRC_FILES := $(llvm_libc++_sources) 154 LOCAL_C_INCLUDES := $(android_support_c_includes) $(llvm_libc++_includes) 155 LOCAL_CFLAGS := $(llvm_libc++_cflags) 156 LOCAL_CPPFLAGS := $(llvm_libc++_cxxflags) 157 LOCAL_CPP_FEATURES := rtti exceptions 158 LOCAL_EXPORT_C_INCLUDES := $(llvm_libc++_export_includes) 159 LOCAL_EXPORT_CPPFLAGS := $(llvm_libc++_export_cxxflags) 160 LOCAL_STATIC_LIBRARIES := android_support 161 include $(BUILD_SHARED_LIBRARY) 162 163 endif # LIBCXX_FORCE_REBUILD == true 164 165 $(call import-module, android/support) 166