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