diff options
author | Dan Albert <danalbert@google.com> | 2014-04-08 12:03:21 -0700 |
---|---|---|
committer | Dan Albert <danalbert@google.com> | 2014-04-15 14:59:23 -0700 |
commit | 2ef012e47441428f752c6a29d2927513669dda30 (patch) | |
tree | 24993a217c7316a03b2f46afd002fa8691d4f21c | |
parent | 3b74eb32545456120f507d5dc2b74d11a3b89bb0 (diff) | |
download | libcxx_35a-2ef012e47441428f752c6a29d2927513669dda30.tar.gz |
Get libc++ building for Android
This adds an Android makefile, aliases locale aware cctype and cwctype
functions, fixes broken configuration in libcxx, and stubs functions missing
from bionic.
Change-Id: I247372d87caabe0310bedc4540b68ab2ed1986c1
-rw-r--r-- | Android.mk | 71 | ||||
-rw-r--r-- | include/__config | 4 | ||||
-rw-r--r-- | include/__locale | 2 | ||||
-rw-r--r-- | include/cwchar | 3 | ||||
-rw-r--r-- | include/locale | 2 | ||||
-rw-r--r-- | include/support/android/langinfo.h | 104 | ||||
-rw-r--r-- | include/support/android/locale_bionic.h | 68 | ||||
-rw-r--r-- | include/support/android/nl_types.h | 34 | ||||
-rw-r--r-- | include/support/android/wchar_bionic.h | 36 | ||||
-rw-r--r-- | src/locale.cpp | 2 | ||||
-rw-r--r-- | src/memory.cpp | 4 | ||||
-rw-r--r-- | src/stubs.cpp | 101 |
12 files changed, 427 insertions, 4 deletions
diff --git a/Android.mk b/Android.mk new file mode 100644 index 00000000..92ecddca --- /dev/null +++ b/Android.mk @@ -0,0 +1,71 @@ +# +# Copyright (C) 2014 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +LOCAL_PATH := $(call my-dir) + +LIBCXX_SRC_FILES := \ + src/algorithm.cpp \ + src/bind.cpp \ + src/chrono.cpp \ + src/condition_variable.cpp \ + src/debug.cpp \ + src/exception.cpp \ + src/future.cpp \ + src/hash.cpp \ + src/ios.cpp \ + src/iostream.cpp \ + src/locale.cpp \ + src/memory.cpp \ + src/mutex.cpp \ + src/new.cpp \ + src/optional.cpp \ + src/random.cpp \ + src/regex.cpp \ + src/shared_mutex.cpp \ + src/stdexcept.cpp \ + src/string.cpp \ + src/strstream.cpp \ + src/system_error.cpp \ + src/thread.cpp \ + src/typeinfo.cpp \ + src/utility.cpp \ + src/valarray.cpp \ + src/stubs.cpp \ + +LIBCXX_CPPFLAGS := \ + -I$(LOCAL_PATH)/include/ \ + -Iexternal/libcxxabi/include \ + -std=c++11 \ + -nostdlib \ + -fexceptions \ + +include $(CLEAR_VARS) +LOCAL_MODULE := libc++ +LOCAL_CLANG := true +LOCAL_SRC_FILES := $(LIBCXX_SRC_FILES) +LOCAL_CPPFLAGS := $(LIBCXX_CPPFLAGS) +LOCAL_SYSTEM_SHARED_LIBRARIES := libc +LOCAL_SHARED_LIBRARIES := libcxxabi +include $(BUILD_SHARED_LIBRARY) + +include $(CLEAR_VARS) +LOCAL_MODULE := libc++ +LOCAL_CLANG := true +LOCAL_SRC_FILES := $(LIBCXX_SRC_FILES) +LOCAL_CPPFLAGS := $(LIBCXX_CPPFLAGS) +LOCAL_LDFLAGS := -lrt -pthread +LOCAL_SHARED_LIBRARIES := libcxxabi +include $(BUILD_HOST_SHARED_LIBRARY) diff --git a/include/__config b/include/__config index 33254e98..b64e4b0b 100644 --- a/include/__config +++ b/include/__config @@ -317,7 +317,7 @@ typedef __char32_t char32_t; #if defined(__FreeBSD__) #define _LIBCPP_HAS_QUICK_EXIT #define _LIBCPP_HAS_C11_FEATURES -#elif defined(__linux__) +#elif defined(__linux__) && defined(__GLIBC__) #include <features.h> #if __GLIBC_PREREQ(2, 15) #define _LIBCPP_HAS_QUICK_EXIT @@ -577,7 +577,7 @@ template <unsigned> struct __static_assert_check {}; #define _LIBCPP_LOCALE__L_EXTENSIONS 1 #endif -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) || defined(__ANDROID__) #define _DECLARE_C99_LDBL_MATH 1 #endif diff --git a/include/__locale b/include/__locale index fb5b196c..2d994fd6 100644 --- a/include/__locale +++ b/include/__locale @@ -23,6 +23,8 @@ # include <support/win32/locale_win32.h> #elif defined(_AIX) # include <support/ibm/xlocale.h> +#elif defined(__ANDROID__) +# include <support/android/locale_bionic.h> #elif (defined(__GLIBC__) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__sun__)) || defined(__EMSCRIPTEN__) || defined(__IBMCPP__) # include <xlocale.h> #endif // _WIN32 || __GLIBC__ || __APPLE__ || __FreeBSD__ || __sun__ || __EMSCRIPTEN__ || __IBMCPP__ diff --git a/include/cwchar b/include/cwchar index 9f51587c..01f7cf16 100644 --- a/include/cwchar +++ b/include/cwchar @@ -109,6 +109,9 @@ size_t wcsrtombs(char* restrict dst, const wchar_t** restrict src, size_t len, #if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__) #include <support/win32/support.h> // pull in *swprintf defines #endif // _LIBCPP_MSVCRT +#ifdef __ANDROID__ +#include <support/android/wchar_bionic.h> +#endif // __ANDROID__ #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header diff --git a/include/locale b/include/locale index cdfe120e..3f0fa4d1 100644 --- a/include/locale +++ b/include/locale @@ -193,6 +193,8 @@ template <class charT> class messages_byname; #include <ctime> #if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__) #include <support/win32/locale_win32.h> +#elif defined(__ANDROID__) +#include <support/android/nl_types.h> #else // _LIBCPP_MSVCRT #include <nl_types.h> #endif // !_LIBCPP_MSVCRT diff --git a/include/support/android/langinfo.h b/include/support/android/langinfo.h new file mode 100644 index 00000000..c706c5dc --- /dev/null +++ b/include/support/android/langinfo.h @@ -0,0 +1,104 @@ +// -*- C++ -*- +//===--------------------- support/android/langinfo.h ---------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +#ifndef _LIBCPP_SUPPORT_ANDROID_LANGINFO_H_ +#define _LIBCPP_SUPPORT_ANDROID_LANGINFO_H_ + +#ifdef __ANDROID__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include <support/android/nl_types.h> + +#define _NL_ITEM(category,index) (((category) << 10) | (index)) + +#define _NL_ITEM_CATEGORY(nl) ((nl) >> 10) +#define _NL_ITEM_INDEX(nl) ((nl) & 0x3ff) + +#define CODESET _NL_ITEM(LC_CTYPE, 0) + +/* Abbreviated days of the week */ +#define ABDAY_1 _NL_ITEM(LC_TIME,1) +#define ABDAY_2 _NL_ITEM(LC_TIME,2) +#define ABDAY_3 _NL_ITEM(LC_TIME,3) +#define ABDAY_4 _NL_ITEM(LC_TIME,4) +#define ABDAY_5 _NL_ITEM(LC_TIME,5) +#define ABDAY_6 _NL_ITEM(LC_TIME,6) +#define ABDAY_7 _NL_ITEM(LC_TIME,7) + +/* Long names of the week */ +#define DAY_1 _NL_ITEM(LC_TIME,11) +#define DAY_2 _NL_ITEM(LC_TIME,12) +#define DAY_3 _NL_ITEM(LC_TIME,13) +#define DAY_4 _NL_ITEM(LC_TIME,14) +#define DAY_5 _NL_ITEM(LC_TIME,15) +#define DAY_6 _NL_ITEM(LC_TIME,16) +#define DAY_7 _NL_ITEM(LC_TIME,17) + +/* Abbreviated month names */ +#define ABMON_1 _NL_ITEM(LC_TIME,21) +#define ABMON_2 _NL_ITEM(LC_TIME,22) +#define ABMON_3 _NL_ITEM(LC_TIME,23) +#define ABMON_4 _NL_ITEM(LC_TIME,24) +#define ABMON_5 _NL_ITEM(LC_TIME,25) +#define ABMON_6 _NL_ITEM(LC_TIME,26) +#define ABMON_7 _NL_ITEM(LC_TIME,27) +#define ABMON_8 _NL_ITEM(LC_TIME,28) +#define ABMON_9 _NL_ITEM(LC_TIME,29) +#define ABMON_10 _NL_ITEM(LC_TIME,30) +#define ABMON_11 _NL_ITEM(LC_TIME,31) +#define ABMON_12 _NL_ITEM(LC_TIME,32) + +/* Long month names */ +#define MON_1 _NL_ITEM(LC_TIME,41) +#define MON_2 _NL_ITEM(LC_TIME,42) +#define MON_3 _NL_ITEM(LC_TIME,43) +#define MON_4 _NL_ITEM(LC_TIME,44) +#define MON_5 _NL_ITEM(LC_TIME,45) +#define MON_6 _NL_ITEM(LC_TIME,46) +#define MON_7 _NL_ITEM(LC_TIME,47) +#define MON_8 _NL_ITEM(LC_TIME,48) +#define MON_9 _NL_ITEM(LC_TIME,49) +#define MON_10 _NL_ITEM(LC_TIME,50) +#define MON_11 _NL_ITEM(LC_TIME,51) +#define MON_12 _NL_ITEM(LC_TIME,52) + +#define AM_STR _NL_ITEM(LC_TIME,53) +#define PM_STR _NL_ITEM(LC_TIME,54) +#define D_T_FMT _NL_ITEM(LC_TIME,55) +#define D_FMT _NL_ITEM(LC_TIME,56) +#define T_FMT _NL_ITEM(LC_TIME,57) +#define T_FMT_AMPM _NL_ITEM(LC_TIME,58) +#define ERA _NL_ITEM(LC_TIME,59) +#define ERA_D_FMT _NL_ITEM(LC_TIME,60) +#define ERA_D_T_FMT _NL_ITEM(LC_TIME,61) +#define ERA_T_FMT _NL_ITEM(LC_TIME,62) +#define ALT_DIGITS _NL_ITEM(LC_TIME,70) + +#define INT_CURRENCY_SYMBOL _NL_ITEM(LC_MONETARY,0) +#define CURRENCY_SYMBOL _NL_ITEM(LC_MONETARY,1) +#define MON_DECIMAL_POINT _NL_ITEM(LC_MONETARY,2) +#define MON_THOUSANDS_SEP _NL_ITEM(LC_MONETARY,3) +#define MON_GROUPING _NL_ITEM(LC_MONETARY,4) +#define POSITIVE_SIGN _NL_ITEM(LC_MONETARY,5) +#define NEGATIVE_SIGN _NL_ITEM(LC_MONETARY,6) +#define INT_FRAC_DIGITS _NL_ITEM(LC_MONETARY,7) +#define FRAC_DIGITS _NL_ITEM(LC_MONETARY,8) + +char *nl_langinfo(nl_item); +char *nl_langinfo_l(nl_item, locale_t); + +#ifdef __cplusplus +} +#endif + +#endif // __ANDROID__ +#endif /* _LIBCPP_SUPPORT_ANDROID_LANGINFO_H_ */ diff --git a/include/support/android/locale_bionic.h b/include/support/android/locale_bionic.h new file mode 100644 index 00000000..fa15b167 --- /dev/null +++ b/include/support/android/locale_bionic.h @@ -0,0 +1,68 @@ +// -*- C++ -*- +//===------------------- support/android/locale_bionic.h ------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_SUPPORT_ANDROID_LOCALE_BIONIC_H +#define _LIBCPP_SUPPORT_ANDROID_LOCALE_BIONIC_H + +#if defined(__ANDROID__) + +#ifdef __cplusplus +extern "C" { +#endif + +#include <xlocale.h> + +#define isalnum_l(c, locale) isalnum(c) +#define isalpha_l(c, locale) isalpha(c) +#define isascii_l(c, locale) isascii(c) +#define isblank_l(c, locale) isblank(c) +#define iscntrl_l(c, locale) iscntrl(c) +#define isdigit_l(c, locale) isdigit(c) +#define isgraph_l(c, locale) isgraph(c) +#define islower_l(c, locale) islower(c) +#define isprint_l(c, locale) isprint(c) +#define ispunct_l(c, locale) ispunct(c) +#define isspace_l(c, locale) isspace(c) +#define isupper_l(c, locale) isupper(c) +#define isxdigit_l(c, locale) isxdigit(c) +#define iswalnum_l(c, locale) iswalnum(c) +#define iswalpha_l(c, locale) iswalpha(c) +#define iswascii_l(c, locale) iswascii(c) +#define iswblank_l(c, locale) iswblank(c) +#define iswcntrl_l(c, locale) iswcntrl(c) +#define iswdigit_l(c, locale) iswdigit(c) +#define iswgraph_l(c, locale) iswgraph(c) +#define iswlower_l(c, locale) iswlower(c) +#define iswprint_l(c, locale) iswprint(c) +#define iswpunct_l(c, locale) iswpunct(c) +#define iswspace_l(c, locale) iswspace(c) +#define iswupper_l(c, locale) iswupper(c) +#define iswxdigit_l(c, locale) iswxdigit(c) +#define toupper_l(c, locale) toupper(c) +#define tolower_l(c, locale) tolower(c) +#define towupper_l(c, locale) towupper(c) +#define towlower_l(c, locale) towlower(c) +#define strcoll_l(s1, s2, locale) strcoll(s1, s2) +#define strxfrm_l(dest, src, n, locale) strxfrm(dest, src, n) +#define strftime_l(s, max, format, tm, locale) strftime(s, max, format, tm) +#define wcscoll_l(s1, s2, locale) wcscoll(s1, s2) +#define wcsxfrm_l(dest, src, n, locale) wcsxfrm(dest, src, n) +#define strtold_l(nptr, endptr, locale) strtold(nptr, endptr) +#define strtoll_l(nptr, endptr, base, locale) strtoll(nptr, endptr, base) +#define strtoull_l(nptr, endptr, base, locale) strtoull(nptr, endptr, base) +#define wcstoll_l(nptr, endptr, locale) wcstoll(nptr, endptr) +#define wcstoull_l(nptr, endptr, locale) wcstoull(nptr, endptr) +#define wcstold_l(nptr, endptr, locale) wcstold(nptr, endptr) + +#ifdef __cplusplus +} +#endif +#endif // defined(__ANDROID__) +#endif // _LIBCPP_SUPPORT_ANDROID_LOCALE_BIONIC_H diff --git a/include/support/android/nl_types.h b/include/support/android/nl_types.h new file mode 100644 index 00000000..e1eb63f6 --- /dev/null +++ b/include/support/android/nl_types.h @@ -0,0 +1,34 @@ +// -*- C++ -*- +//===--------------------- support/android/nl_types.h ---------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +#ifndef _LIBCPP_SUPPORT_ANDROID_NL_TYPES_H +#define _LIBCPP_SUPPORT_ANDROID_NL_TYPES_H + +#ifdef __ANDROID__ + +#ifdef __cplusplus +extern "C" { +#endif + +#define NL_SETD 1 +#define NL_CAT_LOCALE 1 + +typedef void *nl_catd; +typedef int nl_item; + +nl_catd catopen(const char *, int); +int catclose(nl_catd); +char *catgets(nl_catd, int, int, const char *); + +#ifdef __cplusplus +} +#endif + +#endif // __ANDROID__ +#endif // _LIBCPP_SUPPORT_ANDROID_NL_TYPES_H diff --git a/include/support/android/wchar_bionic.h b/include/support/android/wchar_bionic.h new file mode 100644 index 00000000..91985e4d --- /dev/null +++ b/include/support/android/wchar_bionic.h @@ -0,0 +1,36 @@ +// -*- C++ -*- +//===------------------- support/android/wchar_bionic.h -------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_SUPPORT_ANDROID_WCHAR_BIONIC_H +#define _LIBCPP_SUPPORT_ANDROID_WCHAR_BIONIC_H + +#ifdef __ANDROID__ + +#ifdef __cplusplus +extern "C" { +#endif + +int vfwscanf(FILE *, const wchar_t *, va_list); +int vswscanf(const wchar_t *, const wchar_t *, va_list); +int vwscanf(const wchar_t *, va_list); +float wcstof(const wchar_t *, wchar_t **); +double wcstod(const wchar_t *, wchar_t **); +long double wcstold(const wchar_t *, wchar_t **); +long long wcstoll(const wchar_t *, wchar_t **, int); +unsigned long long wcstoull(const wchar_t *, wchar_t **, int); +size_t wcsnrtombs(char *, const wchar_t **, size_t, size_t, mbstate_t *); +size_t mbsnrtowcs(wchar_t *, const char **, size_t, size_t, mbstate_t *); +int mbtowc(wchar_t *, const char *, size_t); + +#ifdef __cplusplus +} +#endif +#endif // __ANDROID__ +#endif // _LIBCPP_SUPPORT_ANDROID_WCHAR_BIONIC_H diff --git a/src/locale.cpp b/src/locale.cpp index 4877f2b6..afc96bd8 100644 --- a/src/locale.cpp +++ b/src/locale.cpp @@ -30,6 +30,8 @@ #include "__sso_allocator" #if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__) #include <support/win32/locale_win32.h> +#elif defined(__ANDROID__) +#include <support/android/langinfo.h> #else // _LIBCPP_MSVCRT #include <langinfo.h> #endif // !_LIBCPP_MSVCRT diff --git a/src/memory.cpp b/src/memory.cpp index 666673fc..02f6bf9d 100644 --- a/src/memory.cpp +++ b/src/memory.cpp @@ -109,7 +109,7 @@ __shared_weak_count::lock() _NOEXCEPT return 0; } -#ifndef _LIBCPP_NO_RTTI +#if !defined(_LIBCPP_NO_RTTI) || !defined(_LIBCPP_BUILD_STATIC) const void* __shared_weak_count::__get_deleter(const type_info&) const _NOEXCEPT @@ -117,7 +117,7 @@ __shared_weak_count::__get_deleter(const type_info&) const _NOEXCEPT return 0; } -#endif // _LIBCPP_NO_RTTI +#endif // !defined(_LIBCPP_NO_RTTI) || !defined(_LIBCPP_BUILD_STATIC) #if __has_feature(cxx_atomic) diff --git a/src/stubs.cpp b/src/stubs.cpp new file mode 100644 index 00000000..d8b1ecbc --- /dev/null +++ b/src/stubs.cpp @@ -0,0 +1,101 @@ +// -*- C++ -*- +//===----------------------------- stubs.cpp ------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifdef __ANDROID__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include <errno.h> +#include <wchar.h> + +#include <support/android/nl_types.h> + +static void unimplemented_stub(const char* function) { + const char* fmt = "%s(3) is not implemented on Android\n"; + fprintf(stderr, fmt, function); +} + +#define UNIMPLEMENTED unimplemented_stub(__PRETTY_FUNCTION__) + +float wcstof(const wchar_t *, wchar_t **) +{ + UNIMPLEMENTED; + return 0; +} + +double wcstod(const wchar_t *, wchar_t **) +{ + UNIMPLEMENTED; + return 0; +} + +long double wcstold(const wchar_t *, wchar_t **) +{ + UNIMPLEMENTED; + return 0; +} + +long long wcstoll(const wchar_t *, wchar_t **, int) +{ + UNIMPLEMENTED; + return 0; +} + +unsigned long long wcstoull(const wchar_t *, wchar_t **, int) +{ + UNIMPLEMENTED; + return 0; +} + +size_t wcsnrtombs(char *, const wchar_t **, size_t, size_t, mbstate_t *) +{ + UNIMPLEMENTED; + errno = EILSEQ; + return (size_t)-1; +} + +size_t mbsnrtowcs(wchar_t *, const char **, size_t, size_t, mbstate_t *) +{ + UNIMPLEMENTED; + errno = EILSEQ; + return (size_t)-1; +} + +int mbtowc(wchar_t *, const char *, size_t) +{ + UNIMPLEMENTED; + return -1; +} + +nl_catd catopen(const char *, int) +{ + UNIMPLEMENTED; + return (nl_catd)-1; +} + +int catclose(nl_catd) +{ + UNIMPLEMENTED; + return -1; +} + +char *catgets(nl_catd, int, int, const char *message) +{ + UNIMPLEMENTED; + return (char *)message; +} + +#ifdef __cplusplus +} +#endif + +#endif // __ANDROID__ |