• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# This file is dual licensed under the MIT and the University of Illinois Open
2# Source Licenses. See LICENSE.TXT for details.
3
4LOCAL_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
10LIBCXX_FORCE_REBUILD := $(strip $(LIBCXX_FORCE_REBUILD))
11
12__libcxx_force_rebuild := $(LIBCXX_FORCE_REBUILD)
13
14ifndef 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
21endif
22
23# Use gabi++ for x86* and mips* until libc++/libc++abi is ready for them
24ifneq (,$(filter x86% mips%,$(TARGET_ARCH_ABI)))
25  __prebuilt_libcxx_compiled_with_gabixx := true
26else
27  __prebuilt_libcxx_compiled_with_gabixx := false
28endif
29
30__libcxx_use_gabixx := $(__prebuilt_libcxx_compiled_with_gabixx)
31
32LIBCXX_USE_GABIXX := $(strip $(LIBCXX_USE_GABIXX))
33ifeq ($(LIBCXX_USE_GABIXX),true)
34  __libcxx_use_gabixx := true
35endif
36
37ifneq ($(__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
48endif
49
50llvm_libc++_includes := $(LOCAL_PATH)/libcxx/include
51llvm_libc++_export_includes := $(llvm_libc++_includes)
52llvm_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
81llvm_libc++_sources := $(llvm_libc++_sources:%=libcxx/src/%)
82
83# For now, this library can only be used to build C++11 binaries.
84llvm_libc++_export_cxxflags := -std=c++11
85
86ifeq (,$(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
90llvm_libc++_export_cxxflags += -fno-strict-aliasing
91endif
92
93llvm_libc++_cxxflags := $(llvm_libc++_export_cxxflags)
94llvm_libc++_cflags :=
95
96ifeq ($(__libcxx_use_gabixx),true)
97
98# Gabi++ emulates libcxxabi when building libcxx.
99llvm_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#
105libgabi++_sources_dir := $(strip $(wildcard $(LOCAL_PATH)/../gabi++))
106ifdef libgabi++_sources_dir
107  libgabi++_sources_prefix := ../gabi++
108else
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)
114endif
115
116include $(libgabi++_sources_dir)/sources.mk
117llvm_libc++_sources += $(addprefix $(libgabi++_sources_prefix:%/=%)/,$(libgabi++_src_files))
118llvm_libc++_includes += $(libgabi++_c_includes)
119llvm_libc++_export_includes += $(libgabi++_c_includes)
120
121else
122# libc++abi
123
124libcxxabi_sources_dir := $(strip $(wildcard $(LOCAL_PATH)/../llvm-libc++abi))
125ifdef libcxxabi_sources_dir
126  libcxxabi_sources_prefix := ../llvm-libc++abi
127else
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)
133endif
134
135include $(libcxxabi_sources_dir)/sources.mk
136llvm_libc++_sources += $(addprefix $(libcxxabi_sources_prefix:%/=%)/,$(libcxxabi_src_files))
137llvm_libc++_includes += $(libcxxabi_c_includes)
138llvm_libc++_export_includes += $(libcxxabi_c_includes)
139
140ifeq (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
143llvm_libc++_cflags += -no-integrated-as
144endif
145
146endif
147
148ifneq ($(__libcxx_force_rebuild),true)
149
150$(call ndk_log,Using prebuilt libc++ libraries)
151
152android_support_c_includes := $(LOCAL_PATH)/../../android/support/include
153
154include $(CLEAR_VARS)
155LOCAL_MODULE := c++_static
156LOCAL_SRC_FILES := libs/$(TARGET_ARCH_ABI)/lib$(LOCAL_MODULE)$(TARGET_LIB_EXTENSION)
157# For armeabi*, choose thumb mode unless LOCAL_ARM_MODE := arm
158ifneq (,$(filter armeabi%,$(TARGET_ARCH_ABI)))
159ifneq (arm,$(LOCAL_ARM_MODE))
160ifneq (arm,$(TARGET_ARM_MODE))
161LOCAL_SRC_FILES := libs/$(TARGET_ARCH_ABI)/thumb/lib$(LOCAL_MODULE)$(TARGET_LIB_EXTENSION)
162endif
163endif
164endif
165LOCAL_EXPORT_C_INCLUDES := $(llvm_libc++_export_includes) $(android_support_c_includes)
166LOCAL_EXPORT_CPPFLAGS := $(llvm_libc++_export_cxxflags)
167include $(PREBUILT_STATIC_LIBRARY)
168
169include $(CLEAR_VARS)
170LOCAL_MODULE := c++_shared
171LOCAL_SRC_FILES := libs/$(TARGET_ARCH_ABI)/lib$(LOCAL_MODULE)$(TARGET_SONAME_EXTENSION)
172# For armeabi*, choose thumb mode unless LOCAL_ARM_MODE := arm
173ifneq (,$(filter armeabi%,$(TARGET_ARCH_ABI)))
174ifneq (arm,$(LOCAL_ARM_MODE))
175ifneq (arm,$(TARGET_ARM_MODE))
176LOCAL_SRC_FILES := libs/$(TARGET_ARCH_ABI)/thumb/lib$(LOCAL_MODULE)$(TARGET_SONAME_EXTENSION)
177endif
178endif
179endif
180LOCAL_EXPORT_C_INCLUDES := $(llvm_libc++_export_includes) $(android_support_c_includes)
181LOCAL_EXPORT_CPPFLAGS := $(llvm_libc++_export_cxxflags)
182include $(PREBUILT_SHARED_LIBRARY)
183
184else
185# __libcxx_force_rebuild == true
186
187$(call ndk_log,Rebuilding libc++ libraries from sources)
188
189include $(CLEAR_VARS)
190LOCAL_MODULE := c++_static
191LOCAL_SRC_FILES := $(llvm_libc++_sources)
192LOCAL_C_INCLUDES := $(android_support_c_includes) $(llvm_libc++_includes)
193LOCAL_CFLAGS := $(llvm_libc++_cflags)
194LOCAL_CPPFLAGS := $(llvm_libc++_cxxflags)
195LOCAL_CPP_FEATURES := rtti exceptions
196LOCAL_EXPORT_C_INCLUDES := $(llvm_libc++_export_includes)
197LOCAL_EXPORT_CPPFLAGS := $(llvm_libc++_export_cxxflags)
198LOCAL_STATIC_LIBRARIES := android_support
199include $(BUILD_STATIC_LIBRARY)
200
201include $(CLEAR_VARS)
202LOCAL_MODULE := c++_shared
203LOCAL_SRC_FILES := $(llvm_libc++_sources)
204LOCAL_C_INCLUDES := $(android_support_c_includes) $(llvm_libc++_includes)
205LOCAL_CFLAGS := $(llvm_libc++_cflags)
206LOCAL_CPPFLAGS := $(llvm_libc++_cxxflags)
207LOCAL_CPP_FEATURES := rtti exceptions
208LOCAL_EXPORT_C_INCLUDES := $(llvm_libc++_export_includes)
209LOCAL_EXPORT_CPPFLAGS := $(llvm_libc++_export_cxxflags)
210LOCAL_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#
220ifeq ($(TARGET_ARCH_ABI),armeabi)
221ifneq (,$(filter clang%,$(NDK_TOOLCHAIN_VERSION)))
222LOCAL_SHARED_LIBRARIES := compiler_rt_shared
223endif
224endif
225
226include $(BUILD_SHARED_LIBRARY)
227
228endif # __libcxx_force_rebuild == true
229
230$(call import-module, android/support)
231$(call import-module, android/compiler-rt)
232