Home | History | Annotate | Download | only in tools
      1 #!/bin/sh
      2 #
      3 # Copyright (C) 2011 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 # Rebuild all target-specific prebuilts
     18 #
     19 
     20 PROGDIR=$(dirname $0)
     21 . $PROGDIR/prebuilt-common.sh
     22 
     23 NDK_DIR=$ANDROID_NDK_ROOT
     24 register_var_option "--ndk-dir=<path>" NDK_DIR "NDK installation directory"
     25 
     26 ARCHS=$(find_ndk_unknown_archs)
     27 ARCHS="$DEFAULT_ARCHS $ARCHS"
     28 register_var_option "--arch=<list>" ARCHS "List of target archs to build for"
     29 
     30 NO_GEN_PLATFORMS=
     31 register_var_option "--no-gen-platforms" NO_GEN_PLATFORMS "Don't generate platforms/ directory, use existing one"
     32 
     33 PACKAGE_DIR=
     34 register_var_option "--package-dir=<path>" PACKAGE_DIR "Package toolchain into this directory"
     35 
     36 VISIBLE_LIBGNUSTL_STATIC=
     37 register_var_option "--visible-libgnustl-static" VISIBLE_LIBGNUSTL_STATIC "Do not use hidden visibility for libgnustl_static.a"
     38 
     39 register_jobs_option
     40 
     41 PROGRAM_PARAMETERS="<toolchain-src-dir>"
     42 PROGRAM_DESCRIPTION=\
     43 "This script can be used to rebuild all the target NDK prebuilts at once.
     44 You need to give it the path to the toolchain source directory, as
     45 downloaded by the 'download-toolchain-sources.sh' dev-script."
     46 
     47 extract_parameters "$@"
     48 
     49 # Check toolchain source path
     50 SRC_DIR="$PARAMETERS"
     51 check_toolchain_src_dir "$SRC_DIR"
     52 SRC_DIR=`cd $SRC_DIR; pwd`
     53 
     54 # Now we can do the build
     55 BUILDTOOLS=$ANDROID_NDK_ROOT/build/tools
     56 
     57 dump "Building platforms and samples..."
     58 PACKAGE_FLAGS=
     59 if [ "$PACKAGE_DIR" ]; then
     60     PACKAGE_FLAGS="--package-dir=$PACKAGE_DIR"
     61 fi
     62 
     63 if [ -z "$NO_GEN_PLATFORMS" ]; then
     64     echo "Preparing the build..."
     65     run $BUILDTOOLS/gen-platforms.sh --samples --fast-copy --dst-dir=$NDK_DIR --ndk-dir=$NDK_DIR --arch=$(spaces_to_commas $ARCHS) $PACKAGE_FLAGS
     66     fail_panic "Could not generate platforms and samples directores!"
     67 else
     68     if [ ! -d "$NDK_DIR/platforms" ]; then
     69         echo "ERROR: --no-gen-platforms used but directory missing: $NDK_DIR/platforms"
     70         exit 1
     71     fi
     72 fi
     73 
     74 ARCHS=$(commas_to_spaces $ARCHS)
     75 
     76 # Detect unknown arch
     77 UNKNOWN_ARCH=$(filter_out "$DEFAULT_ARCHS" "$ARCHS")
     78 if [ ! -z "$UNKNOWN_ARCH" ]; then
     79     ARCHS=$(filter_out "$UNKNOWN_ARCH" "$ARCHS")
     80 fi
     81 
     82 FLAGS=
     83 if [ "$VERBOSE" = "yes" ]; then
     84     FLAGS=$FLAGS" --verbose"
     85 fi
     86 if [ "$VERBOSE2" = "yes" ]; then
     87     FLAGS=$FLAGS" --verbose"
     88 fi
     89 if [ "$PACKAGE_DIR" ]; then
     90     mkdir -p "$PACKAGE_DIR"
     91     fail_panic "Could not create package directory: $PACKAGE_DIR"
     92     FLAGS=$FLAGS" --package-dir=\"$PACKAGE_DIR\""
     93 fi
     94 FLAGS=$FLAGS" -j$NUM_JOBS"
     95 
     96 # First, gdbserver
     97 for ARCH in $ARCHS; do
     98     GDB_TOOLCHAINS=$(get_default_toolchain_name_for_arch $ARCH)
     99     for GDB_TOOLCHAIN in $GDB_TOOLCHAINS; do
    100         GDB_VERSION="--gdb-version="$(get_default_gdb_version_for_gcc $GDB_TOOLCHAIN)
    101         dump "Building $GDB_TOOLCHAIN gdbserver binaries..."
    102         run $BUILDTOOLS/build-gdbserver.sh "$SRC_DIR" "$NDK_DIR" "$GDB_TOOLCHAIN" "$GDB_VERSION" $FLAGS
    103         fail_panic "Could not build $GDB_TOOLCHAIN gdb-server!"
    104     done
    105 done
    106 
    107 FLAGS=$FLAGS" --ndk-dir=\"$NDK_DIR\""
    108 ABIS=$(convert_archs_to_abis $ARCHS)
    109 UNKNOWN_ABIS=$(convert_archs_to_abis $UNKNOWN_ARCH)
    110 
    111 dump "Building $ABIS compiler-rt binaries..."
    112 run $BUILDTOOLS/build-compiler-rt.sh --abis="$ABIS" $FLAGS --src-dir="$SRC_DIR/llvm-$DEFAULT_LLVM_VERSION/compiler-rt" \
    113    --llvm-version=$DEFAULT_LLVM_VERSION
    114 fail_panic "Could not build compiler-rt!"
    115 
    116 dump "Building $ABIS gabi++ binaries..."
    117 run $BUILDTOOLS/build-cxx-stl.sh --stl=gabi++ --abis="$ABIS" $FLAGS
    118 fail_panic "Could not build gabi++!"
    119 run $BUILDTOOLS/build-cxx-stl.sh --stl=gabi++ --abis="$ABIS" $FLAGS --with-debug-info
    120 fail_panic "Could not build gabi++ with debug info!"
    121 
    122 dump "Building $ABIS $UNKNOWN_ABIS stlport binaries..."
    123 run $BUILDTOOLS/build-cxx-stl.sh --stl=stlport --abis="$ABIS,$UNKNOWN_ABIS" $FLAGS
    124 fail_panic "Could not build stlport!"
    125 run $BUILDTOOLS/build-cxx-stl.sh --stl=stlport --abis="$ABIS,$UNKNOWN_ABIS" $FLAGS --with-debug-info
    126 fail_panic "Could not build stlport with debug info!"
    127 
    128 dump "Building $ABIS $UNKNOWN_ABIS libc++ binaries... with libc++abi"
    129 run $BUILDTOOLS/build-cxx-stl.sh --stl=libc++-libc++abi --abis="$ABIS,$UNKNOWN_ABIS" $FLAGS --llvm-version=$DEFAULT_LLVM_VERSION
    130 fail_panic "Could not build libc++ with libc++abi!"
    131 run $BUILDTOOLS/build-cxx-stl.sh --stl=libc++-libc++abi --abis="$ABIS,$UNKNOWN_ABIS" $FLAGS --with-debug-info --llvm-version=$DEFAULT_LLVM_VERSION
    132 fail_panic "Could not build libc++ with libc++abi and debug info!"
    133 
    134 # workaround issues in libc++/libc++abi for x86 and mips
    135 for abi in $ABIS; do
    136   case $abi in
    137      x86|x86_64|mips|mips64)
    138   dump "Rebuilding $abi libc++ binaries... with gabi++"
    139   run $BUILDTOOLS/build-cxx-stl.sh --stl=libc++-gabi++ --abis=$abi $FLAGS --llvm-version=$DEFAULT_LLVM_VERSION
    140   fail_panic "Could not build libc++ with gabi++!"
    141   run $BUILDTOOLS/build-cxx-stl.sh --stl=libc++-gabi++ --abis=$abi $FLAGS --with-debug-info --llvm-version=$DEFAULT_LLVM_VERSION
    142   fail_panic "Could not build libc++ with gabi++ and debug info!"
    143      ;;
    144   esac
    145 done
    146 
    147 if [ ! -z $VISIBLE_LIBGNUSTL_STATIC ]; then
    148     GNUSTL_STATIC_VIS_FLAG=--visible-libgnustl-static
    149 fi
    150 
    151 dump "Building $ABIS gnustl binaries..."
    152 run $BUILDTOOLS/build-gnu-libstdc++.sh --abis="$ABIS" $FLAGS $GNUSTL_STATIC_VIS_FLAG "$SRC_DIR"
    153 fail_panic "Could not build gnustl!"
    154 run $BUILDTOOLS/build-gnu-libstdc++.sh --abis="$ABIS" $FLAGS $GNUSTL_STATIC_VIS_FLAG "$SRC_DIR" --with-debug-info
    155 fail_panic "Could not build gnustl with debug info!"
    156 
    157 dump "Building $ABIS libportable binaries..."
    158 run $BUILDTOOLS/build-libportable.sh --abis="$ABIS" $FLAGS
    159 fail_panic "Could not build libportable!"
    160 
    161 if [ "$PACKAGE_DIR" ]; then
    162     dump "Done, see $PACKAGE_DIR"
    163 else
    164     dump "Done"
    165 fi
    166 
    167 exit 0
    168