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