Home | History | Annotate | Download | only in tools
      1 #!/bin/sh
      2 #
      3 # Copyright (C) 2013 The Android Open Source Project
      4 #
      5 # Licensed under the Apache License, Version 2.0 (the "License");
      6 # you may not use this file except in compliance with the License.
      7 # You may obtain a copy of the License at
      8 #
      9 #      http://www.apache.org/licenses/LICENSE-2.0
     10 #
     11 # Unless required by applicable law or agreed to in writing, software
     12 # distributed under the License is distributed on an "AS IS" BASIS,
     13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14 # See the License for the specific language governing permissions and
     15 # limitations under the License.
     16 #
     17 #  This shell script is used to rebuild one of the NDK C++ STL
     18 #  implementations from sources. To use it:
     19 #
     20 #   - Define CXX_STL to one of 'gabi++', 'stlport' or 'libc++'
     21 #   - Run it.
     22 #
     23 
     24 # include common function and variable definitions
     25 . `dirname $0`/prebuilt-common.sh
     26 . `dirname $0`/builder-funcs.sh
     27 
     28 CXX_STL_LIST="gabi++ stlport libc++"
     29 
     30 PROGRAM_PARAMETERS=""
     31 
     32 PROGRAM_DESCRIPTION=\
     33 "Rebuild one of the following NDK C++ runtimes: $CXX_STL_LIST.
     34 
     35 This script is called when pacakging a new NDK release. It will simply
     36 rebuild the static and shared libraries of a given C++ runtime from
     37 sources.
     38 
     39 Use the --stl=<name> option to specify which runtime you want to rebuild.
     40 
     41 This requires a temporary NDK installation containing platforms and
     42 toolchain binaries for all target architectures.
     43 
     44 By default, this will try with the current NDK directory, unless
     45 you use the --ndk-dir=<path> option.
     46 
     47 If you want to use clang to rebuild the binaries, please use
     48 --llvm-version=<ver> option.
     49 
     50 The output will be placed in appropriate sub-directories of
     51 <ndk>/sources/cxx-stl/$CXX_STL_SUBDIR, but you can override this with
     52 the --out-dir=<path> option.
     53 "
     54 
     55 CXX_STL=
     56 register_var_option "--stl=<name>" CXX_STL "Select C++ runtime to rebuild."
     57 
     58 PACKAGE_DIR=
     59 register_var_option "--package-dir=<path>" PACKAGE_DIR "Put prebuilt tarballs into <path>."
     60 
     61 NDK_DIR=
     62 register_var_option "--ndk-dir=<path>" NDK_DIR "Specify NDK root path for the build."
     63 
     64 BUILD_DIR=
     65 OPTION_BUILD_DIR=
     66 register_var_option "--build-dir=<path>" OPTION_BUILD_DIR "Specify temporary build dir."
     67 
     68 OUT_DIR=
     69 register_var_option "--out-dir=<path>" OUT_DIR "Specify output directory directly."
     70 
     71 ABIS="$PREBUILT_ABIS"
     72 register_var_option "--abis=<list>" ABIS "Specify list of target ABIs."
     73 
     74 NO_MAKEFILE=
     75 register_var_option "--no-makefile" NO_MAKEFILE "Do not use makefile to speed-up build"
     76 
     77 VISIBLE_STATIC=
     78 register_var_option "--visible-static" VISIBLE_STATIC "Do not use hidden visibility for the static library"
     79 
     80 WITH_DEBUG_INFO=
     81 register_var_option "--with-debug-info" WITH_DEBUG_INFO "Build with -g.  STL is still built with optimization but with debug info"
     82 
     83 GCC_VERSION=
     84 register_var_option "--gcc-version=<ver>" GCC_VERSION "Specify GCC version"
     85 
     86 LLVM_VERSION=
     87 register_var_option "--llvm-version=<ver>" LLVM_VERSION "Specify LLVM version"
     88 
     89 register_jobs_option
     90 
     91 register_try64_option
     92 
     93 extract_parameters "$@"
     94 
     95 if [ -n "${LLVM_VERSION}" -a -n "${GCC_VERSION}" ]; then
     96     panic "Cannot set both LLVM_VERSION and GCC_VERSION. Make up your mind!"
     97 fi
     98 
     99 ABIS=$(commas_to_spaces $ABIS)
    100 UNKNOWN_ABIS=
    101 if [ "$ABIS" = "${ABIS%%64*}" ]; then
    102     UNKNOWN_ABIS="$(filter_out "$PREBUILT_ABIS mips32r6" "$ABIS" )"
    103     if [ -n "$UNKNOWN_ABIS" ] && [ -n "$(find_ndk_unknown_archs)" ]; then
    104         ABIS="$(filter_out "$UNKNOWN_ABIS" "$ABIS")"
    105         ABIS="$ABIS $(find_ndk_unknown_archs)"
    106     fi
    107 fi
    108 
    109 # Handle NDK_DIR
    110 if [ -z "$NDK_DIR" ] ; then
    111     NDK_DIR=$ANDROID_NDK_ROOT
    112     log "Auto-config: --ndk-dir=$NDK_DIR"
    113 else
    114   if [ ! -d "$NDK_DIR" ]; then
    115     panic "NDK directory does not exist: $NDK_DIR"
    116   fi
    117 fi
    118 
    119 # Handle OUT_DIR
    120 if [ -z "$OUT_DIR" ] ; then
    121   OUT_DIR=$ANDROID_NDK_ROOT
    122   log "Auto-config: --out-dir=$OUT_DIR"
    123 else
    124   mkdir -p "$OUT_DIR"
    125   fail_panic "Could not create directory: $OUT_DIR"
    126 fi
    127 
    128 # Check that --stl=<name> is used with one of the supported runtime names.
    129 if [ -z "$CXX_STL" ]; then
    130   panic "Please use --stl=<name> to select a C++ runtime to rebuild."
    131 fi
    132 
    133 # Derive runtime, and normalize CXX_STL
    134 CXX_SUPPORT_LIB=gabi++
    135 case $CXX_STL in
    136   gabi++)
    137     ;;
    138   stlport)
    139     ;;
    140   libc++)
    141     CXX_SUPPORT_LIB=gabi++  # libc++abi
    142     ;;
    143   libc++-libc++abi)
    144     CXX_SUPPORT_LIB=libc++abi
    145     CXX_STL=libc++
    146     ;;
    147   libc++-gabi++)
    148     CXX_SUPPORT_LIB=gabi++
    149     CXX_STL=libc++
    150     ;;
    151   *)
    152     panic "Invalid --stl value ('$CXX_STL'), please use one of: $CXX_STL_LIST."
    153     ;;
    154 esac
    155 
    156 if [ -z "$OPTION_BUILD_DIR" ]; then
    157     BUILD_DIR=$NDK_TMPDIR/build-$CXX_STL
    158 else
    159     BUILD_DIR=$OPTION_BUILD_DIR
    160 fi
    161 rm -rf "$BUILD_DIR"
    162 mkdir -p "$BUILD_DIR"
    163 fail_panic "Could not create build directory: $BUILD_DIR"
    164 
    165 # Location of the various C++ runtime source trees.  Use symlink from
    166 # $BUILD_DIR instead of $NDK which may contain full path of builder's working dir
    167 
    168 rm -f $BUILD_DIR/ndk
    169 ln -sf $ANDROID_NDK_ROOT $BUILD_DIR/ndk
    170 
    171 GABIXX_SRCDIR=$BUILD_DIR/ndk/$GABIXX_SUBDIR
    172 STLPORT_SRCDIR=$BUILD_DIR/ndk/$STLPORT_SUBDIR
    173 LIBCXX_SRCDIR=$BUILD_DIR/ndk/$LIBCXX_SUBDIR
    174 LIBCXXABI_SRCDIR=$BUILD_DIR/ndk/$LIBCXXABI_SUBDIR
    175 
    176 if [ "$CXX_SUPPORT_LIB" = "gabi++" ]; then
    177     LIBCXX_INCLUDES="-I$LIBCXX_SRCDIR/libcxx/include -I$ANDROID_NDK_ROOT/sources/android/support/include -I$GABIXX_SRCDIR/include"
    178 elif [ "$CXX_SUPPORT_LIB" = "libc++abi" ]; then
    179     LIBCXX_INCLUDES="-I$LIBCXX_SRCDIR/libcxx/include -I$ANDROID_NDK_ROOT/sources/android/support/include -I$LIBCXXABI_SRCDIR/include"
    180 else
    181     panic "Unknown CXX_SUPPORT_LIB: $CXX_SUPPORT_LIB"
    182 fi
    183 
    184 COMMON_C_CXX_FLAGS="-fPIC -O2 -ffunction-sections -fdata-sections"
    185 COMMON_CXXFLAGS="-fexceptions -frtti -fuse-cxa-atexit"
    186 
    187 if [ "$WITH_DEBUG_INFO" ]; then
    188     COMMON_C_CXX_FLAGS="$COMMON_C_CXX_FLAGS -g"
    189 fi
    190 
    191 if [ "$CXX_STL" = "libc++" ]; then
    192     # Use clang to build libc++ by default.
    193     if [ -z "$LLVM_VERSION" -a -z "$GCC_VERSION" ]; then
    194         LLVM_VERSION=$DEFAULT_LLVM_VERSION
    195     fi
    196 fi
    197 
    198 # Determine GAbi++ build parameters. Note that GAbi++ is also built as part
    199 # of STLport and Libc++, in slightly different ways.
    200 if [ "$CXX_SUPPORT_LIB" = "gabi++" ]; then
    201     if [ "$CXX_STL" = "libc++" ]; then
    202         GABIXX_INCLUDES="$LIBCXX_INCLUDES"
    203         GABIXX_CXXFLAGS="$GABIXX_CXXFLAGS -DLIBCXXABI=1"
    204     else
    205         GABIXX_INCLUDES="-I$GABIXX_SRCDIR/include"
    206     fi
    207     GABIXX_CFLAGS="$COMMON_C_CXX_FLAGS $GABIXX_INCLUDES"
    208     GABIXX_CXXFLAGS="$GABIXX_CXXFLAGS $GABIXX_CFLAGS $COMMON_CXXFLAGS"
    209     GABIXX_SOURCES=$(cd $ANDROID_NDK_ROOT/$GABIXX_SUBDIR && ls src/*.cc)
    210     GABIXX_LDFLAGS="-ldl"
    211 fi
    212 
    213 # Determine STLport build parameters
    214 STLPORT_CFLAGS="$COMMON_C_CXX_FLAGS -DGNU_SOURCE -I$STLPORT_SRCDIR/stlport $GABIXX_INCLUDES"
    215 STLPORT_CXXFLAGS="$STLPORT_CFLAGS $COMMON_CXXFLAGS"
    216 STLPORT_SOURCES=\
    217 "src/dll_main.cpp \
    218 src/fstream.cpp \
    219 src/strstream.cpp \
    220 src/sstream.cpp \
    221 src/ios.cpp \
    222 src/stdio_streambuf.cpp \
    223 src/istream.cpp \
    224 src/ostream.cpp \
    225 src/iostream.cpp \
    226 src/codecvt.cpp \
    227 src/collate.cpp \
    228 src/ctype.cpp \
    229 src/monetary.cpp \
    230 src/num_get.cpp \
    231 src/num_put.cpp \
    232 src/num_get_float.cpp \
    233 src/num_put_float.cpp \
    234 src/numpunct.cpp \
    235 src/time_facets.cpp \
    236 src/messages.cpp \
    237 src/locale.cpp \
    238 src/locale_impl.cpp \
    239 src/locale_catalog.cpp \
    240 src/facets_byname.cpp \
    241 src/complex.cpp \
    242 src/complex_io.cpp \
    243 src/complex_trig.cpp \
    244 src/string.cpp \
    245 src/bitset.cpp \
    246 src/allocators.cpp \
    247 src/c_locale.c \
    248 src/cxa.c"
    249 
    250 # Determine Libc++ build parameters
    251 LIBCXX_LINKER_SCRIPT=export_symbols.txt
    252 LIBCXX_CFLAGS="$COMMON_C_CXX_FLAGS $LIBCXX_INCLUDES -Drestrict=__restrict__"
    253 LIBCXX_CXXFLAGS="$LIBCXX_CFLAGS -DLIBCXXABI=1 -std=c++11"
    254 if [ -f "$_BUILD_SRCDIR/$LIBCXX_LINKER_SCRIPT" ]; then
    255     LIBCXX_LDFLAGS="-Wl,--version-script,\$_BUILD_SRCDIR/$LIBCXX_LINKER_SCRIPT"
    256 fi
    257 LIBCXX_SOURCES=\
    258 "libcxx/src/algorithm.cpp \
    259 libcxx/src/bind.cpp \
    260 libcxx/src/chrono.cpp \
    261 libcxx/src/condition_variable.cpp \
    262 libcxx/src/debug.cpp \
    263 libcxx/src/exception.cpp \
    264 libcxx/src/future.cpp \
    265 libcxx/src/hash.cpp \
    266 libcxx/src/ios.cpp \
    267 libcxx/src/iostream.cpp \
    268 libcxx/src/locale.cpp \
    269 libcxx/src/memory.cpp \
    270 libcxx/src/mutex.cpp \
    271 libcxx/src/new.cpp \
    272 libcxx/src/optional.cpp \
    273 libcxx/src/random.cpp \
    274 libcxx/src/regex.cpp \
    275 libcxx/src/shared_mutex.cpp \
    276 libcxx/src/stdexcept.cpp \
    277 libcxx/src/string.cpp \
    278 libcxx/src/strstream.cpp \
    279 libcxx/src/system_error.cpp \
    280 libcxx/src/thread.cpp \
    281 libcxx/src/typeinfo.cpp \
    282 libcxx/src/utility.cpp \
    283 libcxx/src/valarray.cpp \
    284 libcxx/src/support/android/locale_android.cpp \
    285 "
    286 
    287 LIBCXXABI_SOURCES=\
    288 "../llvm-libc++abi/libcxxabi/src/abort_message.cpp \
    289 ../llvm-libc++abi/libcxxabi/src/cxa_aux_runtime.cpp \
    290 ../llvm-libc++abi/libcxxabi/src/cxa_default_handlers.cpp \
    291 ../llvm-libc++abi/libcxxabi/src/cxa_demangle.cpp \
    292 ../llvm-libc++abi/libcxxabi/src/cxa_exception.cpp \
    293 ../llvm-libc++abi/libcxxabi/src/cxa_exception_storage.cpp \
    294 ../llvm-libc++abi/libcxxabi/src/cxa_guard.cpp \
    295 ../llvm-libc++abi/libcxxabi/src/cxa_handlers.cpp \
    296 ../llvm-libc++abi/libcxxabi/src/cxa_new_delete.cpp \
    297 ../llvm-libc++abi/libcxxabi/src/cxa_personality.cpp \
    298 ../llvm-libc++abi/libcxxabi/src/cxa_unexpected.cpp \
    299 ../llvm-libc++abi/libcxxabi/src/cxa_vector.cpp \
    300 ../llvm-libc++abi/libcxxabi/src/cxa_virtual.cpp \
    301 ../llvm-libc++abi/libcxxabi/src/exception.cpp \
    302 ../llvm-libc++abi/libcxxabi/src/private_typeinfo.cpp \
    303 ../llvm-libc++abi/libcxxabi/src/stdexcept.cpp \
    304 ../llvm-libc++abi/libcxxabi/src/typeinfo.cpp \
    305 ../llvm-libc++abi/libcxxabi/src/Unwind/libunwind.cpp \
    306 ../llvm-libc++abi/libcxxabi/src/Unwind/Unwind-EHABI.cpp \
    307 ../llvm-libc++abi/libcxxabi/src/Unwind/UnwindLevel1.c \
    308 ../llvm-libc++abi/libcxxabi/src/Unwind/UnwindLevel1-gcc-ext.c \
    309 ../llvm-libc++abi/libcxxabi/src/Unwind/UnwindRegistersRestore.S \
    310 ../llvm-libc++abi/libcxxabi/src/Unwind/UnwindRegistersSave.S \
    311 "
    312 
    313 # android/support files for libc++
    314 SUPPORT32_SOURCES=\
    315 "../../android/support/src/libdl_support.c \
    316 ../../android/support/src/locale_support.c \
    317 ../../android/support/src/math_support.c \
    318 ../../android/support/src/stdlib_support.c \
    319 ../../android/support/src/wchar_support.c \
    320 ../../android/support/src/locale/duplocale.c \
    321 ../../android/support/src/locale/freelocale.c \
    322 ../../android/support/src/locale/localeconv.c \
    323 ../../android/support/src/locale/newlocale.c \
    324 ../../android/support/src/locale/uselocale.c \
    325 ../../android/support/src/stdio/stdio_impl.c \
    326 ../../android/support/src/stdio/strtod.c \
    327 ../../android/support/src/stdio/vfprintf.c \
    328 ../../android/support/src/stdio/vfwprintf.c \
    329 ../../android/support/src/msun/e_log2.c \
    330 ../../android/support/src/msun/e_log2f.c \
    331 ../../android/support/src/msun/s_nan.c \
    332 ../../android/support/src/musl-multibyte/btowc.c \
    333 ../../android/support/src/musl-multibyte/internal.c \
    334 ../../android/support/src/musl-multibyte/mblen.c \
    335 ../../android/support/src/musl-multibyte/mbrlen.c \
    336 ../../android/support/src/musl-multibyte/mbrtowc.c \
    337 ../../android/support/src/musl-multibyte/mbsinit.c \
    338 ../../android/support/src/musl-multibyte/mbsnrtowcs.c \
    339 ../../android/support/src/musl-multibyte/mbsrtowcs.c \
    340 ../../android/support/src/musl-multibyte/mbstowcs.c \
    341 ../../android/support/src/musl-multibyte/mbtowc.c \
    342 ../../android/support/src/musl-multibyte/wcrtomb.c \
    343 ../../android/support/src/musl-multibyte/wcsnrtombs.c \
    344 ../../android/support/src/musl-multibyte/wcsrtombs.c \
    345 ../../android/support/src/musl-multibyte/wcstombs.c \
    346 ../../android/support/src/musl-multibyte/wctob.c \
    347 ../../android/support/src/musl-multibyte/wctomb.c \
    348 ../../android/support/src/musl-ctype/iswalnum.c \
    349 ../../android/support/src/musl-ctype/iswalpha.c \
    350 ../../android/support/src/musl-ctype/iswblank.c \
    351 ../../android/support/src/musl-ctype/iswcntrl.c \
    352 ../../android/support/src/musl-ctype/iswctype.c \
    353 ../../android/support/src/musl-ctype/iswdigit.c \
    354 ../../android/support/src/musl-ctype/iswgraph.c \
    355 ../../android/support/src/musl-ctype/iswlower.c \
    356 ../../android/support/src/musl-ctype/iswprint.c \
    357 ../../android/support/src/musl-ctype/iswpunct.c \
    358 ../../android/support/src/musl-ctype/iswspace.c \
    359 ../../android/support/src/musl-ctype/iswupper.c \
    360 ../../android/support/src/musl-ctype/iswxdigit.c \
    361 ../../android/support/src/musl-ctype/isxdigit.c \
    362 ../../android/support/src/musl-ctype/towctrans.c \
    363 ../../android/support/src/musl-ctype/wcswidth.c \
    364 ../../android/support/src/musl-ctype/wctrans.c \
    365 ../../android/support/src/musl-ctype/wcwidth.c \
    366 ../../android/support/src/musl-locale/catclose.c \
    367 ../../android/support/src/musl-locale/catgets.c \
    368 ../../android/support/src/musl-locale/catopen.c \
    369 ../../android/support/src/musl-locale/iconv.c \
    370 ../../android/support/src/musl-locale/intl.c \
    371 ../../android/support/src/musl-locale/isalnum_l.c \
    372 ../../android/support/src/musl-locale/isalpha_l.c \
    373 ../../android/support/src/musl-locale/isblank_l.c \
    374 ../../android/support/src/musl-locale/iscntrl_l.c \
    375 ../../android/support/src/musl-locale/isdigit_l.c \
    376 ../../android/support/src/musl-locale/isgraph_l.c \
    377 ../../android/support/src/musl-locale/islower_l.c \
    378 ../../android/support/src/musl-locale/isprint_l.c \
    379 ../../android/support/src/musl-locale/ispunct_l.c \
    380 ../../android/support/src/musl-locale/isspace_l.c \
    381 ../../android/support/src/musl-locale/isupper_l.c \
    382 ../../android/support/src/musl-locale/iswalnum_l.c \
    383 ../../android/support/src/musl-locale/iswalpha_l.c \
    384 ../../android/support/src/musl-locale/iswblank_l.c \
    385 ../../android/support/src/musl-locale/iswcntrl_l.c \
    386 ../../android/support/src/musl-locale/iswctype_l.c \
    387 ../../android/support/src/musl-locale/iswdigit_l.c \
    388 ../../android/support/src/musl-locale/iswgraph_l.c \
    389 ../../android/support/src/musl-locale/iswlower_l.c \
    390 ../../android/support/src/musl-locale/iswprint_l.c \
    391 ../../android/support/src/musl-locale/iswpunct_l.c \
    392 ../../android/support/src/musl-locale/iswspace_l.c \
    393 ../../android/support/src/musl-locale/iswupper_l.c \
    394 ../../android/support/src/musl-locale/iswxdigit_l.c \
    395 ../../android/support/src/musl-locale/isxdigit_l.c \
    396 ../../android/support/src/musl-locale/langinfo.c \
    397 ../../android/support/src/musl-locale/strcasecmp_l.c \
    398 ../../android/support/src/musl-locale/strcoll.c \
    399 ../../android/support/src/musl-locale/strerror_l.c \
    400 ../../android/support/src/musl-locale/strfmon.c \
    401 ../../android/support/src/musl-locale/strftime_l.c \
    402 ../../android/support/src/musl-locale/strncasecmp_l.c \
    403 ../../android/support/src/musl-locale/strxfrm.c \
    404 ../../android/support/src/musl-locale/tolower_l.c \
    405 ../../android/support/src/musl-locale/toupper_l.c \
    406 ../../android/support/src/musl-locale/towctrans_l.c \
    407 ../../android/support/src/musl-locale/towlower_l.c \
    408 ../../android/support/src/musl-locale/towupper_l.c \
    409 ../../android/support/src/musl-locale/wcscoll.c \
    410 ../../android/support/src/musl-locale/wcsxfrm.c \
    411 ../../android/support/src/musl-locale/wctrans_l.c \
    412 ../../android/support/src/musl-locale/wctype_l.c \
    413 ../../android/support/src/musl-math/frexpf.c \
    414 ../../android/support/src/musl-math/frexpl.c \
    415 ../../android/support/src/musl-math/frexp.c \
    416 ../../android/support/src/musl-stdio/swprintf.c \
    417 ../../android/support/src/musl-stdio/vwprintf.c \
    418 ../../android/support/src/musl-stdio/wprintf.c \
    419 ../../android/support/src/musl-stdio/printf.c \
    420 ../../android/support/src/musl-stdio/snprintf.c \
    421 ../../android/support/src/musl-stdio/sprintf.c \
    422 ../../android/support/src/musl-stdio/vprintf.c \
    423 ../../android/support/src/musl-stdio/vsprintf.c \
    424 ../../android/support/src/wcstox/intscan.c \
    425 ../../android/support/src/wcstox/floatscan.c \
    426 ../../android/support/src/wcstox/shgetc.c \
    427 ../../android/support/src/wcstox/wcstod.c \
    428 ../../android/support/src/wcstox/wcstol.c \
    429 "
    430 # Replaces broken implementations in x86 libm.so
    431 SUPPORT32_SOURCES_x86=\
    432 "../../android/support/src/musl-math/scalbln.c \
    433 ../../android/support/src/musl-math/scalblnf.c \
    434 ../../android/support/src/musl-math/scalblnl.c \
    435 ../../android/support/src/musl-math/scalbnl.c \
    436 "
    437 
    438 # android/support files for libc++
    439 SUPPORT64_SOURCES=\
    440 "../../android/support/src/musl-locale/catclose.c \
    441 ../../android/support/src/musl-locale/catgets.c \
    442 ../../android/support/src/musl-locale/catopen.c \
    443 "
    444 
    445 # If the --no-makefile flag is not used, we're going to put all build
    446 # commands in a temporary Makefile that we will be able to invoke with
    447 # -j$NUM_JOBS to build stuff in parallel.
    448 #
    449 if [ -z "$NO_MAKEFILE" ]; then
    450     MAKEFILE=$BUILD_DIR/Makefile
    451 else
    452     MAKEFILE=
    453 fi
    454 
    455 # Define a few common variables based on parameters.
    456 case $CXX_STL in
    457   gabi++)
    458     CXX_STL_LIB=libgabi++
    459     CXX_STL_SUBDIR=$GABIXX_SUBDIR
    460     CXX_STL_SRCDIR=$GABIXX_SRCDIR
    461     CXX_STL_CFLAGS=$GABIXX_CFLAGS
    462     CXX_STL_CXXFLAGS=$GABIXX_CXXFLAGS
    463     CXX_STL_LDFLAGS=$GABIXX_LDFLAGS
    464     CXX_STL_SOURCES=$GABIXX_SOURCES
    465     CXX_STL_PACKAGE=gabixx
    466     ;;
    467   stlport)
    468     CXX_STL_LIB=libstlport
    469     CXX_STL_SUBDIR=$STLPORT_SUBDIR
    470     CXX_STL_SRCDIR=$STLPORT_SRCDIR
    471     CXX_STL_CFLAGS=$STLPORT_CFLAGS
    472     CXX_STL_CXXFLAGS=$STLPORT_CXXFLAGS
    473     CXX_STL_LDFLAGS=$STLPORT_LDFLAGS
    474     CXX_STL_SOURCES=$STLPORT_SOURCES
    475     CXX_STL_PACKAGE=stlport
    476     ;;
    477   libc++)
    478     CXX_STL_LIB=libc++
    479     CXX_STL_SUBDIR=$LIBCXX_SUBDIR
    480     CXX_STL_SRCDIR=$LIBCXX_SRCDIR
    481     CXX_STL_CFLAGS=$LIBCXX_CFLAGS
    482     CXX_STL_CXXFLAGS=$LIBCXX_CXXFLAGS
    483     CXX_STL_LDFLAGS=$LIBCXX_LDFLAGS
    484     CXX_STL_SOURCES=$LIBCXX_SOURCES
    485     CXX_STL_PACKAGE=libcxx
    486     ;;
    487   *)
    488     panic "Internal error: Unknown STL name '$CXX_STL'"
    489     ;;
    490 esac
    491 
    492 HIDDEN_VISIBILITY_FLAGS="-fvisibility=hidden -fvisibility-inlines-hidden"
    493 
    494 # By default, all static libraries include hidden ELF symbols, except
    495 # if one uses the --visible-static option.
    496 if [ -z "$VISIBLE_STATIC" ]; then
    497     STATIC_CONLYFLAGS="$HIDDEN_VISIBILITY_FLAGS"
    498     STATIC_CXXFLAGS="$HIDDEN_VISIBILITY_FLAGS"
    499 else
    500     STATIC_CONLYFLAGS=
    501     STATIC_CXXFLAGS=
    502 fi
    503 SHARED_CONLYFLAGS="$HIDDEN_VISIBILITY_FLAGS"
    504 SHARED_CXXFLAGS=
    505 
    506 
    507 # build_stl_libs_for_abi
    508 # $1: ABI
    509 # $2: build directory
    510 # $3: build type: "static" or "shared"
    511 # $4: installation directory
    512 # $5: (optional) thumb
    513 build_stl_libs_for_abi ()
    514 {
    515     local ARCH BINPREFIX SYSROOT
    516     local ABI=$1
    517     local THUMB="$5"
    518     local BUILDDIR="$2"/$THUMB
    519     local TYPE="$3"
    520     local DSTDIR="$4"
    521     local FLOAT_ABI=""
    522     local DEFAULT_CFLAGS DEFAULT_CXXFLAGS
    523     local SRC OBJ OBJECTS EXTRA_CFLAGS EXTRA_CXXFLAGS EXTRA_LDFLAGS LIB_SUFFIX GCCVER
    524 
    525     EXTRA_CFLAGS=""
    526     EXTRA_CXXFLAGS=""
    527     EXTRA_LDFLAGS=""
    528 
    529     case $ABI in
    530         armeabi-v7a-hard)
    531             EXTRA_CFLAGS="-mhard-float -D_NDK_MATH_NO_SOFTFP=1"
    532             EXTRA_CXXFLAGS="-mhard-float -D_NDK_MATH_NO_SOFTFP=1"
    533             EXTRA_LDFLAGS="-Wl,--no-warn-mismatch -lm_hard"
    534             FLOAT_ABI="hard"
    535             ;;
    536         arm64-v8a)
    537             EXTRA_CFLAGS="-mfix-cortex-a53-835769"
    538             EXTRA_CXXFLAGS="-mfix-cortex-a53-835769"
    539             ;;
    540         x86|x86_64)
    541             # ToDo: remove the following once all x86-based device call JNI function with
    542             #       stack aligned to 16-byte
    543             EXTRA_CFLAGS="-mstackrealign"
    544             EXTRA_CXXFLAGS="-mstackrealign"
    545             ;;
    546         mips32r6)
    547             EXTRA_CFLAGS="-mips32r6"
    548             EXTRA_CXXFLAGS="-mips32r6"
    549             EXTRA_LDFLAGS="-mips32r6"
    550             ;;
    551     esac
    552 
    553     if [ -n "$THUMB" ]; then
    554         EXTRA_CFLAGS="$EXTRA_CFLAGS -mthumb"
    555         EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS -mthumb"
    556     fi
    557 
    558     if [ "$TYPE" = "static" ]; then
    559         EXTRA_CFLAGS="$EXTRA_CFLAGS $STATIC_CONLYFLAGS"
    560         EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS $STATIC_CXXFLAGS"
    561     else
    562         EXTRA_CFLAGS="$EXTRA_CFLAGS $SHARED_CONLYFLAGS"
    563         EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS $SHARED_CXXFLAGS"
    564     fi
    565 
    566     DSTDIR=$DSTDIR/$CXX_STL_SUBDIR/libs/$ABI/$THUMB
    567     LIB_SUFFIX="$(get_lib_suffix_for_abi $ABI)"
    568 
    569     mkdir -p "$BUILDDIR"
    570     mkdir -p "$DSTDIR"
    571 
    572     if [ -n "$GCC_VERSION" ]; then
    573         GCCVER=$GCC_VERSION
    574         EXTRA_CFLAGS="$EXTRA_CFLAGS -std=c99"
    575     else
    576         ARCH=$(convert_abi_to_arch $ABI)
    577         GCCVER=$(get_default_gcc_version_for_arch $ARCH)
    578     fi
    579 
    580     # libc++ built with clang (for ABI armeabi-only) produces
    581     # libc++_shared.so and libc++_static.a with undefined __atomic_fetch_add_4
    582     # Add -latomic.
    583     if [ -n "$LLVM_VERSION" -a "$CXX_STL_LIB" = "libc++" ]; then
    584         # clang3.5 use integrated-as as default, which has trouble compiling
    585         # llvm-libc++abi/libcxxabi/src/Unwind/UnwindRegistersRestore.S
    586         if [ "$LLVM_VERSION" = "3.5" ]; then
    587             EXTRA_CFLAGS="${EXTRA_CFLAGS} -no-integrated-as"
    588             EXTRA_CXXFLAGS="${EXTRA_CXXFLAGS} -no-integrated-as"
    589         fi
    590         if [ "$ABI" = "armeabi" ]; then
    591             # EHABI tables were added as experimental flags in llvm 3.4. In 3.5, these
    592             # are now the defaults and the flags have been removed. Add these flags
    593             # explicitly only for llvm 3.4.
    594             if [ "$LLVM_VERSION" = "3.4" ]; then
    595                 EXTRA_CFLAGS="${EXTRA_CFLAGS} -mllvm -arm-enable-ehabi-descriptors \
    596                               -mllvm -arm-enable-ehabi"
    597                 EXTRA_CXXFLAGS="${EXTRA_CXXFLAGS} -mllvm -arm-enable-ehabi-descriptors \
    598                                 -mllvm -arm-enable-ehabi"
    599             fi
    600             EXTRA_LDFLAGS="$EXTRA_LDFLAGS -latomic"
    601         fi
    602     fi
    603 
    604     builder_begin_android $ABI "$BUILDDIR" "$GCCVER" "$LLVM_VERSION" "$MAKEFILE"
    605 
    606     builder_set_dstdir "$DSTDIR"
    607     builder_reset_cflags DEFAULT_CFLAGS
    608     builder_reset_cxxflags DEFAULT_CXXFLAGS
    609 
    610     if [ "$CXX_SUPPORT_LIB" = "gabi++" ]; then
    611         builder_set_srcdir "$GABIXX_SRCDIR"
    612         builder_cflags "$DEFAULT_CFLAGS $GABIXX_CFLAGS $EXTRA_CFLAGS"
    613         builder_cxxflags "$DEFAULT_CXXFLAGS $GABIXX_CXXFLAGS $EXTRA_CXXFLAGS"
    614         builder_ldflags "$GABIXX_LDFLAGS $EXTRA_LDFLAGS"
    615         if [ "$(find_ndk_unknown_archs)" != "$ABI" ]; then
    616             builder_sources $GABIXX_SOURCES
    617         elif [ "$CXX_STL" = "gabi++" ]; then
    618             log "Could not build gabi++ with unknown arch!"
    619             exit 1
    620         else
    621             builder_sources src/delete.cc src/new.cc
    622         fi
    623     fi
    624 
    625     # Build the runtime sources, except if we're only building GAbi++
    626     if [ "$CXX_STL" != "gabi++" ]; then
    627       builder_set_srcdir "$CXX_STL_SRCDIR"
    628       builder_reset_cflags
    629       builder_cflags "$DEFAULT_CFLAGS $CXX_STL_CFLAGS $EXTRA_CFLAGS"
    630       builder_reset_cxxflags
    631       builder_cxxflags "$DEFAULT_CXXFLAGS $CXX_STL_CXXFLAGS $EXTRA_CXXFLAGS"
    632       builder_ldflags "$CXX_STL_LDFLAGS $EXTRA_LDFLAGS"
    633       builder_sources $CXX_STL_SOURCES
    634       if [ "$CXX_SUPPORT_LIB" = "libc++abi" ]; then
    635           builder_sources $LIBCXXABI_SOURCES
    636           builder_ldflags "-ldl"
    637       fi
    638       if [ "$CXX_STL" = "libc++" ]; then
    639         if [ "$ABI" = "${ABI%%64*}" ]; then
    640           if [ "$ABI" = "x86" ]; then
    641             builder_sources $SUPPORT32_SOURCES $SUPPORT32_SOURCES_x86
    642           else
    643             builder_sources $SUPPORT32_SOURCES
    644 	  fi
    645         else
    646           builder_sources $SUPPORT64_SOURCES
    647         fi
    648       fi
    649     fi
    650 
    651     if [ "$TYPE" = "static" ]; then
    652         log "Building $DSTDIR/${CXX_STL_LIB}_static.a"
    653         builder_static_library ${CXX_STL_LIB}_static
    654     else
    655         log "Building $DSTDIR/${CXX_STL_LIB}_shared${LIB_SUFFIX}"
    656         if [ "$(find_ndk_unknown_archs)" != "$ABI" ]; then
    657             builder_shared_library ${CXX_STL_LIB}_shared $LIB_SUFFIX "$FLOAT_ABI"
    658         else
    659             builder_ldflags "-lm -lc"
    660             builder_nostdlib_shared_library ${CXX_STL_LIB}_shared $LIB_SUFFIX # Don't use libgcc
    661         fi
    662     fi
    663 
    664     builder_end
    665 }
    666 
    667 for ABI in $ABIS; do
    668     build_stl_libs_for_abi $ABI "$BUILD_DIR/$ABI/static" "static" "$OUT_DIR"
    669     build_stl_libs_for_abi $ABI "$BUILD_DIR/$ABI/shared" "shared" "$OUT_DIR"
    670     # build thumb version of libraries for 32-bit arm
    671     if [ "$ABI" != "${ABI%%arm*}" -a "$ABI" = "${ABI%%64*}" ] ; then
    672         build_stl_libs_for_abi $ABI "$BUILD_DIR/$ABI/static" "static" "$OUT_DIR" thumb
    673         build_stl_libs_for_abi $ABI "$BUILD_DIR/$ABI/shared" "shared" "$OUT_DIR" thumb
    674     fi
    675 done
    676 
    677 # If needed, package files into tarballs
    678 if [ -n "$PACKAGE_DIR" ] ; then
    679     for ABI in $ABIS; do
    680         FILES=""
    681         LIB_SUFFIX="$(get_lib_suffix_for_abi $ABI)"
    682         for LIB in ${CXX_STL_LIB}_static.a ${CXX_STL_LIB}_shared${LIB_SUFFIX}; do
    683 	    if [ -d "$CXX_STL_SUBDIR/libs/$ABI/thumb" ]; then
    684                 FILES="$FILES $CXX_STL_SUBDIR/libs/$ABI/thumb/$LIB"
    685             fi
    686             FILES="$FILES $CXX_STL_SUBDIR/libs/$ABI/$LIB"
    687         done
    688         PACKAGE="$PACKAGE_DIR/${CXX_STL_PACKAGE}-libs-$ABI"
    689         if [ "$WITH_DEBUG_INFO" ]; then
    690             PACKAGE="${PACKAGE}-g"
    691         fi
    692         PACKAGE="${PACKAGE}.tar.bz2"
    693         log "Packaging: $PACKAGE"
    694         pack_archive "$PACKAGE" "$OUT_DIR" "$FILES"
    695         fail_panic "Could not package $ABI $CXX_STL binaries!"
    696         dump "Packaging: $PACKAGE"
    697     done
    698 fi
    699 
    700 if [ -z "$OPTION_BUILD_DIR" ]; then
    701     log "Cleaning up..."
    702     rm -rf $BUILD_DIR
    703 else
    704     log "Don't forget to cleanup: $BUILD_DIR"
    705 fi
    706 
    707 log "Done!"
    708