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 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     future.cpp \
     31     hash.cpp \
     32     ios.cpp \
     33     iostream.cpp \
     34     locale.cpp \
     35     memory.cpp \
     36     mutex.cpp \
     37     new.cpp \
     38     optional.cpp \
     39     random.cpp \
     40     regex.cpp \
     41     shared_mutex.cpp \
     42     stdexcept.cpp \
     43     string.cpp \
     44     strstream.cpp \
     45     system_error.cpp \
     46     thread.cpp \
     47     typeinfo.cpp \
     48     utility.cpp \
     49     valarray.cpp \
     50     support/android/locale_android.cpp
     51 
     52 libcxx_sources := $(libcxx_sources:%=src/%)
     53 
     54 # For now, this library can only be used to build C++11 binaries.
     55 libcxx_export_cxxflags := -std=c++11
     56 
     57 ifeq (,$(filter clang%,$(NDK_TOOLCHAIN_VERSION)))
     58 # Add -fno-strict-aliasing because __list_imp::_end_ breaks TBAA rules by declaring
     59 # simply as __list_node_base then casted to __list_node derived from that.  See
     60 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61571 for details
     61 libcxx_export_cxxflags += -fno-strict-aliasing
     62 endif
     63 
     64 libcxx_cxxflags := $(libcxx_export_cxxflags)
     65 libcxx_cflags := -D__STDC_FORMAT_MACROS -DLIBCXX_BUILDING_LIBCXXABI
     66 
     67 libcxx_ldflags :=
     68 libcxx_export_ldflags :=
     69 # Need to make sure the unwinder is always linked with hidden visibility.
     70 ifneq (,$(filter armeabi%,$(TARGET_ARCH_ABI)))
     71     libcxx_ldflags += -Wl,--exclude-libs,libunwind.a
     72     libcxx_export_ldflags += -Wl,--exclude-libs,libunwind.a
     73 endif
     74 
     75 ifneq ($(LIBCXX_FORCE_REBUILD),true)
     76 
     77 $(call ndk_log,Using prebuilt libc++ libraries)
     78 
     79 android_support_c_includes := $(LOCAL_PATH)/../../android/support/include
     80 libcxxabi_c_includes := $(LOCAL_PATH)/../llvm-libc++abi/include
     81 
     82 include $(CLEAR_VARS)
     83 LOCAL_MODULE := c++_static
     84 LOCAL_SRC_FILES := libs/$(TARGET_ARCH_ABI)/lib$(LOCAL_MODULE)$(TARGET_LIB_EXTENSION)
     85 LOCAL_EXPORT_C_INCLUDES := $(libcxx_export_includes) $(android_support_c_includes)
     86 LOCAL_EXPORT_CPPFLAGS := $(libcxx_export_cxxflags)
     87 LOCAL_EXPORT_LDFLAGS := $(libcxx_export_ldflags)
     88 include $(PREBUILT_STATIC_LIBRARY)
     89 
     90 include $(CLEAR_VARS)
     91 LOCAL_MODULE := c++_shared
     92 LOCAL_SRC_FILES := libs/$(TARGET_ARCH_ABI)/lib$(LOCAL_MODULE)$(TARGET_SONAME_EXTENSION)
     93 LOCAL_EXPORT_C_INCLUDES := \
     94     $(libcxx_export_includes) \
     95     $(libcxxabi_c_includes) \
     96     $(android_support_c_includes)
     97 LOCAL_EXPORT_CPPFLAGS := $(libcxx_export_cxxflags)
     98 LOCAL_EXPORT_LDFLAGS := $(libcxx_export_ldflags)
     99 include $(PREBUILT_SHARED_LIBRARY)
    100 
    101 $(call import-module, cxx-stl/llvm-libc++abi)
    102 
    103 else
    104 # LIBCXX_FORCE_REBUILD == true
    105 
    106 $(call ndk_log,Rebuilding libc++ libraries from sources)
    107 
    108 android_support_c_includes := $(LOCAL_PATH)/../../ndk/sources/android/support/include
    109 
    110 include $(CLEAR_VARS)
    111 LOCAL_MODULE := c++_static
    112 LOCAL_SRC_FILES := $(libcxx_sources)
    113 LOCAL_C_INCLUDES := $(libcxx_includes) $(android_support_c_includes)
    114 LOCAL_CFLAGS := $(libcxx_cflags)
    115 LOCAL_CPPFLAGS := $(libcxx_cxxflags)
    116 LOCAL_CPP_FEATURES := rtti exceptions
    117 LOCAL_EXPORT_C_INCLUDES := $(libcxx_export_includes)
    118 LOCAL_EXPORT_CPPFLAGS := $(libcxx_export_cxxflags)
    119 LOCAL_EXPORT_LDFLAGS := $(libcxx_export_ldflags)
    120 LOCAL_STATIC_LIBRARIES := libc++abi android_support
    121 include $(BUILD_STATIC_LIBRARY)
    122 
    123 include $(CLEAR_VARS)
    124 LOCAL_MODULE := c++_shared
    125 LOCAL_WHOLE_STATIC_LIBRARIES := c++_static
    126 LOCAL_EXPORT_C_INCLUDES := $(libcxx_export_includes) $(android_support_c_includes)
    127 LOCAL_EXPORT_CPPFLAGS := $(libcxx_export_cxxflags)
    128 LOCAL_EXPORT_LDFLAGS := $(libcxx_export_ldflags)
    129 LOCAL_STATIC_LIBRARIES := libc++abi android_support
    130 LOCAL_LDFLAGS := $(libcxx_ldflags)
    131 # Use --as-needed to strip the DT_NEEDED on libstdc++.so (bionic's) that the
    132 # driver always links for C++ but we don't use.
    133 # See https://github.com/android-ndk/ndk/issues/105
    134 LOCAL_LDFLAGS += -Wl,--as-needed
    135 
    136 # We use the LLVM unwinder for all the 32-bit ARM targets.
    137 ifneq (,$(filter armeabi%,$(TARGET_ARCH_ABI)))
    138     LOCAL_STATIC_LIBRARIES += libunwind
    139 endif
    140 
    141 # But only need -latomic for armeabi.
    142 ifeq ($(TARGET_ARCH_ABI),armeabi)
    143     LOCAL_LDLIBS += -latomic
    144 endif
    145 include $(BUILD_SHARED_LIBRARY)
    146 
    147 $(call import-add-path, $(LOCAL_PATH)/../..)
    148 $(call import-module, external/libcxxabi)
    149 
    150 endif # LIBCXX_FORCE_REBUILD == true
    151 
    152 $(call import-module, android/support)
    153