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 llvm_libc++_cflags :=
     95 
     96 ifeq ($(__libcxx_use_gabixx),true)
     97 
     98 # Gabi++ emulates libcxxabi when building libcxx.
     99 llvm_libc++_cxxflags += -DLIBCXXABI=1
    100 
    101 # Find the GAbi++ sources to include them here.
    102 # The voodoo below is to allow building libc++ out of the NDK source
    103 # tree. This can make it easier to experiment / update / debug it.
    104 #
    105 libgabi++_sources_dir := $(strip $(wildcard $(LOCAL_PATH)/../gabi++))
    106 ifdef libgabi++_sources_dir
    107   libgabi++_sources_prefix := ../gabi++
    108 else
    109   libgabi++_sources_dir := $(strip $(wildcard $(NDK_ROOT)/sources/cxx-stl/gabi++))
    110   ifndef libgabi++_sources_dir
    111     $(error Can't find GAbi++ sources directory!!)
    112   endif
    113   libgabi++_sources_prefix := $(libgabi++_sources_dir)
    114 endif
    115 
    116 include $(libgabi++_sources_dir)/sources.mk
    117 llvm_libc++_sources += $(addprefix $(libgabi++_sources_prefix:%/=%)/,$(libgabi++_src_files))
    118 llvm_libc++_includes += $(libgabi++_c_includes)
    119 llvm_libc++_export_includes += $(libgabi++_c_includes)
    120 
    121 else
    122 # libc++abi
    123 
    124 libcxxabi_sources_dir := $(strip $(wildcard $(LOCAL_PATH)/../llvm-libc++abi))
    125 ifdef libcxxabi_sources_dir
    126   libcxxabi_sources_prefix := ../llvm-libc++abi
    127 else
    128   libcxxabi_sources_dir := $(strip $(wildcard $(NDK_ROOT)/sources/cxx-stl/llvm-libc++abi))
    129   ifndef libcxxabi_sources_dir
    130     $(error Can't find libcxxabi sources directory!!)
    131   endif
    132   libcxxabi_sources_prefix := $(libcxxabi_sources_dir)
    133 endif
    134 
    135 include $(libcxxabi_sources_dir)/sources.mk
    136 llvm_libc++_sources += $(addprefix $(libcxxabi_sources_prefix:%/=%)/,$(libcxxabi_src_files))
    137 llvm_libc++_includes += $(libcxxabi_c_includes)
    138 llvm_libc++_export_includes += $(libcxxabi_c_includes)
    139 
    140 ifeq (clang3.5,$(NDK_TOOLCHAIN_VERSION))
    141 # Workaround an issue of integrated-as (default in clang3.5) where it fails to compile
    142 # llvm-libc++abi/libcxxabi/src/Unwind/UnwindRegistersRestore.S
    143 llvm_libc++_cflags += -no-integrated-as
    144 endif
    145 
    146 endif
    147 
    148 ifneq ($(__libcxx_force_rebuild),true)
    149 
    150 $(call ndk_log,Using prebuilt libc++ libraries)
    151 
    152 android_support_c_includes := $(LOCAL_PATH)/../../android/support/include
    153 
    154 include $(CLEAR_VARS)
    155 LOCAL_MODULE := c++_static
    156 LOCAL_SRC_FILES := libs/$(TARGET_ARCH_ABI)/lib$(LOCAL_MODULE)$(TARGET_LIB_EXTENSION)
    157 # For armeabi*, choose thumb mode unless LOCAL_ARM_MODE := arm
    158 ifneq (,$(filter armeabi%,$(TARGET_ARCH_ABI)))
    159 ifneq (arm,$(LOCAL_ARM_MODE))
    160 ifneq (arm,$(TARGET_ARM_MODE))
    161 LOCAL_SRC_FILES := libs/$(TARGET_ARCH_ABI)/thumb/lib$(LOCAL_MODULE)$(TARGET_LIB_EXTENSION)
    162 endif
    163 endif
    164 endif
    165 LOCAL_EXPORT_C_INCLUDES := $(llvm_libc++_export_includes) $(android_support_c_includes)
    166 LOCAL_EXPORT_CPPFLAGS := $(llvm_libc++_export_cxxflags)
    167 include $(PREBUILT_STATIC_LIBRARY)
    168 
    169 include $(CLEAR_VARS)
    170 LOCAL_MODULE := c++_shared
    171 LOCAL_SRC_FILES := libs/$(TARGET_ARCH_ABI)/lib$(LOCAL_MODULE)$(TARGET_SONAME_EXTENSION)
    172 # For armeabi*, choose thumb mode unless LOCAL_ARM_MODE := arm
    173 ifneq (,$(filter armeabi%,$(TARGET_ARCH_ABI)))
    174 ifneq (arm,$(LOCAL_ARM_MODE))
    175 ifneq (arm,$(TARGET_ARM_MODE))
    176 LOCAL_SRC_FILES := libs/$(TARGET_ARCH_ABI)/thumb/lib$(LOCAL_MODULE)$(TARGET_SONAME_EXTENSION)
    177 endif
    178 endif
    179 endif
    180 LOCAL_EXPORT_C_INCLUDES := $(llvm_libc++_export_includes) $(android_support_c_includes)
    181 LOCAL_EXPORT_CPPFLAGS := $(llvm_libc++_export_cxxflags)
    182 include $(PREBUILT_SHARED_LIBRARY)
    183 
    184 else
    185 # __libcxx_force_rebuild == true
    186 
    187 $(call ndk_log,Rebuilding libc++ libraries from sources)
    188 
    189 include $(CLEAR_VARS)
    190 LOCAL_MODULE := c++_static
    191 LOCAL_SRC_FILES := $(llvm_libc++_sources)
    192 LOCAL_C_INCLUDES := $(android_support_c_includes) $(llvm_libc++_includes)
    193 LOCAL_CFLAGS := $(llvm_libc++_cflags)
    194 LOCAL_CPPFLAGS := $(llvm_libc++_cxxflags)
    195 LOCAL_CPP_FEATURES := rtti exceptions
    196 LOCAL_EXPORT_C_INCLUDES := $(llvm_libc++_export_includes)
    197 LOCAL_EXPORT_CPPFLAGS := $(llvm_libc++_export_cxxflags)
    198 LOCAL_STATIC_LIBRARIES := android_support
    199 include $(BUILD_STATIC_LIBRARY)
    200 
    201 include $(CLEAR_VARS)
    202 LOCAL_MODULE := c++_shared
    203 LOCAL_SRC_FILES := $(llvm_libc++_sources)
    204 LOCAL_C_INCLUDES := $(android_support_c_includes) $(llvm_libc++_includes)
    205 LOCAL_CFLAGS := $(llvm_libc++_cflags)
    206 LOCAL_CPPFLAGS := $(llvm_libc++_cxxflags)
    207 LOCAL_CPP_FEATURES := rtti exceptions
    208 LOCAL_EXPORT_C_INCLUDES := $(llvm_libc++_export_includes)
    209 LOCAL_EXPORT_CPPFLAGS := $(llvm_libc++_export_cxxflags)
    210 LOCAL_STATIC_LIBRARIES := android_support
    211 # For armeabi's shared version of libc++ compiled by clang, we need compiler-rt or libatomic
    212 # for __atomic_fetch_add_4.  Note that "clang -gcc-toolchain" uses gcc4.8's as/ld/libs, including
    213 # libatomic (which is not available in gcc4.6)
    214 #
    215 # On the other hand, all prebuilt libc++ libaries at sources/cxx-stl/llvm-libc++/libs are
    216 # compiled with "clang -gcc-toolchain *4.8*" with -latomic, such that uses of prebuilt
    217 # libc++_shared.so don't automatically requires -latomic or compiler-rt, unless code does
    218 # "#include <atomic>" where  __atomic_is_lock_free is needed for armeabi and mips
    219 #
    220 ifeq ($(TARGET_ARCH_ABI),armeabi)
    221 ifneq (,$(filter clang%,$(NDK_TOOLCHAIN_VERSION)))
    222 LOCAL_SHARED_LIBRARIES := compiler_rt_shared
    223 endif
    224 endif
    225 
    226 include $(BUILD_SHARED_LIBRARY)
    227 
    228 endif # __libcxx_force_rebuild == true
    229 
    230 $(call import-module, android/support)
    231 $(call import-module, android/compiler-rt)
    232