Home | History | Annotate | Download | only in llvm-libc++
      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 
     12 __libcxx_force_rebuild := $(LIBCXX_FORCE_REBUILD)
     13 
     14 ifndef LIBCXX_FORCE_REBUILD
     15   ifeq (,$(strip $(wildcard $(LOCAL_PATH)/libs/$(TARGET_ARCH_ABI)/libc++_static$(TARGET_LIB_EXTENSION))))
     16     $(call __ndk_info,WARNING: Rebuilding libc++ libraries from sources!)
     17     $(call __ndk_info,You might want to use $$NDK/build/tools/build-cxx-stl.sh --stl=libc++)
     18     $(call __ndk_info,in order to build prebuilt versions to speed up your builds!)
     19     __libcxx_force_rebuild := true
     20   endif
     21 endif
     22 
     23 # Use gabi++ for x86* and mips* until libc++/libc++abi is ready for them
     24 ifneq (,$(filter x86% mips%,$(TARGET_ARCH_ABI)))
     25   __prebuilt_libcxx_compiled_with_gabixx := true
     26 else
     27   __prebuilt_libcxx_compiled_with_gabixx := false
     28 endif
     29 
     30 __libcxx_use_gabixx := $(__prebuilt_libcxx_compiled_with_gabixx)
     31 
     32 LIBCXX_USE_GABIXX := $(strip $(LIBCXX_USE_GABIXX))
     33 ifeq ($(LIBCXX_USE_GABIXX),true)
     34   __libcxx_use_gabixx := true
     35 endif
     36 
     37 ifneq ($(__libcxx_use_gabixx),$(__prebuilt_libcxx_compiled_with_gabixx))
     38   ifneq ($(__libcxx_force_rebuild),true)
     39     ifeq ($(__prebuilt_libcxx_compiled_with_gabixx),true)
     40       $(call __ndk_info,WARNING: Rebuilding libc++ libraries from sources since libc++ prebuilt libraries for $(TARGET_ARCH_ABI))
     41       $(call __ndk_info,are compiled with gabi++ but LIBCXX_USE_GABIXX is not set to true)
     42     else
     43       $(call __ndk_info,WARNING: Rebuilding libc++ libraries from sources since libc++ prebuilt libraries for $(TARGET_ARCH_ABI))
     44       $(call __ndk_info,are not compiled with gabi++ and LIBCXX_USE_GABIXX is set to true)
     45     endif
     46     __libcxx_force_rebuild := true
     47   endif
     48 endif
     49 
     50 llvm_libc++_includes := $(LOCAL_PATH)/libcxx/include
     51 llvm_libc++_export_includes := $(llvm_libc++_includes)
     52 llvm_libc++_sources := \
     53 	algorithm.cpp \
     54 	bind.cpp \
     55 	chrono.cpp \
     56 	condition_variable.cpp \
     57 	debug.cpp \
     58 	exception.cpp \
     59 	future.cpp \
     60 	hash.cpp \
     61 	ios.cpp \
     62 	iostream.cpp \
     63 	locale.cpp \
     64 	memory.cpp \
     65 	mutex.cpp \
     66 	new.cpp \
     67 	optional.cpp \
     68 	random.cpp \
     69 	regex.cpp \
     70 	shared_mutex.cpp \
     71 	stdexcept.cpp \
     72 	string.cpp \
     73 	strstream.cpp \
     74 	system_error.cpp \
     75 	thread.cpp \
     76 	typeinfo.cpp \
     77 	utility.cpp \
     78 	valarray.cpp \
     79 	support/android/locale_android.cpp
     80 
     81 llvm_libc++_sources := $(llvm_libc++_sources:%=libcxx/src/%)
     82 
     83 # For now, this library can only be used to build C++11 binaries.
     84 llvm_libc++_export_cxxflags := -std=c++11
     85 
     86 ifeq (,$(filter clang%,$(NDK_TOOLCHAIN_VERSION)))
     87 # Add -fno-strict-aliasing because __list_imp::_end_ breaks TBAA rules by declaring
     88 # simply as __list_node_base then casted to __list_node derived from that.  See
     89 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61571 for details
     90 llvm_libc++_export_cxxflags += -fno-strict-aliasing
     91 endif
     92 
     93 llvm_libc++_cxxflags := $(llvm_libc++_export_cxxflags)
     94 
     95 ifeq ($(__libcxx_use_gabixx),true)
     96 
     97 # Gabi++ emulates libcxxabi when building libcxx.
     98 llvm_libc++_cxxflags += -DLIBCXXABI=1
     99 
    100 # Find the GAbi++ sources to include them here.
    101 # The voodoo below is to allow building libc++ out of the NDK source
    102 # tree. This can make it easier to experiment / update / debug it.
    103 #
    104 libgabi++_sources_dir := $(strip $(wildcard $(LOCAL_PATH)/../gabi++))
    105 ifdef libgabi++_sources_dir
    106   libgabi++_sources_prefix := ../gabi++
    107 else
    108   libgabi++_sources_dir := $(strip $(wildcard $(NDK_ROOT)/sources/cxx-stl/gabi++))
    109   ifndef libgabi++_sources_dir
    110     $(error Can't find GAbi++ sources directory!!)
    111   endif
    112   libgabi++_sources_prefix := $(libgabi++_sources_dir)
    113 endif
    114 
    115 include $(libgabi++_sources_dir)/sources.mk
    116 llvm_libc++_sources += $(addprefix $(libgabi++_sources_prefix:%/=%)/,$(libgabi++_src_files))
    117 llvm_libc++_includes += $(libgabi++_c_includes)
    118 llvm_libc++_export_includes += $(libgabi++_c_includes)
    119 
    120 else
    121 # libc++abi
    122 
    123 libcxxabi_sources_dir := $(strip $(wildcard $(LOCAL_PATH)/../llvm-libc++abi))
    124 ifdef libcxxabi_sources_dir
    125   libcxxabi_sources_prefix := ../llvm-libc++abi
    126 else
    127   libcxxabi_sources_dir := $(strip $(wildcard $(NDK_ROOT)/sources/cxx-stl/llvm-libc++abi))
    128   ifndef libcxxabi_sources_dir
    129     $(error Can't find libcxxabi sources directory!!)
    130   endif
    131   libcxxabi_sources_prefix := $(libcxxabi_sources_dir)
    132 endif
    133 
    134 include $(libcxxabi_sources_dir)/sources.mk
    135 llvm_libc++_sources += $(addprefix $(libcxxabi_sources_prefix:%/=%)/,$(libcxxabi_src_files))
    136 llvm_libc++_includes += $(libcxxabi_c_includes)
    137 llvm_libc++_export_includes += $(libcxxabi_c_includes)
    138 
    139 endif
    140 
    141 ifneq ($(__libcxx_force_rebuild),true)
    142 
    143 $(call ndk_log,Using prebuilt libc++ libraries)
    144 
    145 android_support_c_includes := $(LOCAL_PATH)/../../android/support/include
    146 
    147 include $(CLEAR_VARS)
    148 LOCAL_MODULE := c++_static
    149 LOCAL_SRC_FILES := libs/$(TARGET_ARCH_ABI)/lib$(LOCAL_MODULE)$(TARGET_LIB_EXTENSION)
    150 # For armeabi*, choose thumb mode unless LOCAL_ARM_MODE := arm
    151 ifneq (,$(filter armeabi%,$(TARGET_ARCH_ABI)))
    152 ifneq (arm,$(LOCAL_ARM_MODE))
    153 ifneq (arm,$(TARGET_ARM_MODE))
    154 LOCAL_SRC_FILES := libs/$(TARGET_ARCH_ABI)/thumb/lib$(LOCAL_MODULE)$(TARGET_LIB_EXTENSION)
    155 endif
    156 endif
    157 endif
    158 LOCAL_EXPORT_C_INCLUDES := $(llvm_libc++_export_includes) $(android_support_c_includes)
    159 LOCAL_EXPORT_CPPFLAGS := $(llvm_libc++_export_cxxflags)
    160 include $(PREBUILT_STATIC_LIBRARY)
    161 
    162 include $(CLEAR_VARS)
    163 LOCAL_MODULE := c++_shared
    164 LOCAL_SRC_FILES := libs/$(TARGET_ARCH_ABI)/lib$(LOCAL_MODULE)$(TARGET_SONAME_EXTENSION)
    165 # For armeabi*, choose thumb mode unless LOCAL_ARM_MODE := arm
    166 ifneq (,$(filter armeabi%,$(TARGET_ARCH_ABI)))
    167 ifneq (arm,$(LOCAL_ARM_MODE))
    168 ifneq (arm,$(TARGET_ARM_MODE))
    169 LOCAL_SRC_FILES := libs/$(TARGET_ARCH_ABI)/thumb/lib$(LOCAL_MODULE)$(TARGET_SONAME_EXTENSION)
    170 endif
    171 endif
    172 endif
    173 LOCAL_EXPORT_C_INCLUDES := $(llvm_libc++_export_includes) $(android_support_c_includes)
    174 LOCAL_EXPORT_CPPFLAGS := $(llvm_libc++_export_cxxflags)
    175 include $(PREBUILT_SHARED_LIBRARY)
    176 
    177 else
    178 # __libcxx_force_rebuild == true
    179 
    180 $(call ndk_log,Rebuilding libc++ libraries from sources)
    181 
    182 include $(CLEAR_VARS)
    183 LOCAL_MODULE := c++_static
    184 LOCAL_SRC_FILES := $(llvm_libc++_sources)
    185 LOCAL_C_INCLUDES := $(android_support_c_includes) $(llvm_libc++_includes)
    186 LOCAL_CPPFLAGS := $(llvm_libc++_cxxflags)
    187 LOCAL_CPP_FEATURES := rtti exceptions
    188 LOCAL_EXPORT_C_INCLUDES := $(llvm_libc++_export_includes)
    189 LOCAL_EXPORT_CPPFLAGS := $(llvm_libc++_export_cxxflags)
    190 LOCAL_STATIC_LIBRARIES := android_support
    191 include $(BUILD_STATIC_LIBRARY)
    192 
    193 include $(CLEAR_VARS)
    194 LOCAL_MODULE := c++_shared
    195 LOCAL_SRC_FILES := $(llvm_libc++_sources)
    196 LOCAL_C_INCLUDES := $(android_support_c_includes) $(llvm_libc++_includes)
    197 LOCAL_CPPFLAGS := $(llvm_libc++_cxxflags)
    198 LOCAL_CPP_FEATURES := rtti exceptions
    199 LOCAL_EXPORT_C_INCLUDES := $(llvm_libc++_export_includes)
    200 LOCAL_EXPORT_CPPFLAGS := $(llvm_libc++_export_cxxflags)
    201 LOCAL_STATIC_LIBRARIES := android_support
    202 # For armeabi's shared version of libc++ compiled by clang, we need compiler-rt or libatomic
    203 # for __atomic_fetch_add_4.  Note that "clang -gcc-toolchain" uses gcc4.8's as/ld/libs, including
    204 # libatomic (which is not available in gcc4.6)
    205 #
    206 # On the other hand, all prebuilt libc++ libaries at sources/cxx-stl/llvm-libc++/libs are
    207 # compiled with "clang -gcc-toolchain *4.8*" with -latomic, such that uses of prebuilt
    208 # libc++_shared.so don't automatically requires -latomic or compiler-rt, unless code does
    209 # "#include <atomic>" where  __atomic_is_lock_free is needed for armeabi and mips
    210 #
    211 ifeq ($(TARGET_ARCH_ABI),armeabi)
    212 ifneq (,$(filter clang%,$(NDK_TOOLCHAIN_VERSION)))
    213 LOCAL_SHARED_LIBRARIES := compiler_rt_shared
    214 endif
    215 endif
    216 
    217 include $(BUILD_SHARED_LIBRARY)
    218 
    219 endif # __libcxx_force_rebuild == true
    220 
    221 $(call import-module, android/support)
    222 $(call import-module, android/compiler-rt)
    223