Revert "Roll NDK to r11c and extract it into its own repository."
[android_tools.git] / ndk / build / tools / build-target-prebuilts.sh
blob57d0f9241b569c95171c5416c2ff0d04bbeb776b
1 #!/bin/sh
3 # Copyright (C) 2011 The Android Open Source Project
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
9 # http://www.apache.org/licenses/LICENSE-2.0
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.
17 # Rebuild all target-specific prebuilts
20 PROGDIR=$(dirname $0)
21 . $PROGDIR/prebuilt-common.sh
23 NDK_DIR=$ANDROID_NDK_ROOT
24 register_var_option "--ndk-dir=<path>" NDK_DIR "NDK installation directory"
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"
30 NO_GEN_PLATFORMS=
31 register_var_option "--no-gen-platforms" NO_GEN_PLATFORMS "Don't generate platforms/ directory, use existing one"
33 GCC_VERSION_LIST="default" # it's arch defined by default so use default keyword
34 register_var_option "--gcc-version-list=<vers>" GCC_VERSION_LIST "GCC version list (libgnustl should be built per each GCC version)"
36 LLVM_VERSION=
37 register_var_option "--llvm-version=<vers>" LLVM_VERSION "LLVM version"
39 PACKAGE_DIR=
40 register_var_option "--package-dir=<path>" PACKAGE_DIR "Package toolchain into this directory"
42 VISIBLE_LIBGNUSTL_STATIC=
43 register_var_option "--visible-libgnustl-static" VISIBLE_LIBGNUSTL_STATIC "Do not use hidden visibility for libgnustl_static.a"
45 register_jobs_option
47 register_try64_option
49 PROGRAM_PARAMETERS="<toolchain-src-dir>"
50 PROGRAM_DESCRIPTION=\
51 "This script can be used to rebuild all the target NDK prebuilts at once.
52 You need to give it the path to the toolchain source directory, as
53 downloaded by the 'download-toolchain-sources.sh' dev-script."
55 extract_parameters "$@"
57 # Pickup one GCC_VERSION for the cases where we want only one build
58 # That's actually all cases except libgnustl where we are building for each GCC version
59 GCC_VERSION=
60 if [ "$GCC_VERSION_LIST" != "default" ]; then
61 GCC_VERSIONS=$(commas_to_spaces $GCC_VERSION_LIST)
62 GCC_VERSION=${GCC_VERSIONS%% *}
65 # Use DEFAULT_LLVM_VERSION to build targets unless we want to build with some particular version
66 if [ -z "$GCC_VERSION_LIST" -a -z "$LLVM_VERSION" ]; then
67 LLVM_VERSION=$DEFAULT_LLVM_VERSION
70 if [ ! -z "$LLVM_VERSION" ]; then
71 BUILD_TOOLCHAIN="--llvm-version=$LLVM_VERSION"
72 elif [ ! -z "$GCC_VERSION" ]; then
73 BUILD_TOOLCHAIN="--gcc-version=$GCC_VERSION"
76 # Check toolchain source path
77 SRC_DIR="$PARAMETERS"
78 check_toolchain_src_dir "$SRC_DIR"
79 SRC_DIR=`cd $SRC_DIR; pwd`
81 # Now we can do the build
82 BUILDTOOLS=$ANDROID_NDK_ROOT/build/tools
84 dump "Building platforms and samples..."
85 PACKAGE_FLAGS=
86 if [ "$PACKAGE_DIR" ]; then
87 PACKAGE_FLAGS="--package-dir=$PACKAGE_DIR"
90 if [ -z "$NO_GEN_PLATFORMS" ]; then
91 echo "Preparing the build..."
92 PLATFORMS_BUILD_TOOLCHAIN=
93 if [ ! -z "$GCC_VERSION" ]; then
94 PLATFORMS_BUILD_TOOLCHAIN="--gcc-version=$GCC_VERSION"
96 run $BUILDTOOLS/gen-platforms.sh --samples --fast-copy --dst-dir=$NDK_DIR --ndk-dir=$NDK_DIR --arch=$(spaces_to_commas $ARCHS) $PACKAGE_FLAGS $PLATFORMS_BUILD_TOOLCHAIN
97 fail_panic "Could not generate platforms and samples directores!"
98 else
99 if [ ! -d "$NDK_DIR/platforms" ]; then
100 echo "ERROR: --no-gen-platforms used but directory missing: $NDK_DIR/platforms"
101 exit 1
105 ARCHS=$(commas_to_spaces $ARCHS)
107 # Detect unknown arch
108 UNKNOWN_ARCH=$(filter_out "$DEFAULT_ARCHS" "$ARCHS")
109 if [ ! -z "$UNKNOWN_ARCH" ]; then
110 ARCHS=$(filter_out "$UNKNOWN_ARCH" "$ARCHS")
113 FLAGS=
114 if [ "$DRYRUN" = "yes" ]; then
115 FLAGS=$FLAGS" --dryrun"
117 if [ "$VERBOSE" = "yes" ]; then
118 FLAGS=$FLAGS" --verbose"
120 if [ "$VERBOSE2" = "yes" ]; then
121 FLAGS=$FLAGS" --verbose"
123 if [ "$PACKAGE_DIR" ]; then
124 mkdir -p "$PACKAGE_DIR"
125 fail_panic "Could not create package directory: $PACKAGE_DIR"
126 FLAGS=$FLAGS" --package-dir=\"$PACKAGE_DIR\""
128 FLAGS=$FLAGS" -j$NUM_JOBS"
130 if [ "$TRY64" = "yes" ]; then
131 FLAGS=$FLAGS" --try-64"
134 # First, gdbserver
135 for ARCH in $ARCHS; do
136 if [ -z "$GCC_VERSION" ]; then
137 GDB_TOOLCHAIN=$(get_default_toolchain_name_for_arch $ARCH)
138 else
139 GDB_TOOLCHAIN=$(get_toolchain_name_for_arch $ARCH $GCC_VERSION)
141 GDB_VERSION="--gdb-version="$(get_default_gdb_version_for_gcc $GDB_TOOLCHAIN)
142 dump "Building $GDB_TOOLCHAIN gdbserver binaries..."
143 run $BUILDTOOLS/build-gdbserver.sh "$SRC_DIR" "$NDK_DIR" "$GDB_TOOLCHAIN" "$GDB_VERSION" $FLAGS
144 fail_panic "Could not build $GDB_TOOLCHAIN gdb-server!"
145 done
147 FLAGS=$FLAGS" --ndk-dir=\"$NDK_DIR\""
148 ABIS=$(convert_archs_to_abis $ARCHS)
149 UNKNOWN_ABIS=$(convert_archs_to_abis $UNKNOWN_ARCH)
151 if [ ! -z "$LLVM_VERSION" ]; then
152 dump "Building $ABIS compiler-rt binaries..."
153 run $BUILDTOOLS/build-compiler-rt.sh --abis="$ABIS" $FLAGS --src-dir="$SRC_DIR/llvm-$LLVM_VERSION/compiler-rt" $BUILD_TOOLCHAIN
154 fail_panic "Could not build compiler-rt!"
157 dump "Building $ABIS gabi++ binaries..."
158 run $BUILDTOOLS/build-cxx-stl.sh --stl=gabi++ --abis="$ABIS" $FLAGS --with-debug-info $BUILD_TOOLCHAIN
159 fail_panic "Could not build gabi++ with debug info!"
161 dump "Building $ABIS $UNKNOWN_ABIS stlport binaries..."
162 run $BUILDTOOLS/build-cxx-stl.sh --stl=stlport --abis="$ABIS,$UNKNOWN_ABIS" $FLAGS --with-debug-info $BUILD_TOOLCHAIN
163 fail_panic "Could not build stlport with debug info!"
165 dump "Building $ABIS libc++ binaries... with libc++abi"
166 run $BUILDTOOLS/build-cxx-stl.sh --stl=libc++-libc++abi --abis="$ABIS" $FLAGS --with-debug-info $BUILD_TOOLCHAIN
167 fail_panic "Could not build libc++ with libc++abi and debug info!"
169 # workaround issues in libc++/libc++abi for x86 and mips
170 for abi in $ABIS; do
171 case $abi in
172 x86|x86_64|mips|mips32r6|mips64)
173 dump "Rebuilding $abi libc++ binaries... with gabi++"
174 run $BUILDTOOLS/build-cxx-stl.sh --stl=libc++-gabi++ --abis=$abi $FLAGS --with-debug-info $BUILD_TOOLCHAIN
175 esac
176 done
178 if [ ! -z $VISIBLE_LIBGNUSTL_STATIC ]; then
179 GNUSTL_STATIC_VIS_FLAG=--visible-libgnustl-static
182 if [ ! -z "$GCC_VERSION_LIST" ]; then
183 STDCXX_GCC_VERSIONS=
184 if [ "$GCC_VERSION_LIST" != "default" ]; then
185 STDCXX_GCC_VERSIONS="--gcc-version-list=$GCC_VERSION_LIST"
187 dump "Building $ABIS gnustl binaries..."
188 run $BUILDTOOLS/build-gnu-libstdc++.sh --abis="$ABIS" $FLAGS $GNUSTL_STATIC_VIS_FLAG "$SRC_DIR" --with-debug-info $STDCXX_GCC_VERSIONS
189 fail_panic "Could not build gnustl with debug info!"
192 dump "Building $ABIS libportable binaries..."
193 run $BUILDTOOLS/build-libportable.sh --abis="$ABIS" $FLAGS $BUILD_TOOLCHAIN
194 fail_panic "Could not build libportable!"
196 if [ "$PACKAGE_DIR" ]; then
197 dump "Done, see $PACKAGE_DIR"
198 else
199 dump "Done"
202 exit 0