1#!/bin/sh 2# 3# Copyright (C) 2009-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# This script is used to package complete Android NDK release packages. 18# 19# You will need prebuilt toolchain binary tarballs or a previous 20# NDK release package to do that. 21# 22# See make-release.sh if you want to make a new release completely from 23# scratch. 24# 25 26. `dirname $0`/prebuilt-common.sh 27 28NDK_ROOT_DIR="$ANDROID_NDK_ROOT" 29 30# the list of platforms / API levels we want to package in 31# this release. This can be overriden with the --platforms 32# option, see below. 33# 34PLATFORMS="$API_LEVELS" 35 36# the default release name (use today's date) 37RELEASE=`date +%Y%m%d` 38register_var_option "--release=<name>" RELEASE "Specify release name" 39 40# the directory containing all prebuilts 41PREBUILT_DIR= 42register_var_option "--prebuilt-dir=<path>" PREBUILT_DIR "Specify prebuilt directory" 43 44# a prebuilt NDK archive (.zip file). empty means don't use any 45PREBUILT_NDK= 46register_var_option "--prebuilt-ndk=<file>" PREBUILT_NDK "Specify prebuilt ndk package" 47 48# the list of supported host development systems 49SYSTEMS=$DEFAULT_SYSTEMS 50register_var_option "--systems=<list>" SYSTEMS "Specify host systems" 51 52# ARCH to build for 53ARCHS=$DEFAULT_ARCHS 54register_var_option "--arch=<arch>" ARCHS "Specify target architecture(s)" 55 56# set to 'yes' if we should use 'git ls-files' to list the files to 57# be copied into the archive. 58NO_GIT=no 59register_var_option "--no-git" NO_GIT "Don't use git to list input files, take all of them." 60 61# set of toolchain prebuilts we need to package 62TOOLCHAINS=$(get_toolchain_name_list_for_arch arm) 63OPTION_TOOLCHAINS=$TOOLCHAINS 64register_var_option "--toolchains=<list>" OPTION_TOOLCHAINS "Specify list of toolchains." 65 66# set of platforms to package (all by default) 67register_var_option "--platforms=<list>" PLATFORMS "Specify API levels" 68 69# the package prefix 70PREFIX=android-ndk 71register_var_option "--prefix=<name>" PREFIX "Specify package prefix" 72 73# default location for generated packages 74OUT_DIR=/tmp/ndk-$USER/release 75OPTION_OUT_DIR= 76register_var_option "--out-dir=<path>" OPTION_OUT_DIR "Specify output package directory" "$OUT_DIR" 77 78# Find the location of the platforms root directory 79DEVELOPMENT_ROOT=`dirname $ANDROID_NDK_ROOT`/development/ndk 80register_var_option "--development-root=<path>" DEVELOPMENT_ROOT "Specify platforms/samples directory" 81 82PROGRAM_PARAMETERS= 83PROGRAM_DESCRIPTION=\ 84"Package a new set of release packages for the Android NDK. 85 86You will need to have generated one or more prebuilt binary tarballs 87with the build/tools/rebuild-all-prebuilts.sh script. These files should 88be named like <toolname>-<system>.tar.bz2, where <toolname> is an arbitrary 89tool name, and <system> is one of: $SYSTEMS 90 91Use the --prebuilt-dir=<path> option to build release packages from the 92binary tarballs stored in <path>. 93 94Alternatively, you can use --prebuilt-ndk=<file> where <file> is the path 95to a previous NDK release package. It will be used to extract the toolchain 96binaries and copy them to your new release. Only use this for experimental 97package releases. 98 99The generated release packages will be stored in a temporary directory that 100will be printed at the end of the generation process. 101" 102 103extract_parameters "$@" 104 105# Ensure that SYSTEMS is space-separated 106SYSTEMS=$(commas_to_spaces $SYSTEMS) 107 108# Do we need to support x86? 109ARCHS=$(commas_to_spaces $ARCHS) 110echo "$ARCHS" | tr ' ' '\n' | grep -q x86 111if [ $? = 0 ] ; then 112 TRY_X86=yes 113else 114 TRY_X86=no 115fi 116# Do we need to support mips? 117echo "$ARCHS" | tr ' ' '\n' | grep -q mips 118if [ $? = 0 ] ; then 119 TRY_mips=yes 120else 121 TRY_mips=no 122fi 123 124# Compute ABIS from ARCHS 125ABIS= 126for ARCH in $ARCHS; do 127 DEFAULT_ABIS=$(get_default_abis_for_arch $ARCH) 128 if [ -z "$ABIS" ]; then 129 ABIS=$DEFAULT_ABIS 130 else 131 ABIS=$ABIS" $DEFAULT_ABIS" 132 fi 133done 134 135# If --arch is used to list x86 as a target architecture, Add x86-4.4.3 to 136# the list of default toolchains to package. That is, unless you also 137# explicitely use --toolchains=<list> 138# 139# Ensure that TOOLCHAINS is space-separated after this. 140# 141if [ "$OPTION_TOOLCHAINS" != "$TOOLCHAINS" ]; then 142 TOOLCHAINS=$(commas_to_spaces $OPTION_TOOLCHAINS) 143else 144 if [ "$TRY_X86" = "yes" ]; then 145 TOOLCHAINS=$TOOLCHAINS" "$(get_toolchain_name_list_for_arch x86) 146 fi 147 if [ "$TRY_mips" = "yes" ]; then 148 TOOLCHAINS=$TOOLCHAINS" "$(get_toolchain_name_list_for_arch mips) 149 fi 150 TOOLCHAINS=$(commas_to_spaces $TOOLCHAINS) 151fi 152 153# Check the prebuilt path 154# 155if [ -n "$PREBUILT_NDK" -a -n "$PREBUILT_DIR" ] ; then 156 echo "ERROR: You cannot use both --prebuilt-ndk and --prebuilt-dir at the same time." 157 exit 1 158fi 159 160if [ -z "$PREBUILT_DIR" -a -z "$PREBUILT_NDK" ] ; then 161 echo "ERROR: You must use one of --prebuilt-dir or --prebuilt-ndk. See --help for details." 162 exit 1 163fi 164 165# Check the option directory. 166if [ -n "$OPTION_OUT_DIR" ] ; then 167 OUT_DIR="$OPTION_OUT_DIR" 168 mkdir -p $OUT_DIR 169 if [ $? != 0 ] ; then 170 echo "ERROR: Could not create output directory: $OUT_DIR" 171 exit 1 172 fi 173else 174 rm -rf $OUT_DIR && mkdir -p $OUT_DIR 175fi 176 177# Handle the prebuilt binaries now 178# 179if [ -n "$PREBUILT_DIR" ] ; then 180 if [ ! -d "$PREBUILT_DIR" ] ; then 181 echo "ERROR: the --prebuilt-dir argument is not a directory: $PREBUILT_DIR" 182 exit 1 183 fi 184 if [ -z "$SYSTEMS" ] ; then 185 echo "ERROR: Your systems list is empty, use --systems=LIST to specify a different one." 186 exit 1 187 fi 188 # Check the toolchain prebuilts 189 # 190 for TC in $TOOLCHAINS; do 191 for SYS in $SYSTEMS; do 192 if [ ! -f "$PREBUILT_DIR/$TC-$SYS.tar.bz2" ] ; then 193 echo "ERROR: Missing prebuilt file $TC-$SYS.tar.bz2 in: $PREBUILT_DIR" 194 exit 1 195 fi 196 done 197 if [ ! -f "$PREBUILT_DIR/$TC-gdbserver.tar.bz2" ] ; then 198 echo "ERROR: Missing prebuilt file $TC-gdbserver.tar.bz2 in: $PREBUILT_DIR" 199 exit 1 200 fi 201 done 202else 203 if [ ! -f "$PREBUILT_NDK" ] ; then 204 echo "ERROR: the --prebuilt-ndk argument is not a file: $PREBUILT_NDK" 205 exit 1 206 fi 207 # Check that the name ends with the proper host tag 208 HOST_NDK_SUFFIX="$HOST_TAG.zip" 209 echo "$PREBUILT_NDK" | grep -q "$HOST_NDK_SUFFIX" 210 fail_panic "The name of the prebuilt NDK must end in $HOST_NDK_SUFFIX" 211 SYSTEMS=$HOST_TAG 212fi 213 214echo "Architectures: $ARCHS" 215echo "CPU ABIs: $ABIS" 216echo "Toolchains: $TOOLCHAINS" 217echo "Host systems: $SYSTEMS" 218 219 220# The list of git files to copy into the archives 221if [ "$NO_GIT" != "yes" ] ; then 222 echo "Collecting sources from git (use --no-git to copy all files instead)." 223 GIT_FILES=`cd $NDK_ROOT_DIR && git ls-files` 224else 225 echo "Collecting all sources files under tree." 226 # Cleanup everything that is likely to not be part of the final NDK 227 # i.e. generated files... 228 rm -rf $NDK_ROOT_DIR/samples/*/obj 229 rm -rf $NDK_ROOT_DIR/samples/*/libs 230 # Get all files under the NDK root 231 GIT_FILES=`cd $NDK_ROOT_DIR && find .` 232 GIT_FILES=`echo $GIT_FILES | sed -e "s!\./!!g"` 233fi 234 235# temporary directory used for packaging 236TMPDIR=$NDK_TMPDIR 237 238RELEASE_PREFIX=$PREFIX-$RELEASE 239 240# ensure that the generated files are ug+rx 241umask 0022 242 243# Unpack a prebuilt into the destination directory ($DSTDIR) 244# $1: prebuilt name, relative to $PREBUILT_DIR 245# $2: optional, destination directory 246unpack_prebuilt () 247{ 248 local PREBUILT=$1 249 local DDIR="${2:-$DSTDIR}" 250 echo "Unpacking $PREBUILT" 251 if [ -f "$PREBUILT_DIR/$PREBUILT" ] ; then 252 unpack_archive "$PREBUILT_DIR/$PREBUILT" "$DDIR" 253 fail_panic "Could not unpack prebuilt $PREBUILT. Aborting." 254 else 255 echo "WARNING: Could not find $PREBUILT in $PREBUILT_DIR" 256 fi 257} 258 259# Copy a prebuilt directory from the previous 260# $1: Source directory relative to 261copy_prebuilt () 262{ 263 local SUBDIR="$1" 264 if [ -d "$1" ] ; then 265 echo "Copying: $SUBDIR" 266 copy_directory "$SUBDIR" "$DSTDIR/$2" 267 else 268 echo "Ignored: $SUBDIR" 269 fi 270} 271 272 273rm -rf $TMPDIR && mkdir -p $TMPDIR 274 275# Unpack the previous NDK package if any 276if [ -n "$PREBUILT_NDK" ] ; then 277 echo "Unpacking prebuilt toolchains from $PREBUILT_NDK" 278 UNZIP_DIR=$TMPDIR/prev-ndk 279 rm -rf $UNZIP_DIR && mkdir -p $UNZIP_DIR 280 fail_panic "Could not create temporary directory: $UNZIP_DIR" 281 unpack_archive "$PREBUILT_NDK" "$UNZIP_DIR" 282 fail_panic "Could not unzip NDK package $PREBUILT_NDK" 283fi 284 285# first create the reference ndk directory from the git reference 286echo "Creating reference from source files" 287REFERENCE=$TMPDIR/reference && rm -rf $REFERENCE/* && 288copy_file_list "$NDK_ROOT_DIR" "$REFERENCE" $GIT_FILES && 289rm -f $REFERENCE/Android.mk 290fail_panic "Could not create reference. Aborting." 291 292# Copy platform and sample files 293if [ "$PREBUILT_DIR" ]; then 294 echo "Unpacking platform files" && 295 unpack_archive "$PREBUILT_DIR/platforms.tar.bz2" "$REFERENCE" && 296 echo "Unpacking samples files" && 297 unpack_archive "$PREBUILT_DIR/samples.tar.bz2" "$REFERENCE" 298 fail_panic "Could not unpack platform and sample files" 299elif [ "$PREBUILT_NDK" ]; then 300 echo "ERROR: NOT IMPLEMENTED!" 301 exit 1 302else 303 # copy platform and sample files 304 echo "Copying platform and sample files" 305 FLAGS="--src-dir=$DEVELOPMENT_ROOT --dst-dir=$REFERENCE" 306 if [ "$VERBOSE2" = "yes" ] ; then 307 FLAGS="$FLAGS --verbose" 308 fi 309 310 FLAGS="$FLAGS --platform=$(spaces_to_commas $PLATFORMS)" 311 FLAGS="$FLAGS --arch=$(spaces_to_commas $ARCHS)" 312 $NDK_ROOT_DIR/build/tools/gen-platforms.sh $FLAGS 313 fail_panic "Could not copy platform files. Aborting." 314fi 315 316# Remove the source for host tools to make the final package smaller 317rm -rf $REFERENCE/sources/host-tools 318 319# Remove leftovers, just in case... 320rm -rf $REFERENCE/samples/*/{obj,libs,build.xml,local.properties,Android.mk} && 321rm -rf $REFERENCE/tests/build/*/{obj,libs} && 322rm -rf $REFERENCE/tests/device/*/{obj,libs} 323 324# copy sources files 325if [ -d $DEVELOPMENT_ROOT/sources ] ; then 326 echo "Copying NDK sources files" 327 copy_file_list "$DEVELOPMENT_ROOT" "$REFERENCE" "sources" 328 fail_panic "Could not copy sources. Aborting." 329fi 330 331# Unpack prebuilt C++ runtimes headers and libraries 332if [ -z "$PREBUILT_NDK" ]; then 333 # Unpack gdbserver 334 for TC in $TOOLCHAINS; do 335 unpack_prebuilt $TC-gdbserver.tar.bz2 "$REFERENCE" 336 done 337 # Unpack C++ runtimes 338 unpack_prebuilt gnu-libstdc++-headers.tar.bz2 "$REFERENCE" 339 for ABI in $ABIS; do 340 unpack_prebuilt gabixx-libs-$ABI.tar.bz2 "$REFERENCE" 341 unpack_prebuilt stlport-libs-$ABI.tar.bz2 "$REFERENCE" 342 unpack_prebuilt gnu-libstdc++-libs-$ABI.tar.bz2 "$REFERENCE" 343 done 344fi 345 346# create a release file named 'RELEASE.TXT' containing the release 347# name. This is used by the build script to detect whether you're 348# invoking the NDK from a release package or from the development 349# tree. 350# 351echo "$RELEASE" > $REFERENCE/RELEASE.TXT 352 353# Remove un-needed files 354rm -f $REFERENCE/CleanSpec.mk 355 356# now, for each system, create a package 357# 358for SYSTEM in $SYSTEMS; do 359 echo "Preparing package for system $SYSTEM." 360 BIN_RELEASE=$RELEASE_PREFIX-$SYSTEM 361 DSTDIR=$TMPDIR/$RELEASE_PREFIX 362 rm -rf $DSTDIR && 363 copy_directory "$REFERENCE" "$DSTDIR" 364 fail_panic "Could not copy reference. Aborting." 365 366 if [ "$PREBUILT_NDK" ]; then 367 cd $UNZIP_DIR/android-ndk-* && cp -rP toolchains/* $DSTDIR/toolchains/ 368 fail_panic "Could not copy toolchain files from $PREBUILT_NDK" 369 370 if [ -d "$DSTDIR/$GABIXX_SUBDIR" ]; then 371 GABIXX_ABIS=$PREBUILT_ABIS 372 for GABIXX_ABI in $GABIXX_ABIS; do 373 copy_prebuilt "$GABIXX_SUBDIR/libs/$GABIXX_ABI" "$GABIXX_SUBDIR/libs" 374 done 375 else 376 echo "WARNING: Could not find GAbi++ source tree!" 377 fi 378 379 if [ -d "$DSTDIR/$STLPORT_SUBDIR" ] ; then 380 STLPORT_ABIS=$PREBUILT_ABIS 381 for STL_ABI in $STLPORT_ABIS; do 382 copy_prebuilt "$STLPORT_SUBDIR/libs/$STL_ABI" "$STLPORT_SUBDIR/libs" 383 done 384 else 385 echo "WARNING: Could not find STLport source tree!" 386 fi 387 388 copy_prebuilt "$GNUSTL_SUBDIR/include" "$GNUSTL_SUBDIR" 389 for STL_ABI in $PREBUILT_ABIS; do 390 copy_prebuilt "$GNUSTL_SUBDIR/libs/$STL_ABI" "$GNUSTL_SUBDIR/libs" 391 done 392 else 393 # Unpack gdbserver 394 for TC in $TOOLCHAINS; do 395 unpack_prebuilt $TC-$SYSTEM.tar.bz2 396 echo "Removing sysroot for $TC" 397 rm -rf $DSTDIR/toolchains/$TC/prebuilt/$SYSTEM/sysroot 398 done 399 400 # Unpack prebuilt ndk-stack and other host tools 401 unpack_prebuilt ndk-stack-$SYSTEM.tar.bz2 402 unpack_prebuilt ndk-make-$SYSTEM.tar.bz2 403 unpack_prebuilt ndk-sed-$SYSTEM.tar.bz2 404 unpack_prebuilt ndk-awk-$SYSTEM.tar.bz2 405 406 if [ "$SYSTEM" = "windows" ]; then 407 unpack_prebuilt toolbox-$SYSTEM.tar.bz2 408 fi 409 fi 410 411 # Create an archive for the final package. Extension depends on the 412 # host system. 413 case "$SYSTEM" in 414 windows) 415 ARCHIVE="$BIN_RELEASE.zip" 416 ;; 417 *) 418 ARCHIVE="$BIN_RELEASE.tar.bz2" 419 ;; 420 esac 421 echo "Creating $ARCHIVE" 422 pack_archive "$OUT_DIR/$ARCHIVE" "$TMPDIR" "$RELEASE_PREFIX" 423 fail_panic "Could not create archive: $OUT_DIR/$ARCHIVE" 424# chmod a+r $TMPDIR/$ARCHIVE 425done 426 427echo "Cleaning up." 428rm -rf $TMPDIR/reference 429rm -rf $TMPDIR/prev-ndk 430 431echo "Done, please see packages in $OUT_DIR:" 432ls -l $OUT_DIR 433