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# gen-platforms.sh 18# 19# This tool is used when packaging a new release, or when developing 20# the NDK itself. It will populate DST ($NDK/platforms by default) 21# with the content of SRC ($NDK/../development/ndk/platforms/ by default). 22# 23# The idea is that the content of $SRC/android-N/ only contains stuff 24# that is relevant to API level N, and not contain anything that is already 25# provided by API level N-1, N-2, etc.. 26# 27# More precisely, for each architecture A: 28# $SRC/android-N/include --> $DST/android-N/arch-A/usr/include 29# $SRC/android-N/arch-A/include --> $DST/android-N/arch-A/usr/include 30# $SRC/android-N/arch-A/lib --> $DST/android-N/arch-A/usr/lib 31# 32# Also, we generate on-the-fly shared dynamic libraries from list of symbols: 33# 34# $SRC/android-N/arch-A/symbols --> $DST/android-N/arch-A/usr/lib 35# 36# Repeat after that for N+1, N+2, etc.. 37# 38 39PROGDIR=$(dirname "$0") 40. "$PROGDIR/prebuilt-common.sh" 41 42# Return the list of platform supported from $1/platforms 43# as a single space-separated sorted list of levels. (e.g. "3 4 5 8 9 14") 44# $1: source directory 45extract_platforms_from () 46{ 47 if [ -d "$1" ] ; then 48 (cd "$1/platforms" && ls -d android-*) | sed -e "s!android-!!" | sort -g | tr '\n' ' ' 49 else 50 echo "" 51 fi 52} 53 54SRCDIR="../development/ndk" 55DSTDIR="$ANDROID_NDK_ROOT" 56 57ARCHS="$DEFAULT_ARCHS" 58PLATFORMS=`extract_platforms_from "$SRCDIR"` 59NDK_DIR=$ANDROID_NDK_ROOT 60 61OPTION_HELP=no 62OPTION_PLATFORMS= 63OPTION_SRCDIR= 64OPTION_DSTDIR= 65OPTION_SAMPLES= 66OPTION_FAST_COPY= 67OPTION_MINIMAL= 68OPTION_ARCH= 69OPTION_ABI= 70OPTION_DEBUG_LIBS= 71OPTION_OVERLAY= 72PACKAGE_DIR= 73 74VERBOSE=no 75VERBOSE2=no 76 77for opt do 78 optarg=`expr "x$opt" : 'x[^=]*=\(.*\)'` 79 case "$opt" in 80 --help|-h|-\?) OPTION_HELP=yes 81 ;; 82 --verbose) 83 if [ "$VERBOSE" = "yes" ] ; then 84 VERBOSE2=yes 85 else 86 VERBOSE=yes 87 fi 88 ;; 89 --src-dir=*) 90 OPTION_SRCDIR="$optarg" 91 ;; 92 --dst-dir=*) 93 OPTION_DSTDIR="$optarg" 94 ;; 95 --ndk-dir=*) 96 NDK_DIR=$optarg 97 ;; 98 --platform=*) 99 OPTION_PLATFORM=$optarg 100 ;; 101 --arch=*) 102 OPTION_ARCH=$optarg 103 ;; 104 --abi=*) # We still support this for backwards-compatibility 105 OPTION_ABI=$optarg 106 ;; 107 --samples) 108 OPTION_SAMPLES=yes 109 ;; 110 --fast-copy) 111 OPTION_FAST_COPY=yes 112 ;; 113 --minimal) 114 OPTION_MINIMAL=yes 115 ;; 116 --package-dir=*) 117 PACKAGE_DIR=$optarg 118 ;; 119 --debug-libs) 120 OPTION_DEBUG_LIBS=true 121 ;; 122 --overlay) 123 OPTION_OVERLAY=true 124 ;; 125 *) 126 echo "unknown option '$opt', use --help" 127 exit 1 128 esac 129done 130 131if [ $OPTION_HELP = "yes" ] ; then 132 echo "Collect files from an Android NDK development tree and assemble" 133 echo "the platform files appropriately into a final release structure." 134 echo "" 135 echo "options:" 136 echo "" 137 echo " --help Print this message" 138 echo " --verbose Enable verbose messages" 139 echo " --src-dir=<path> Source directory for development platform files [$SRCDIR]" 140 echo " --dst-dir=<path> Destination directory [$DSTDIR]" 141 echo " --ndk-dir=<path> Use toolchains from this NDK directory [$NDK_DIR]" 142 echo " --platform=<list> List of API levels [$PLATFORMS]" 143 echo " --arch=<list> List of CPU architectures [$ARCHS]" 144 echo " --minimal Ignore samples, symlinks and generated shared libs." 145 echo " --fast-copy Don't create symlinks, copy files instead" 146 echo " --samples Also generate samples directories." 147 echo " --package-dir=<path> Package platforms archive in specific path." 148 echo " --debug-libs Also generate C source file for generated libraries." 149 echo "" 150 echo "Use the --minimal flag if you want to generate minimal sysroot directories" 151 echo "that will be used to generate prebuilt toolchains. Otherwise, the script" 152 echo "will require these toolchains to be pre-installed and will use them to" 153 echo "generate shared system shared libraries from the symbol list files." 154 exit 0 155fi 156 157if [ -n "$OPTION_SRCDIR" ] ; then 158 SRCDIR="$OPTION_SRCDIR"; 159 if [ ! -d "$SRCDIR" ] ; then 160 echo "ERROR: Source directory $SRCDIR does not exist !" 161 exit 1 162 fi 163 if [ ! -d "$SRCDIR/platforms/android-3" ] ; then 164 echo "ERROR: Invalid source directory: $SRCDIR" 165 echo "Please make sure it contains platforms/android-3 etc..." 166 exit 1 167 fi 168else 169 SRCDIR=`dirname $ANDROID_NDK_ROOT`/development/ndk 170 log "Using source directory: $SRCDIR" 171fi 172 173if [ -n "$OPTION_PLATFORM" ] ; then 174 PLATFORMS=$(commas_to_spaces $OPTION_PLATFORM) 175else 176 # Build the list from the content of SRCDIR 177 PLATFORMS=`extract_platforms_from "$SRCDIR"` 178 log "Using platforms: $PLATFORMS" 179fi 180 181# Remove the android- prefix of any platform name 182PLATFORMS=$(echo $PLATFORMS | tr ' ' '\n' | sed -e 's!^android-!!g' | tr '\n' ' ') 183 184if [ -n "$OPTION_DSTDIR" ] ; then 185 DSTDIR="$OPTION_DSTDIR" 186else 187 log "Using destination directory: $DSTDIR" 188fi 189 190# Handle architecture list 191# 192# We support both --arch and --abi for backwards compatibility reasons 193# --arch is the new hotness, --abi is deprecated. 194# 195if [ -n "$OPTION_ARCH" ]; then 196 OPTION_ARCH=$(commas_to_spaces $OPTION_ARCH) 197fi 198 199if [ -n "$OPTION_ABI" ] ; then 200 echo "WARNING: --abi=<names> is deprecated. Use --arch=<names> instead!" 201 OPTION_ABI=$(commas_to_spaces $OPTION_ABI) 202 if [ -n "$OPTION_ARCH" -a "$OPTION_ARCH" != "$OPTION_ABI" ]; then 203 echo "ERROR: You can't use both --abi and --arch with different values!" 204 exit 1 205 fi 206 OPTION_ARCH=$OPTION_ABI 207fi 208 209if [ -n "$OPTION_ARCH" ] ; then 210 ARCHS="$OPTION_ARCH" 211fi 212log "Using architectures: $(commas_to_spaces $ARCHS)" 213 214log "Checking source platforms." 215for PLATFORM in $PLATFORMS; do 216 DIR="$SRCDIR/platforms/android-$PLATFORM" 217 if [ ! -d $DIR ] ; then 218 echo "ERROR: Directory missing: $DIR" 219 echo "Please check your --platform=<list> option and try again." 220 exit 2 221 else 222 log " $DIR" 223 fi 224done 225 226log "Checking source platform architectures." 227BAD_ARCHS= 228for ARCH in $ARCHS; do 229 eval CHECK_$ARCH=no 230done 231for PLATFORM in $PLATFORMS; do 232 for ARCH in $ARCHS; do 233 DIR="$SRCDIR/platforms/android-$PLATFORM/arch-$ARCH" 234 if [ -d $DIR ] ; then 235 log " $DIR" 236 eval CHECK_$ARCH=yes 237 fi 238 done 239done 240 241if [ "$OPTION_MINIMAL" ]; then 242 OPTION_SAMPLES= 243 OPTION_FAST_COPY=yes 244fi 245 246BAD_ARCHS= 247for ARCH in $ARCHS; do 248 CHECK=`var_value CHECK_$ARCH` 249 log " $ARCH check: $CHECK" 250 if [ "$CHECK" = no ] ; then 251 if [ -z "$BAD_ARCHS" ] ; then 252 BAD_ARCHS=$ARCH 253 else 254 BAD_ARCHS="$BAD_ARCHS $ARCH" 255 fi 256 fi 257done 258 259if [ -n "$BAD_ARCHS" ] ; then 260 echo "ERROR: Source directory doesn't support these ARCHs: $BAD_ARCHS" 261 exit 3 262fi 263 264# $1: source directory (relative to $SRCDIR) 265# $2: destination directory (relative to $DSTDIR) 266# $3: description of directory contents (e.g. "sysroot" or "samples") 267copy_src_directory () 268{ 269 local SDIR="$SRCDIR/$1" 270 local DDIR="$DSTDIR/$2" 271 if [ -d "$SDIR" ] ; then 272 log "Copying $3 from \$SRC/$1 to \$DST/$2." 273 mkdir -p "$DDIR" && (cd "$SDIR" && 2>/dev/null tar chf - *) | (tar xf - -C "$DDIR") 274 if [ $? != 0 ] ; then 275 echo "ERROR: Could not copy $3 directory $SDIR into $DDIR !" 276 exit 5 277 fi 278 fi 279} 280 281# $1: source dir 282# $2: destination dir 283# $3: reverse path 284# 285symlink_src_directory_inner () 286{ 287 local files file subdir rev 288 mkdir -p "$DSTDIR/$2" 289 rev=$3 290 files=$(cd $DSTDIR/$1 && ls -1p) 291 for file in $files; do 292 if [ "$file" = "${file%%/}" ]; then 293 log2 "Link \$DST/$2/$file --> $rev/$1/$file" 294 ln -s $rev/$1/$file $DSTDIR/$2/$file 295 else 296 file=${file%%/} 297 symlink_src_directory_inner "$1/$file" "$2/$file" "$rev/.." 298 fi 299 done 300} 301# Create a symlink-copy of directory $1 into $2 302# This function is recursive. 303# 304# $1: source directory (relative to $SRCDIR) 305# $2: destination directory (relative to $DSTDIR) 306symlink_src_directory () 307{ 308 symlink_src_directory_inner "$1" "$2" "$(reverse_path $1)" 309} 310 311# Remove unwanted symbols 312# $1: symbol file (one symbol per line) 313# $2+: Input symbol list 314# Out: Input symbol file, without any unwanted symbol listed by $1 315remove_unwanted_symbols_from () 316{ 317 local SYMBOL_FILE="$1" 318 shift 319 if [ -f "$SYMBOL_FILE" ]; then 320 echo "$@" | tr ' ' '\n' | grep -v -F -x -f $SYMBOL_FILE | tr '\n' ' ' 321 else 322 echo "$@" 323 fi 324} 325 326# Remove unwanted symbols from a library's functions list. 327# $1: Architecture name 328# $2: Library name (e.g. libc.so) 329# $3+: Input symbol list 330# Out: Input symbol list without any unwanted symbols. 331remove_unwanted_function_symbols () 332{ 333 local ARCH LIBRARY SYMBOL_FILE 334 ARCH=$1 335 LIBRARY=$2 336 shift; shift 337 SYMBOL_FILE=$PROGDIR/unwanted-symbols/$ARCH/$LIBRARY.functions.txt 338 remove_unwanted_symbols_from $SYMBOL_FILE "$@" 339} 340 341# Same as remove_unwanted_functions_symbols, but for variable names. 342# 343remove_unwanted_variable_symbols () 344{ 345 local ARCH LIBRARY SYMBOL_FILE 346 ARCH=$1 347 LIBRARY=$2 348 shift; shift 349 SYMBOL_FILE=$PROGDIR/unwanted-symbols/$ARCH/$LIBRARY.variables.txt 350 remove_unwanted_symbols_from $SYMBOL_FILE "$@" 351} 352 353# $1: library name 354# $2: functions list 355# $3: variables list 356# $4: destination file 357# $5: toolchain binprefix 358gen_shared_lib () 359{ 360 local LIBRARY=$1 361 local FUNCS="$2" 362 local VARS="$3" 363 local DSTFILE="$4" 364 local BINPREFIX="$5" 365 # Now generate a small C source file that contains similarly-named stubs 366 echo "/* Auto-generated file, do not edit */" > $TMPC 367 local func var 368 for func in $FUNCS; do 369 echo "void $func(void) {}" >> $TMPC 370 done 371 for var in $VARS; do 372 echo "int $var = 0;" >> $TMPC 373 done 374 375 # Build it with our cross-compiler. It will complain about conflicting 376 # types for built-in functions, so just shut it up. 377 COMMAND="$BINPREFIX-gcc -Wl,-shared,-Bsymbolic -nostdlib -o $TMPO $TMPC" 378 echo "## COMMAND: $COMMAND" > $TMPL 379 $COMMAND 1>>$TMPL 2>&1 380 if [ $? != 0 ] ; then 381 dump "ERROR: Can't generate shared library for: $LIBNAME" 382 dump "See the content of $TMPC and $TMPL for details." 383 cat $TMPL | tail -10 384 exit 1 385 fi 386 387 # Copy to our destination now 388 local libdir=$(dirname "$DSTFILE") 389 mkdir -p "$libdir" && cp -f $TMPO "$DSTFILE" 390 if [ $? != 0 ] ; then 391 dump "ERROR: Can't copy shared library for: $LIBNAME" 392 dump "target location is: $DSTFILE" 393 exit 1 394 fi 395 396 if [ "$OPTION_DEBUG_LIBS" ]; then 397 cp $TMPC $DSTFILE.c 398 echo "$FUNCS" > $DSTFILE.functions.txt 399 echo "$VARS" > $DSTFILE.variables.txt 400 fi 401} 402 403# $1: Architecture 404# $2: symbol source directory (relative to $SRCDIR) 405# $3: destination directory for generated libs (relative to $DSTDIR) 406gen_shared_libraries () 407{ 408 local ARCH=$1 409 local SYMDIR="$SRCDIR/$2" 410 local SYSROOT="$3" 411 local DSTDIR="$DSTDIR/$SYSROOT/usr/lib" 412 local TOOLCHAIN_PREFIX funcs vars numfuncs numvars 413 414 # Let's locate the toolchain we're going to use 415 local TOOLCHAIN_PREFIX="$NDK_DIR/$(get_default_toolchain_binprefix_for_arch $1)" 416 TOOLCHAIN_PREFIX=${TOOLCHAIN_PREFIX%-} 417 if [ ! -f "$TOOLCHAIN_PREFIX-gcc" ]; then 418 dump "ERROR: $ARCH toolchain not installed: $TOOLCHAIN_PREFIX-gcc" 419 dump "Important: Use the --minimal flag to use this script without generated system shared libraries." 420 dump "This is generally useful when you want to generate the host cross-toolchain programs." 421 exit 1 422 fi 423 424 # In certain cases, the symbols directory doesn't exist, 425 # e.g. on x86 for PLATFORM < 9 426 if [ ! -d "$SYMDIR" ]; then 427 return 428 fi 429 430 # Let's list the libraries we're going to generate 431 LIBS=$( (cd $SYMDIR && 2>/dev/null ls *.functions.txt) | sort -u | sed -e 's!\.functions\.txt$!!g') 432 433 for LIB in $LIBS; do 434 funcs=$(cat "$SYMDIR/$LIB.functions.txt" 2>/dev/null) 435 vars=$(cat "$SYMDIR/$LIB.variables.txt" 2>/dev/null) 436 funcs=$(remove_unwanted_function_symbols $ARCH libgcc.a $funcs) 437 funcs=$(remove_unwanted_function_symbols $ARCH $LIB $funcs) 438 vars=$(remove_unwanted_variable_symbols $ARCH $LIB $vars) 439 numfuncs=$(echo $funcs | wc -w) 440 numvars=$(echo $vars | wc -w) 441 log "Generating $ARCH shared library for $LIB ($numfuncs functions + $numvars variables)" 442 443 gen_shared_lib $LIB "$funcs" "$vars" "$DSTDIR/$LIB" "$TOOLCHAIN_PREFIX" 444 done 445} 446 447# $1: platform number 448# $2: architecture name 449# $3: common source directory (for crtbrand.c, etc) 450# $4: source directory (for *.S files) 451# $5: destination directory 452gen_crt_objects () 453{ 454 local API=$1 455 local ARCH=$2 456 local COMMON_SRC_DIR="$SRCDIR/$3" 457 local SRC_DIR="$SRCDIR/$4" 458 local DST_DIR="$DSTDIR/$5" 459 local SRC_FILE DST_FILE 460 local TOOLCHAIN_PREFIX 461 462 if [ ! -d "$SRC_DIR" ]; then 463 return 464 fi 465 466 # Let's locate the toolchain we're going to use 467 local TOOLCHAIN_PREFIX="$NDK_DIR/$(get_default_toolchain_binprefix_for_arch $ARCH)" 468 TOOLCHAIN_PREFIX=${TOOLCHAIN_PREFIX%-} 469 if [ ! -f "$TOOLCHAIN_PREFIX-gcc" ]; then 470 dump "ERROR: $ARCH toolchain not installed: $TOOLCHAIN_PREFIX-gcc" 471 dump "Important: Use the --minimal flag to use this script without generating object files." 472 dump "This is generally useful when you want to generate the host cross-toolchain programs." 473 exit 1 474 fi 475 476 CRTBRAND_S=$DST_DIR/crtbrand.s 477 log "Generating platform $API crtbrand assembly code: $CRTBRAND_S" 478 (cd "$COMMON_SRC_DIR" && $TOOLCHAIN_PREFIX-gcc -DPLATFORM_SDK_VERSION=$API -fpic -S -o - crtbrand.c | \ 479 sed -e '/\.note\.ABI-tag/s/progbits/note/' > "$CRTBRAND_S") 1>>$TMPL 2>&1 480 if [ $? != 0 ]; then 481 dump "ERROR: Could not generate $CRTBRAND_S from $COMMON_SRC_DIR/crtbrand.c" 482 dump "Please see the content of $TMPL for details!" 483 cat $TMPL | tail -10 484 exit 1 485 fi 486 487 for SRC_FILE in $(cd "$SRC_DIR" && ls crt*.[cS]); do 488 DST_FILE=${SRC_FILE%%.c} 489 DST_FILE=${DST_FILE%%.S}.o 490 491 case "$DST_FILE" in 492 "crtend.o") 493 # Special case: crtend.S must be compiled as crtend_android.o 494 # This is for long historical reasons, i.e. to avoid name conflicts 495 # in the past with other crtend.o files. This is hard-coded in the 496 # Android toolchain configuration, so switch the name here. 497 DST_FILE=crtend_android.o 498 ;; 499 "crtbegin_dynamic.o"|"crtbegin_static.o") 500 # Add .note.ABI-tag section 501 SRC_FILE=$SRC_FILE" $CRTBRAND_S" 502 ;; 503 esac 504 505 log "Generating $ARCH C runtime object: $DST_FILE" 506 (cd "$SRC_DIR" && $TOOLCHAIN_PREFIX-gcc -O2 -fpic -Wl,-r -nostdlib -o "$DST_DIR/$DST_FILE" $SRC_FILE) 1>>$TMPL 2>&1 507 if [ $? != 0 ]; then 508 dump "ERROR: Could not generate $DST_FILE from $SRC_DIR/$SRC_FILE" 509 dump "Please see the content of $TMPL for details!" 510 cat $TMPL | tail -10 511 exit 1 512 fi 513 done 514 rm -f "$CRTBRAND_S" 515} 516 517# $1: platform number 518# $2: architecture 519# $3: target NDK directory 520generate_api_level () 521{ 522 local API=$1 523 local ARCH=$2 524 local HEADER="platforms/android-$API/arch-$ARCH/usr/include/android/api-level.h" 525 log "Generating: $HEADER" 526 rm -f "$3/$HEADER" # Remove symlink if any. 527 cat > "$3/$HEADER" <<EOF 528/* 529 * Copyright (C) 2008 The Android Open Source Project 530 * All rights reserved. 531 * 532 * Redistribution and use in source and binary forms, with or without 533 * modification, are permitted provided that the following conditions 534 * are met: 535 * * Redistributions of source code must retain the above copyright 536 * notice, this list of conditions and the following disclaimer. 537 * * Redistributions in binary form must reproduce the above copyright 538 * notice, this list of conditions and the following disclaimer in 539 * the documentation and/or other materials provided with the 540 * distribution. 541 * 542 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 543 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 544 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 545 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 546 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 547 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 548 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 549 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 550 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 551 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 552 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 553 * SUCH DAMAGE. 554 */ 555#ifndef ANDROID_API_LEVEL_H 556#define ANDROID_API_LEVEL_H 557 558#define __ANDROID_API__ $API 559 560#endif /* ANDROID_API_LEVEL_H */ 561EOF 562} 563 564# Copy platform sysroot and samples into your destination 565# 566 567# if $SRC/android-$PLATFORM/arch-$ARCH exists 568# $SRC/android-$PLATFORM/include --> $DST/android-$PLATFORM/arch-$ARCH/usr/include 569# $SRC/android-$PLATFORM/arch-$ARCH/include --> $DST/android-$PLATFORM/arch-$ARCH/usr/include 570# $SRC/android-$PLATFORM/arch-$ARCH/lib --> $DST/android-$PLATFORM/arch-$ARCH/usr/lib 571# 572if [ -z "$OPTION_OVERLAY" ]; then 573 rm -rf $DSTDIR/platforms && mkdir -p $DSTDIR/platforms 574fi 575for ARCH in $ARCHS; do 576 # Find first platform for this arch 577 PREV_SYSROOT_DST= 578 for PLATFORM in $PLATFORMS; do 579 PLATFORM_DST=platforms/android-$PLATFORM # Relative to $DSTDIR 580 PLATFORM_SRC=$PLATFORM_DST # Relative to $SRCDIR 581 SYSROOT_DST=$PLATFORM_DST/arch-$ARCH/usr 582 # Skip over if there is no arch-specific file for this platform 583 # and no destination platform directory was created. This is needed 584 # because x86 and MIPS don't have files for API levels 3-8. 585 if [ -z "$PREV_SYSROOT_DST" -a \ 586 ! -d "$SRCDIR/$PLATFORM_SRC/arch-$ARCH" ]; then 587 log "Skipping: \$SRC/$PLATFORM_SRC/arch-$ARCH" 588 continue 589 fi 590 591 log "Populating \$DST/platforms/android-$PLATFORM/arch-$ARCH" 592 593 # If this is not the first destination directory, copy over, or 594 # symlink the files from the previous one now. 595 if [ "$PREV_SYSROOT_DST" ]; then 596 if [ "$OPTION_FAST_COPY" ]; then 597 log "Copying \$DST/$PREV_SYSROOT_DST to \$DST/$SYSROOT_DST" 598 copy_directory "$DSTDIR/$PREV_SYSROOT_DST" "$DSTDIR/$SYSROOT_DST" 599 else 600 log "Symlink-copying \$DST/$PREV_SYSROOT_DST to \$DST/$SYSROOT_DST" 601 symlink_src_directory $PREV_SYSROOT_DST $SYSROOT_DST 602 fi 603 fi 604 605 # If this is the first destination directory, copy the common 606 # files from previous platform directories into this one. 607 # This helps copy the common headers from android-3 to android-8 608 # into the x86 and mips android-9 directories. 609 if [ -z "$PREV_SYSROOT_DST" ]; then 610 for OLD_PLATFORM in $PLATFORMS; do 611 if [ "$OLD_PLATFORM" -eq "$PLATFORM" ]; then 612 break 613 fi 614 copy_src_directory platforms/android-$OLD_PLATFORM/include \ 615 $SYSROOT_DST/include \ 616 "common android-$OLD_PLATFORM headers" 617 done 618 fi 619 620 # Now copy over all non-arch specific include files 621 copy_src_directory $PLATFORM_SRC/include $SYSROOT_DST/include "common system headers" 622 copy_src_directory $PLATFORM_SRC/arch-$ARCH/include $SYSROOT_DST/include "$ARCH system headers" 623 624 generate_api_level "$PLATFORM" "$ARCH" "$DSTDIR" 625 626 # If --minimal is not used, copy or generate binary files. 627 if [ -z "$OPTION_MINIMAL" ]; then 628 # Copy the prebuilt static libraries. 629 copy_src_directory $PLATFORM_SRC/arch-$ARCH/lib $SYSROOT_DST/lib "$ARCH sysroot libs" 630 631 # Generate C runtime object files when available 632 PLATFORM_SRC_ARCH=$PLATFORM_SRC/arch-$ARCH/src 633 if [ ! -d "$SRCDIR/$PLATFORM_SRC_ARCH" ]; then 634 PLATFORM_SRC_ARCH=$PREV_PLATFORM_SRC_ARCH 635 else 636 PREV_PLATFORM_SRC_ARCH=$PLATFORM_SRC_ARCH 637 fi 638 gen_crt_objects $PLATFORM $ARCH platforms/common/src $PLATFORM_SRC_ARCH $SYSROOT_DST/lib 639 640 # Generate shared libraries from symbol files 641 gen_shared_libraries $ARCH $PLATFORM_SRC/arch-$ARCH/symbols $PLATFORM_DST/arch-$ARCH 642 else 643 # Copy the prebuilt binaries to bootstrap GCC 644 copy_src_directory $PLATFORM_SRC/arch-$ARCH/lib-bootstrap $SYSROOT_DST/lib "$ARCH sysroot libs (boostrap)" 645 fi 646 PREV_SYSROOT_DST=$SYSROOT_DST 647 done 648done 649 650# 651# $SRC/android-$PLATFORM/samples --> $DST/samples 652# 653if [ "$OPTION_SAMPLES" ] ; then 654 # Copy platform samples and generic samples into your destination 655 # 656 # $SRC/samples/ --> $DST/samples/ 657 # $SRC/android-$PLATFORM/samples/ --> $DST/samples 658 # 659 dump "Copying generic samples" 660 if [ -z "$OPTION_OVERLAY" ]; then 661 rm -rf $DSTDIR/samples && mkdir -p $DSTDIR/samples 662 fi 663 copy_src_directory samples samples samples 664 665 for PLATFORM in $PLATFORMS; do 666 dump "Copy android-$PLATFORM samples" 667 # $SRC/platform-$PLATFORM/samples --> $DST/samples 668 copy_src_directory platforms/android-$PLATFORM/samples samples samples 669 done 670 671 # Cleanup generated files in samples 672 rm -rf "$DSTDIR/samples/*/obj" 673 rm -rf "$DSTDIR/samples/*/libs" 674fi 675 676if [ "$PACKAGE_DIR" ]; then 677 mkdir -p "$PACKAGE_DIR" 678 fail_panic "Could not create package directory: $PACKAGE_DIR" 679 ARCHIVE=platforms.tar.bz2 680 dump "Packaging $ARCHIVE" 681 pack_archive "$PACKAGE_DIR/$ARCHIVE" "$DSTDIR" "platforms" 682 fail_panic "Could not package platforms" 683 if [ "$OPTION_SAMPLES" ]; then 684 ARCHIVE=samples.tar.bz2 685 dump "Packaging $ARCHIVE" 686 pack_archive "$PACKAGE_DIR/$ARCHIVE" "$DSTDIR" "samples" 687 fail_panic "Could not package samples" 688 fi 689fi 690 691log "Done !" 692