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 82LLVM_VERSION_LIST=$DEFAULT_LLVM_VERSION_LIST 83register_var_option "--llvm=<versions>" LLVM_VERSION_LIST "List of LLVM release versions" 84 85register_try64_option 86 87SEPARATE_64=no 88register_option "--separate-64" do_SEPARATE_64 "Separate 64-bit host toolchain to its own package" 89do_SEPARATE_64 () 90{ 91 if [ "$TRY64" = "yes" ]; then 92 echo "ERROR: You cannot use both --try-64 and --separate-64 at the same time." 93 exit 1 94 fi 95 SEPARATE_64=yes; 96} 97 98PROGRAM_PARAMETERS= 99PROGRAM_DESCRIPTION=\ 100"Package a new set of release packages for the Android NDK. 101 102You will need to have generated one or more prebuilt binary tarballs 103with the build/tools/rebuild-all-prebuilts.sh script. These files should 104be named like <toolname>-<system>.tar.bz2, where <toolname> is an arbitrary 105tool name, and <system> is one of: $SYSTEMS 106 107Use the --prebuilt-dir=<path> option to build release packages from the 108binary tarballs stored in <path>. 109 110Alternatively, you can use --prebuilt-ndk=<file> where <file> is the path 111to a previous NDK release package. It will be used to extract the toolchain 112binaries and copy them to your new release. Only use this for experimental 113package releases. 114 115The generated release packages will be stored in a temporary directory that 116will be printed at the end of the generation process. 117" 118 119extract_parameters "$@" 120 121# Ensure that SYSTEMS is space-separated 122SYSTEMS=$(commas_to_spaces $SYSTEMS) 123 124# Do we need to support x86? 125ARCHS=$(commas_to_spaces $ARCHS) 126echo "$ARCHS" | tr ' ' '\n' | grep -q x86 127if [ $? = 0 ] ; then 128 TRY_X86=yes 129else 130 TRY_X86=no 131fi 132# Do we need to support mips? 133echo "$ARCHS" | tr ' ' '\n' | grep -q mips 134if [ $? = 0 ] ; then 135 TRY_mips=yes 136else 137 TRY_mips=no 138fi 139 140# Compute ABIS from ARCHS 141ABIS= 142for ARCH in $ARCHS; do 143 DEFAULT_ABIS=$(get_default_abis_for_arch $ARCH) 144 if [ -z "$ABIS" ]; then 145 ABIS=$DEFAULT_ABIS 146 else 147 ABIS=$ABIS" $DEFAULT_ABIS" 148 fi 149done 150 151# Convert comma-separated list to space-separated list 152LLVM_VERSION_LIST=$(commas_to_spaces $LLVM_VERSION_LIST) 153 154# If --arch is used to list x86 as a target architecture, Add x86-4.4.3 to 155# the list of default toolchains to package. That is, unless you also 156# explicitely use --toolchains=<list> 157# 158# Ensure that TOOLCHAINS is space-separated after this. 159# 160if [ "$OPTION_TOOLCHAINS" != "$TOOLCHAINS" ]; then 161 TOOLCHAINS=$(commas_to_spaces $OPTION_TOOLCHAINS) 162else 163 if [ "$TRY_X86" = "yes" ]; then 164 TOOLCHAINS=$TOOLCHAINS" "$(get_toolchain_name_list_for_arch x86) 165 fi 166 if [ "$TRY_mips" = "yes" ]; then 167 TOOLCHAINS=$TOOLCHAINS" "$(get_toolchain_name_list_for_arch mips) 168 fi 169 TOOLCHAINS=$(commas_to_spaces $TOOLCHAINS) 170fi 171 172# Check the prebuilt path 173# 174if [ -n "$PREBUILT_NDK" -a -n "$PREBUILT_DIR" ] ; then 175 echo "ERROR: You cannot use both --prebuilt-ndk and --prebuilt-dir at the same time." 176 exit 1 177fi 178 179if [ -z "$PREBUILT_DIR" -a -z "$PREBUILT_NDK" ] ; then 180 echo "ERROR: You must use one of --prebuilt-dir or --prebuilt-ndk. See --help for details." 181 exit 1 182fi 183 184# Check the option directory. 185if [ -n "$OPTION_OUT_DIR" ] ; then 186 OUT_DIR="$OPTION_OUT_DIR" 187 mkdir -p $OUT_DIR 188 if [ $? != 0 ] ; then 189 echo "ERROR: Could not create output directory: $OUT_DIR" 190 exit 1 191 fi 192else 193 rm -rf $OUT_DIR && mkdir -p $OUT_DIR 194fi 195 196# Handle the prebuilt binaries now 197# 198if [ -n "$PREBUILT_DIR" ] ; then 199 if [ ! -d "$PREBUILT_DIR" ] ; then 200 echo "ERROR: the --prebuilt-dir argument is not a directory: $PREBUILT_DIR" 201 exit 1 202 fi 203 if [ -z "$SYSTEMS" ] ; then 204 echo "ERROR: Your systems list is empty, use --systems=LIST to specify a different one." 205 exit 1 206 fi 207 # Check the toolchain prebuilts 208 # 209 for TC in $TOOLCHAINS; do 210 for SYS in $SYSTEMS; do 211 if [ ! -f "$PREBUILT_DIR/$TC-$SYS.tar.bz2" ] ; then 212 echo "ERROR: Missing prebuilt file $TC-$SYS.tar.bz2 in: $PREBUILT_DIR" 213 exit 1 214 fi 215 done 216 done 217 for ARCH in $ARCHS; do 218 if [ ! -f "$PREBUILT_DIR/$ARCH-gdbserver.tar.bz2" ] ; then 219 echo "ERROR: Missing prebuilt file $ARCH-gdbserver.tar.bz2 in: $PREBUILT_DIR" 220 exit 1 221 fi 222 done 223else 224 if [ ! -f "$PREBUILT_NDK" ] ; then 225 echo "ERROR: the --prebuilt-ndk argument is not a file: $PREBUILT_NDK" 226 exit 1 227 fi 228 # Check that the name ends with the proper host tag 229 HOST_NDK_SUFFIX="$HOST_TAG.zip" 230 echo "$PREBUILT_NDK" | grep -q "$HOST_NDK_SUFFIX" 231 fail_panic "The name of the prebuilt NDK must end in $HOST_NDK_SUFFIX" 232 SYSTEMS=$HOST_TAG 233fi 234 235echo "Architectures: $ARCHS" 236echo "CPU ABIs: $ABIS" 237echo "Toolchains: $TOOLCHAINS" 238echo "Host systems: $SYSTEMS" 239 240 241# The list of git files to copy into the archives 242if [ "$NO_GIT" != "yes" ] ; then 243 echo "Collecting sources from git (use --no-git to copy all files instead)." 244 GIT_FILES=`cd $NDK_ROOT_DIR && git ls-files` 245else 246 echo "Collecting all sources files under tree." 247 # Cleanup everything that is likely to not be part of the final NDK 248 # i.e. generated files... 249 rm -rf $NDK_ROOT_DIR/samples/*/obj 250 rm -rf $NDK_ROOT_DIR/samples/*/libs 251 # Get all files under the NDK root 252 GIT_FILES=`cd $NDK_ROOT_DIR && find .` 253 GIT_FILES=`echo $GIT_FILES | sed -e "s!\./!!g"` 254fi 255 256# temporary directory used for packaging 257TMPDIR=$NDK_TMPDIR 258 259RELEASE_PREFIX=$PREFIX-$RELEASE 260 261# ensure that the generated files are ug+rx 262umask 0022 263 264# Translate name to 64-bit's counterpart 265# $1: prebuilt name 266name64 () 267{ 268 local NAME=$1 269 case $NAME in 270 *windows) 271 NAME=${NAME}-x86_64 272 ;; 273 *linux-x86|*darwin-x86) 274 NAME=${NAME}_64 275 ;; 276 esac 277 echo $NAME 278} 279 280# Unpack a prebuilt into specified destination directory 281# $1: prebuilt name, relative to $PREBUILT_DIR 282# $2: destination directory 283# $3: optional destination directory for 64-bit toolchain 284# $4: optional flag to use 32-bit prebuilt in place of 64-bit 285unpack_prebuilt () 286{ 287 local PREBUILT= 288 local PREBUILT64=null 289 local DDIR="$2" 290 local DDIR64="${3:-$DDIR}" 291 local USE32="${4:-no}" 292 293 if [ "$TRY64" = "yes" -a "$USE32" = "no" ]; then 294 PREBUILT=`name64 $1` 295 else 296 PREBUILT=$1 297 PREBUILT64=`name64 $1` 298 fi 299 300 PREBUILT=${PREBUILT}.tar.bz2 301 PREBUILT64=${PREBUILT64}.tar.bz2 302 303 echo "Unpacking $PREBUILT" 304 if [ -f "$PREBUILT_DIR/$PREBUILT" ] ; then 305 unpack_archive "$PREBUILT_DIR/$PREBUILT" "$DDIR" 306 fail_panic "Could not unpack prebuilt $PREBUILT. Aborting." 307 if [ -f "$PREBUILT_DIR/$PREBUILT64" ] ; then 308 echo "Unpacking $PREBUILT64" 309 unpack_archive "$PREBUILT_DIR/$PREBUILT64" "$DDIR64" 310 fail_panic "Could not unpack prebuilt $PREBUILT64. Aborting." 311 fi 312 else 313 echo "WARNING: Could not find $PREBUILT in $PREBUILT_DIR" 314 fi 315} 316 317# Copy a prebuilt directory from the previous 318# $1: Source directory relative to 319copy_prebuilt () 320{ 321 local SUBDIR="$1" 322 if [ -d "$1" ] ; then 323 echo "Copying: $SUBDIR" 324 copy_directory "$SUBDIR" "$DSTDIR/$2" 325 else 326 echo "Ignored: $SUBDIR" 327 fi 328} 329 330 331rm -rf $TMPDIR && mkdir -p $TMPDIR 332 333# Unpack the previous NDK package if any 334if [ -n "$PREBUILT_NDK" ] ; then 335 echo "Unpacking prebuilt toolchains from $PREBUILT_NDK" 336 UNZIP_DIR=$TMPDIR/prev-ndk 337 rm -rf $UNZIP_DIR && mkdir -p $UNZIP_DIR 338 fail_panic "Could not create temporary directory: $UNZIP_DIR" 339 unpack_archive "$PREBUILT_NDK" "$UNZIP_DIR" 340 fail_panic "Could not unzip NDK package $PREBUILT_NDK" 341fi 342 343# first create the reference ndk directory from the git reference 344echo "Creating reference from source files" 345REFERENCE=$TMPDIR/reference && rm -rf $REFERENCE/* && 346copy_file_list "$NDK_ROOT_DIR" "$REFERENCE" $GIT_FILES && 347rm -f $REFERENCE/Android.mk 348fail_panic "Could not create reference. Aborting." 349 350# Copy platform and sample files 351if [ "$PREBUILT_DIR" ]; then 352 echo "Unpacking platform files" && 353 unpack_archive "$PREBUILT_DIR/platforms.tar.bz2" "$REFERENCE" && 354 echo "Unpacking samples files" && 355 unpack_archive "$PREBUILT_DIR/samples.tar.bz2" "$REFERENCE" 356 fail_panic "Could not unpack platform and sample files" 357elif [ "$PREBUILT_NDK" ]; then 358 echo "ERROR: NOT IMPLEMENTED!" 359 exit 1 360else 361 # copy platform and sample files 362 echo "Copying platform and sample files" 363 FLAGS="--src-dir=$DEVELOPMENT_ROOT --dst-dir=$REFERENCE" 364 if [ "$VERBOSE2" = "yes" ] ; then 365 FLAGS="$FLAGS --verbose" 366 fi 367 368 FLAGS="$FLAGS --platform=$(spaces_to_commas $PLATFORMS)" 369 FLAGS="$FLAGS --arch=$(spaces_to_commas $ARCHS)" 370 $NDK_ROOT_DIR/build/tools/gen-platforms.sh $FLAGS 371 fail_panic "Could not copy platform files. Aborting." 372fi 373 374# Remove the source for host tools to make the final package smaller 375rm -rf $REFERENCE/sources/host-tools 376 377# Remove leftovers, just in case... 378rm -rf $REFERENCE/samples/*/{obj,libs,build.xml,local.properties,Android.mk} && 379rm -rf $REFERENCE/tests/build/*/{obj,libs} && 380rm -rf $REFERENCE/tests/device/*/{obj,libs} 381 382# Remove the libc++ sources, they're not ready for release. 383# http://b.android.com/36496 384rm -rf $REFERENCE/sources/cxx-stl/llvm-libc++ 385 386# copy sources files 387if [ -d $DEVELOPMENT_ROOT/sources ] ; then 388 echo "Copying NDK sources files" 389 copy_file_list "$DEVELOPMENT_ROOT" "$REFERENCE" "sources" 390 fail_panic "Could not copy sources. Aborting." 391fi 392 393# Unpack prebuilt C++ runtimes headers and libraries 394if [ -z "$PREBUILT_NDK" ]; then 395 # Unpack gdbserver 396 for ARCH in $ARCHS; do 397 unpack_prebuilt $ARCH-gdbserver "$REFERENCE" 398 done 399 # Unpack C++ runtimes 400 for VERSION in $DEFAULT_GCC_VERSION_LIST; do 401 unpack_prebuilt gnu-libstdc++-headers-$VERSION "$REFERENCE" 402 done 403 for ABI in $ABIS; do 404 unpack_prebuilt gabixx-libs-$ABI "$REFERENCE" 405 unpack_prebuilt stlport-libs-$ABI "$REFERENCE" 406 for VERSION in $DEFAULT_GCC_VERSION_LIST; do 407 unpack_prebuilt gnu-libstdc++-libs-$VERSION-$ABI "$REFERENCE" 408 done 409 unpack_prebuilt libportable-libs-$ABI "$REFERENCE" 410 done 411fi 412 413# create a release file named 'RELEASE.TXT' containing the release 414# name. This is used by the build script to detect whether you're 415# invoking the NDK from a release package or from the development 416# tree. 417# 418if [ "$TRY64" = "yes" ]; then 419 echo "$RELEASE (64-bit)" > $REFERENCE/RELEASE.TXT 420else 421 echo "$RELEASE" > $REFERENCE/RELEASE.TXT 422fi 423 424# Remove un-needed files 425rm -f $REFERENCE/CleanSpec.mk 426 427# now, for each system, create a package 428# 429DSTDIR=$TMPDIR/$RELEASE_PREFIX 430DSTDIR64=${DSTDIR} 431if [ "$SEPARATE_64" = "yes" ] ; then 432 DSTDIR64=$TMPDIR/64/${RELEASE_PREFIX} 433fi 434 435for SYSTEM in $SYSTEMS; do 436 echo "Preparing package for system $SYSTEM." 437 BIN_RELEASE=$RELEASE_PREFIX-$SYSTEM 438 rm -rf "$DSTDIR" "$DSTDIR64" && 439 mkdir -p "$DSTDIR" "$DSTDIR64" && 440 copy_directory "$REFERENCE" "$DSTDIR" 441 fail_panic "Could not copy reference. Aborting." 442 443 if [ "$PREBUILT_NDK" ]; then 444 cd $UNZIP_DIR/android-ndk-* && cp -rP toolchains/* $DSTDIR/toolchains/ 445 fail_panic "Could not copy toolchain files from $PREBUILT_NDK" 446 447 if [ -d "$DSTDIR/$GABIXX_SUBDIR" ]; then 448 GABIXX_ABIS=$PREBUILT_ABIS 449 for GABIXX_ABI in $GABIXX_ABIS; do 450 copy_prebuilt "$GABIXX_SUBDIR/libs/$GABIXX_ABI" "$GABIXX_SUBDIR/libs" 451 done 452 else 453 echo "WARNING: Could not find GAbi++ source tree!" 454 fi 455 456 if [ -d "$DSTDIR/$STLPORT_SUBDIR" ] ; then 457 STLPORT_ABIS=$PREBUILT_ABIS 458 for STL_ABI in $STLPORT_ABIS; do 459 copy_prebuilt "$STLPORT_SUBDIR/libs/$STL_ABI" "$STLPORT_SUBDIR/libs" 460 done 461 else 462 echo "WARNING: Could not find STLport source tree!" 463 fi 464 465 for VERSION in $DEFAULT_GCC_VERSION_LIST; do 466 copy_prebuilt "$GNUSTL_SUBDIR/$VERSION/include" "$GNUSTL_SUBDIR/$VERSION/" 467 for STL_ABI in $PREBUILT_ABIS; do 468 copy_prebuilt "$GNUSTL_SUBDIR/$VERSION/libs/$STL_ABI" "$GNUSTL_SUBDIR/$VERSION/libs" 469 done 470 done 471 472 if [ -d "$DSTDIR/$LIBPORTABLE_SUBDIR" ]; then 473 LIBPORTABLE_ABIS=$PREBUILT_ABIS 474 for LIBPORTABLE_ABI in $LIBPORTABLE_ABIS; do 475 copy_prebuilt "$LIBPORTABLE_SUBDIR/libs/$LIBPORTABLE_ABI" "$LIBPORTABLE_SUBDIR/libs" 476 done 477 else 478 echo "WARNING: Could not find libportable source tree!" 479 fi 480 else 481 # Unpack toolchains 482 for TC in $TOOLCHAINS; do 483 unpack_prebuilt $TC-$SYSTEM "$DSTDIR" "$DSTDIR64" 484 echo "Removing sysroot for $TC" 485 rm -rf $DSTDIR/toolchains/$TC/prebuilt/$SYSTEM/sysroot 486 rm -rf $DSTDIR64/toolchains/$TC/prebuilt/${SYSTEM}_64/sysroot 487 rm -rf $DSTDIR64/toolchains/$TC/prebuilt/${SYSTEM}-x86_64/sysroot 488 done 489 echo "Remove ld.mcld deployed/packaged earlier by accident " 490 find $DSTDIR/toolchains $DSTDIR64/toolchains -name "*ld.mcld*" -exec rm -f {} \; 491 492 # Unpack llvm and clang 493 for LLVM_VERSION in $LLVM_VERSION_LIST; do 494 unpack_prebuilt llvm-$LLVM_VERSION-$SYSTEM "$DSTDIR" "$DSTDIR64" 495 done 496 497 if [ "$SYSTEM" != "windows" ]; then 498 # Unpack ld.mcld. Todo: windows 499 unpack_prebuilt ld.mcld-$SYSTEM "$DSTDIR" "$DSTDIR64" 500 fi 501 502 # Unpack prebuilt ndk-stack and other host tools 503 unpack_prebuilt ndk-stack-$SYSTEM "$DSTDIR" "$DSTDIR64" "yes" 504 unpack_prebuilt ndk-make-$SYSTEM "$DSTDIR" "$DSTDIR64" 505 unpack_prebuilt ndk-sed-$SYSTEM "$DSTDIR" "$DSTDIR64" 506 unpack_prebuilt ndk-awk-$SYSTEM "$DSTDIR" "$DSTDIR64" 507 unpack_prebuilt ndk-perl-$SYSTEM "$DSTDIR" "$DSTDIR64" 508 509 if [ "$SYSTEM" = "windows" ]; then 510 unpack_prebuilt toolbox-$SYSTEM "$DSTDIR" "$DSTDIR64" 511 fi 512 fi 513 514 # Unpack other host tools 515 unpack_prebuilt scan-build-view "$DSTDIR" "$DSTDIR64" 516 517 # Create an archive for the final package. Extension depends on the 518 # host system. 519 ARCHIVE=$BIN_RELEASE 520 if [ "$TRY64" = "yes" ]; then 521 ARCHIVE=`name64 $ARCHIVE` 522 elif [ "$SYSTEM" = "windows" ]; then 523 ARCHIVE=$ARCHIVE-x86 524 fi 525 case "$SYSTEM" in 526 windows) 527 ARCHIVE64="$ARCHIVE-64bit-tools.zip" 528 ARCHIVE="$ARCHIVE.zip" 529 ;; 530 *) 531 ARCHIVE64="$ARCHIVE-64bit-tools.tar.bz2" 532 ARCHIVE="$ARCHIVE.tar.bz2" 533 ;; 534 esac 535 echo "Creating $ARCHIVE" 536 # make all file universally readable, and all executable (including directory) 537 # universally executable, punt intended 538 find $DSTDIR $DSTDIR64 -exec chmod a+r {} \; 539 find $DSTDIR $DSTDIR64 -executable -exec chmod a+x {} \; 540 pack_archive "$OUT_DIR/$ARCHIVE" "$TMPDIR" "$RELEASE_PREFIX" 541 fail_panic "Could not create archive: $OUT_DIR/$ARCHIVE" 542 if [ "$SEPARATE_64" = "yes" ] ; then 543 pack_archive "$OUT_DIR/$ARCHIVE64" "$TMPDIR/64" "${RELEASE_PREFIX}" 544 fail_panic "Could not create archive: $OUT_DIR/$ARCHIVE64" 545 fi 546done 547 548echo "Cleaning up." 549rm -rf $TMPDIR/reference 550rm -rf $TMPDIR/prev-ndk 551 552echo "Done, please see packages in $OUT_DIR:" 553ls -l $OUT_DIR 554