1 #!/bin/sh 2 # 3 # Copyright (C) 2010 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 18 # Download and rebuild all prebuilt binaries for the Android NDK 19 # This includes: 20 # - cross toolchains (gcc, ld, gdb, etc...) 21 # - target-specific gdbserver 22 # - host ccache 23 # 24 25 . `dirname $0`/prebuilt-common.sh 26 PROGDIR=`dirname $0` 27 28 prepare_host_flags 29 30 NDK_DIR= 31 register_var_option "--ndk-dir=<path>" NDK_DIR "Don't package, copy binaries to target NDK directory" 32 33 BUILD_DIR=`random_temp_directory` 34 register_var_option "--build-dir=<path>" BUILD_DIR "Specify temporary build directory" "/tmp/<random>" 35 36 GDB_VERSION=6.6 37 register_var_option "--gdb-version=<version>" GDB_VERSION "Specify gdb version" 38 39 OPTION_TOOLCHAIN_SRC_PKG= 40 register_var_option "--toolchain-src-pkg=<file>" OPTION_TOOLCHAIN_SRC_PKG "Use toolchain source package." 41 42 OPTION_TOOLCHAIN_SRC_DIR= 43 register_var_option "--toolchain-src-dir=<path>" OPTION_TOOLCHAIN_SRC_DIR "Use toolchain source directory." 44 45 RELEASE=`date +%Y%m%d` 46 PACKAGE_DIR=/tmp/ndk-prebuilt/prebuilt-$RELEASE 47 register_var_option "--package-dir=<path>" PACKAGE_DIR "Put prebuilt tarballs into <path>." 48 49 OPTION_TRY_X86=no 50 register_var_option "--try-x86" OPTION_TRY_X86 "Build experimental x86 toolchain too." 51 52 OPTION_GIT_HTTP=no 53 register_var_option "--git-http" OPTION_GIT_HTTP "Download sources with http." 54 55 register_mingw_option 56 57 PROGRAM_PARAMETERS= 58 PROGRAM_DESCRIPTION=\ 59 "Download and rebuild from scratch all prebuilt binaries for the Android NDK. 60 By default, this will create prebuilt binary tarballs in: $PACKAGE_DIR 61 62 You can however use --ndk-dir=<path> to instead copy the binaries directly 63 to an existing NDK installation. 64 65 By default, the script will download the toolchain sources from the Internet, 66 but you can override this using either --toolchain-src-dir or 67 --toolchain-src-pkg. 68 69 Please read docs/DEVELOPMENT.TXT for more usage information about this 70 script. 71 " 72 73 extract_parameters $@ 74 75 if [ -n "$PACKAGE_DIR" -a -n "$NDK_DIR" ] ; then 76 echo "ERROR: You cannot use both --package-dir and --ndk-dir at the same time!" 77 exit 1 78 fi 79 80 if [ -z "$NDK_DIR" ] ; then 81 mkdir -p "$PACKAGE_DIR" 82 if [ $? != 0 ] ; then 83 echo "ERROR: Could not create directory: $PACKAGE_DIR" 84 exit 1 85 fi 86 NDK_DIR=/tmp/ndk-toolchain/ndk-prebuilt-$$ 87 mkdir -p $NDK_DIR 88 else 89 if [ ! -d "$NDK_DIR" ] ; then 90 echo "ERROR: NDK directory does not exists: $NDK_DIR" 91 exit 1 92 fi 93 PACKAGE_DIR= 94 fi 95 96 if [ -n "$PARAMETERS" ]; then 97 dump "ERROR: Too many parameters. See --help for proper usage." 98 exit 1 99 fi 100 101 mkdir -p $BUILD_DIR 102 if [ $? != 0 ] ; then 103 dump "ERROR: Could not create build directory: $BUILD_DIR" 104 exit 1 105 fi 106 setup_default_log_file "$BUILD_DIR/log.txt" 107 108 if [ -n "$OPTION_TOOLCHAIN_SRC_DIR" ] ; then 109 if [ -n "$OPTION_TOOLCHAIN_SRC_PKG" ] ; then 110 dump "ERROR: You can't use both --toolchain-src-dir and --toolchain-src-pkg" 111 exi t1 112 fi 113 SRC_DIR="$OPTION_TOOLCHAIN_SRC_DIR" 114 if [ ! -d "$SRC_DIR/gcc" ] ; then 115 dump "ERROR: Invalid toolchain source directory: $SRC_DIR" 116 exit 1 117 fi 118 else 119 SRC_DIR="$BUILD_DIR/src" 120 mkdir -p "$SRC_DIR" 121 fi 122 123 FLAGS="" 124 if [ $VERBOSE = yes ] ; then 125 FLAGS="--verbose" 126 fi 127 128 if [ -z "$OPTION_TOOLCHAIN_SRC_DIR" ] ; then 129 if [ -n "$OPTION_TOOLCHAIN_SRC_PKG" ] ; then 130 # Unpack the toolchain sources 131 if [ ! -f "$OPTION_TOOLCHAIN_SRC_PKG" ] ; then 132 dump "ERROR: Invalid toolchain source package: $OPTION_TOOLCHAIN_SRC_PKG" 133 exit 1 134 fi 135 TARFLAGS="xf" 136 if [ $VERBOSE2 = yes ] ; then 137 TARFLAGS="v$TARFLAGS" 138 fi 139 if pattern_match '\.tar\.gz$' "$OPTION_TOOLCHAIN_SRC_PKG"; then 140 TARFLAGS="z$TARFLAGS" 141 fi 142 if pattern_match '\.tar\.bz2$' "$OPTION_TOOLCHAIN_SRC_PKG"; then 143 TARFLAGS="j$TARFLAGS" 144 fi 145 dump "Unpack sources from $OPTION_TOOLCHAIN_SRC_PKG" 146 mkdir -p $SRC_DIR && tar $TARFLAGS $OPTION_TOOLCHAIN_SRC_PKG -C $SRC_DIR 147 if [ $? != 0 ] ; then 148 dump "ERROR: Could not unpack toolchain sources!" 149 exit 1 150 fi 151 else 152 # Download the toolchain sources 153 dump "Download sources from android.git.kernel.org" 154 DOWNLOAD_FLAGS="$FLAGS" 155 if [ $OPTION_GIT_HTTP = "yes" ] ; then 156 DOWNLOAD_FLAGS="$DOWNLOAD_FLAGS --git-http" 157 fi 158 $PROGDIR/download-toolchain-sources.sh $DOWNLOAD_FLAGS $SRC_DIR 159 if [ $? != 0 ] ; then 160 dump "ERROR: Could not download toolchain sources!" 161 exit 1 162 fi 163 fi 164 fi # ! $TOOLCHAIN_SRC_DIR 165 166 if [ "$MINGW" = yes ] ; then 167 FLAGS="$FLAGS --mingw" 168 fi 169 170 # Needed to set HOST_TAG to windows if --mingw is used. 171 prepare_host_flags 172 173 # Package a directory in a .tar.bz2 archive 174 # 175 # $1: textual description 176 # $2: final package name (without .tar.bz2 suffix) 177 # $3: relative root path from $NDK_DIR 178 # 179 package_it () 180 { 181 if [ -n "$PACKAGE_DIR" ] ; then 182 dump "Packaging $1 ($2.tar.bz2) ..." 183 PREBUILT_PACKAGE="$PACKAGE_DIR/$2".tar.bz2 184 (cd $NDK_DIR && tar cjf $PREBUILT_PACKAGE "$3") 185 if [ $? != 0 ] ; then 186 dump "ERROR: Could not package $1!" 187 exit 1 188 fi 189 fi 190 } 191 192 # Build the toolchain from sources 193 build_toolchain () 194 { 195 dump "Building $1 toolchain... (this can be long)" 196 run $PROGDIR/build-gcc.sh $FLAGS --build-out=$BUILD_DIR/toolchain-$1 $SRC_DIR $NDK_DIR $1 197 if [ $? != 0 ] ; then 198 dump "ERROR: Could not build $1 toolchain!" 199 exit 1 200 fi 201 package_it "$1 toolchain" "$1-$HOST_TAG" "toolchains/$1/prebuilt/$HOST_TAG" 202 } 203 204 build_gdbserver () 205 { 206 if [ "$MINGW" = yes ] ; then 207 dump "Skipping gdbserver build (--mingw option being used)." 208 return 209 fi 210 dump "Build $1 gdbserver..." 211 $PROGDIR/build-gdbserver.sh $FLAGS --build-out=$BUILD_DIR/gdbserver-$1 $SRC_DIR/gdb/gdb-$GDB_VERSION/gdb/gdbserver $NDK_DIR $1 212 if [ $? != 0 ] ; then 213 dump "ERROR: Could not build $1 toolchain!" 214 exit 1 215 fi 216 package_it "$1 gdbserver" "$1-gdbserver" "toolchains/$1/prebuilt/gdbserver" 217 } 218 219 build_toolchain arm-eabi-4.4.0 220 build_gdbserver arm-eabi-4.4.0 221 222 build_toolchain arm-linux-androideabi-4.4.3 223 build_gdbserver arm-linux-androideabi-4.4.3 224 225 if [ "$OPTION_TRY_X86" = "yes" ] ; then 226 build_toolchain x86-4.2.1 227 build_gdbserver x86-4.2.1 228 fi 229 230 # XXX: NOT YET NEEDED! 231 # 232 #dump "Building host ccache binary..." 233 #$PROGDIR/build-ccache.sh $FLAGS --build-out=$BUILD_DIR/ccache $NDK_DIR 234 #if [ $? != 0 ] ; then 235 # dump "ERROR: Could not build host ccache binary!" 236 # exit 1 237 #fi 238 239 if [ -n "$PACKAGE_DIR" ] ; then 240 dump "Done! See $PACKAGE_DIR" 241 else 242 dump "Done! See $NDK_DIR/toolchains" 243 fi 244