prebuilt-common.sh revision 3592767ce5ca9431eea728370c99d97aadb0800e
1# Common functions for all prebuilt-related scripts 2# This is included/sourced by other scripts 3# 4 5. `dirname $0`/../core/ndk-common.sh 6 7#==================================================== 8# 9# UTILITY FUNCTIONS 10# 11#==================================================== 12 13# Return the maximum length of a series of strings 14# 15# Usage: len=`max_length <string1> <string2> ...` 16# 17max_length () 18{ 19 echo "$@" | tr ' ' '\n' | awk 'BEGIN {max=0} {len=length($1); if (len > max) max=len} END {print max}' 20} 21 22# Translate dashes to underscores 23# Usage: str=`dashes_to_underscores <values>` 24dashes_to_underscores () 25{ 26 echo $@ | tr '-' '_' 27} 28 29# Translate underscores to dashes 30# Usage: str=`underscores_to_dashes <values>` 31underscores_to_dashes () 32{ 33 echo $@ | tr '_' '-' 34} 35 36# Translate commas to spaces 37# Usage: str=`commas_to_spaces <list>` 38commas_to_spaces () 39{ 40 echo $@ | tr ',' ' ' 41} 42 43# Translate spaces to commas 44# Usage: list=`spaces_to_commas <string>` 45spaces_to_commas () 46{ 47 echo $@ | tr ' ' ',' 48} 49 50# Predicate: true iff a space-separated list contains a given item regex pattern 51# $1: item regex pattern 52# $2+: list 53list_contains () 54{ 55 local KEY="$1" 56 shift 57 echo $@ | tr ' ' '\n' | grep -q -F -e "$KEY" 58} 59 60sort_uniq () 61{ 62 local RET 63 RET=$(echo $@ | tr ' ' '\n' | sort -u) 64 echo $RET 65} 66 67#==================================================== 68# 69# OPTION PROCESSING 70# 71#==================================================== 72 73# We recognize the following option formats: 74# 75# -f 76# --flag 77# 78# -s<value> 79# --setting=<value> 80# 81 82# NOTE: We translate '-' into '_' when storing the options in global variables 83# 84 85OPTIONS="" 86OPTION_FLAGS="" 87OPTION_SETTINGS="" 88 89# Set a given option attribute 90# $1: option name 91# $2: option attribute 92# $3: attribute value 93# 94option_set_attr () 95{ 96 eval OPTIONS_$1_$2=\"$3\" 97} 98 99# Get a given option attribute 100# $1: option name 101# $2: option attribute 102# 103option_get_attr () 104{ 105 echo `var_value OPTIONS_$1_$2` 106} 107 108# Register a new option 109# $1: option 110# $2: small abstract for the option 111# $3: optional. default value 112# 113register_option_internal () 114{ 115 optlabel= 116 optname= 117 optvalue= 118 opttype= 119 while [ -n "1" ] ; do 120 # Check for something like --setting=<value> 121 echo "$1" | grep -q -E -e '^--[^=]+=<.+>$' 122 if [ $? = 0 ] ; then 123 optlabel=`expr -- "$1" : '\(--[^=]*\)=.*'` 124 optvalue=`expr -- "$1" : '--[^=]*=\(<.*>\)'` 125 opttype="long_setting" 126 break 127 fi 128 129 # Check for something like --flag 130 echo "$1" | grep -q -E -e '^--[^=]+$' 131 if [ $? = 0 ] ; then 132 optlabel="$1" 133 opttype="long_flag" 134 break 135 fi 136 137 # Check for something like -f<value> 138 echo "$1" | grep -q -E -e '^-[A-Za-z0-9]<.+>$' 139 if [ $? = 0 ] ; then 140 optlabel=`expr -- "$1" : '\(-.\).*'` 141 optvalue=`expr -- "$1" : '-.\(<.+>\)'` 142 opttype="short_setting" 143 break 144 fi 145 146 # Check for something like -f 147 echo "$1" | grep -q -E -e '^-.$' 148 if [ $? = 0 ] ; then 149 optlabel="$1" 150 opttype="short_flag" 151 break 152 fi 153 154 echo "ERROR: Invalid option format: $1" 155 echo " Check register_option call" 156 exit 1 157 done 158 159 log "new option: type='$opttype' name='$optlabel' value='$optvalue'" 160 161 optname=`dashes_to_underscores $optlabel` 162 OPTIONS="$OPTIONS $optname" 163 OPTIONS_TEXT="$OPTIONS_TEXT $1" 164 option_set_attr $optname label "$optlabel" 165 option_set_attr $optname otype "$opttype" 166 option_set_attr $optname value "$optvalue" 167 option_set_attr $optname text "$1" 168 option_set_attr $optname abstract "$2" 169 option_set_attr $optname default "$3" 170} 171 172# Register a new option with a function callback. 173# 174# $1: option 175# $2: name of function that will be called when the option is parsed 176# $3: small abstract for the option 177# $4: optional. default value 178# 179register_option () 180{ 181 local optname optvalue opttype optlabel 182 register_option_internal "$1" "$3" "$4" 183 option_set_attr $optname funcname "$2" 184} 185 186# Register a new option with a variable store 187# 188# $1: option 189# $2: name of variable that will be set by this option 190# $3: small abstract for the option 191# 192# NOTE: The current value of $2 is used as the default 193# 194register_var_option () 195{ 196 local optname optvalue opttype optlabel 197 register_option_internal "$1" "$3" "`var_value $2`" 198 option_set_attr $optname varname "$2" 199} 200 201 202MINGW=no 203do_mingw_option () { MINGW=yes; } 204 205register_mingw_option () 206{ 207 if [ "$HOST_OS" = "linux" ] ; then 208 register_option "--mingw" do_mingw_option "Generate windows binaries on Linux." 209 fi 210} 211 212TRY64=no 213do_try64_option () { TRY64=yes; } 214 215register_try64_option () 216{ 217 register_option "--try-64" do_try64_option "Generate 64-bit binaries." 218} 219 220# Print the help, including a list of registered options for this program 221# Note: Assumes PROGRAM_PARAMETERS and PROGRAM_DESCRIPTION exist and 222# correspond to the parameters list and the program description 223# 224print_help () 225{ 226 local opt text abstract default 227 228 echo "Usage: $PROGNAME [options] $PROGRAM_PARAMETERS" 229 echo "" 230 if [ -n "$PROGRAM_DESCRIPTION" ] ; then 231 echo "$PROGRAM_DESCRIPTION" 232 echo "" 233 fi 234 echo "Valid options (defaults are in brackets):" 235 echo "" 236 237 maxw=`max_length "$OPTIONS_TEXT"` 238 AWK_SCRIPT=`echo "{ printf \"%-${maxw}s\", \\$1 }"` 239 for opt in $OPTIONS; do 240 text=`option_get_attr $opt text | awk "$AWK_SCRIPT"` 241 abstract=`option_get_attr $opt abstract` 242 default=`option_get_attr $opt default` 243 if [ -n "$default" ] ; then 244 echo " $text $abstract [$default]" 245 else 246 echo " $text $abstract" 247 fi 248 done 249 echo "" 250} 251 252option_panic_no_args () 253{ 254 echo "ERROR: Option '$1' does not take arguments. See --help for usage." 255 exit 1 256} 257 258option_panic_missing_arg () 259{ 260 echo "ERROR: Option '$1' requires an argument. See --help for usage." 261 exit 1 262} 263 264extract_parameters () 265{ 266 local opt optname otype value name fin funcname 267 PARAMETERS="" 268 while [ -n "$1" ] ; do 269 # If the parameter does not begin with a dash 270 # it is not an option. 271 param=`expr -- "$1" : '^\([^\-].*\)$'` 272 if [ -n "$param" ] ; then 273 if [ -z "$PARAMETERS" ] ; then 274 PARAMETERS="$1" 275 else 276 PARAMETERS="$PARAMETERS $1" 277 fi 278 shift 279 continue 280 fi 281 282 while [ -n "1" ] ; do 283 # Try to match a long setting, i.e. --option=value 284 opt=`expr -- "$1" : '^\(--[^=]*\)=.*$'` 285 if [ -n "$opt" ] ; then 286 otype="long_setting" 287 value=`expr -- "$1" : '^--[^=]*=\(.*\)$'` 288 break 289 fi 290 291 # Try to match a long flag, i.e. --option 292 opt=`expr -- "$1" : '^\(--.*\)$'` 293 if [ -n "$opt" ] ; then 294 otype="long_flag" 295 value="yes" 296 break 297 fi 298 299 # Try to match a short setting, i.e. -o<value> 300 opt=`expr -- "$1" : '^\(-[A-Za-z0-9]\)..*$'` 301 if [ -n "$opt" ] ; then 302 otype="short_setting" 303 value=`expr -- "$1" : '^-.\(.*\)$'` 304 break 305 fi 306 307 # Try to match a short flag, i.e. -o 308 opt=`expr -- "$1" : '^\(-.\)$'` 309 if [ -n "$opt" ] ; then 310 otype="short_flag" 311 value="yes" 312 break 313 fi 314 315 echo "ERROR: Unknown option '$1'. Use --help for list of valid values." 316 exit 1 317 done 318 319 #echo "Found opt='$opt' otype='$otype' value='$value'" 320 321 name=`dashes_to_underscores $opt` 322 found=0 323 for xopt in $OPTIONS; do 324 if [ "$name" != "$xopt" ] ; then 325 continue 326 fi 327 # Check that the type is correct here 328 # 329 # This also allows us to handle -o <value> as -o<value> 330 # 331 xotype=`option_get_attr $name otype` 332 if [ "$otype" != "$xotype" ] ; then 333 case "$xotype" in 334 "short_flag") 335 option_panic_no_args $opt 336 ;; 337 "short_setting") 338 if [ -z "$2" ] ; then 339 option_panic_missing_arg $opt 340 fi 341 value="$2" 342 shift 343 ;; 344 "long_flag") 345 option_panic_no_args $opt 346 ;; 347 "long_setting") 348 option_panic_missing_arg $opt 349 ;; 350 esac 351 fi 352 found=1 353 break 354 break 355 done 356 if [ "$found" = "0" ] ; then 357 echo "ERROR: Unknown option '$opt'. See --help for usage." 358 exit 1 359 fi 360 # Set variable or launch option-specific function. 361 varname=`option_get_attr $name varname` 362 if [ -n "$varname" ] ; then 363 eval ${varname}=\"$value\" 364 else 365 eval `option_get_attr $name funcname` \"$value\" 366 fi 367 shift 368 done 369} 370 371do_option_help () 372{ 373 print_help 374 exit 0 375} 376 377VERBOSE=no 378VERBOSE2=no 379do_option_verbose () 380{ 381 if [ $VERBOSE = "yes" ] ; then 382 VERBOSE2=yes 383 else 384 VERBOSE=yes 385 fi 386} 387 388register_option "--help" do_option_help "Print this help." 389register_option "--verbose" do_option_verbose "Enable verbose mode." 390 391#==================================================== 392# 393# TOOLCHAIN AND ABI PROCESSING 394# 395#==================================================== 396 397# Determine optional variable value 398# $1: final variable name 399# $2: option variable name 400# $3: small description for the option 401fix_option () 402{ 403 if [ -n "$2" ] ; then 404 eval $1="$2" 405 log "Using specific $3: $2" 406 else 407 log "Using default $3: `var_value $1`" 408 fi 409} 410 411 412# If SYSROOT is empty, check that $1/$2 contains a sysroot 413# and set the variable to it. 414# 415# $1: sysroot path 416# $2: platform/arch suffix 417check_sysroot () 418{ 419 if [ -z "$SYSROOT" ] ; then 420 log "Probing directory for sysroot: $1/$2" 421 if [ -d $1/$2 ] ; then 422 SYSROOT=$1/$2 423 fi 424 fi 425} 426 427# Determine sysroot 428# $1: Option value (or empty) 429# 430fix_sysroot () 431{ 432 if [ -n "$1" ] ; then 433 eval SYSROOT="$1" 434 log "Using specified sysroot: $1" 435 else 436 SYSROOT_SUFFIX=$PLATFORM/arch-$ARCH 437 SYSROOT= 438 check_sysroot $NDK_DIR/platforms $SYSROOT_SUFFIX 439 check_sysroot $ANDROID_NDK_ROOT/platforms $SYSROOT_SUFFIX 440 check_sysroot `dirname $ANDROID_NDK_ROOT`/development/ndk/platforms $SYSROOT_SUFFIX 441 442 if [ -z "$SYSROOT" ] ; then 443 echo "ERROR: Could not find NDK sysroot path for $SYSROOT_SUFFIX." 444 echo " Use --sysroot=<path> to specify one." 445 exit 1 446 fi 447 fi 448 449 if [ ! -f $SYSROOT/usr/include/stdlib.h ] ; then 450 echo "ERROR: Invalid sysroot path: $SYSROOT" 451 echo " Use --sysroot=<path> to indicate a valid one." 452 exit 1 453 fi 454} 455 456# Use the check for the availability of a compatibility SDK in Darwin 457# this can be used to generate binaries compatible with either Tiger or 458# Leopard. 459# 460# $1: SDK root path 461# $2: MacOS X minimum version (e.g. 10.4) 462check_darwin_sdk () 463{ 464 if [ -d "$1" ] ; then 465 HOST_CFLAGS="-isysroot $1 -mmacosx-version-min=$2 -DMAXOSX_DEPLOYEMENT_TARGET=$2" 466 HOST_LDFLAGS="-Wl,-syslibroot,$sdk -mmacosx-version-min=$2" 467 return 0 # success 468 fi 469 return 1 470} 471 472 473prepare_host_flags () 474{ 475 # detect build tag 476 case $HOST_TAG in 477 linux-x86) 478 ABI_CONFIGURE_BUILD=i386-linux-gnu 479 ;; 480 linux-x86_64) 481 ABI_CONFIGURE_BUILD=x86_64-linux-gnu 482 ;; 483 darwin-x86) 484 ABI_CONFIGURE_BUILD=i686-apple-darwin 485 ;; 486 darwin-x86_64) 487 ABI_CONFIGURE_BUILD=x86_64-apple-darwin 488 ;; 489 windows) 490 ABI_CONFIGURE_BUILD=i686-pc-cygwin 491 ;; 492 *) 493 echo "ERROR: Unsupported HOST_TAG: $HOST_TAG" 494 echo "Please update 'prepare_host_flags' in build/tools/prebuilt-common.sh" 495 ;; 496 esac 497 498 # By default, assume host == build 499 ABI_CONFIGURE_HOST="$ABI_CONFIGURE_BUILD" 500 501 # On Linux, detect our legacy-compatible toolchain when in the Android 502 # source tree, and use it to force the generation of glibc-2.7 compatible 503 # binaries. 504 # 505 # We only do this if the CC variable is not defined to a given value 506 # and the --mingw or --try-64 options are not used. 507 # 508 if [ "$HOST_OS" = "linux" -a -z "$CC" -a "$MINGW" != "yes" -a "$TRY64" != "yes" ]; then 509 LEGACY_TOOLCHAIN_DIR="$ANDROID_NDK_ROOT/../prebuilt/linux-x86/toolchain/i686-linux-glibc2.7-4.4.3" 510 if [ -d "$LEGACY_TOOLCHAIN_DIR" ] ; then 511 dump "Forcing generation of Linux binaries with legacy toolchain" 512 CC="$LEGACY_TOOLCHAIN_DIR/bin/i686-linux-gcc" 513 CXX="$LEGACY_TOOLCHAIN_DIR/bin/i686-linux-g++" 514 fi 515 fi 516 517 # Force generation of 32-bit binaries on 64-bit systems 518 CC=${CC:-gcc} 519 CXX=${CXX:-g++} 520 case $HOST_TAG in 521 darwin-*) 522 # Try to build with Tiger SDK if available 523 if check_darwin_sdk /Developer/SDKs/MacOSX10.4.sdku 10.4; then 524 log "Generating Tiger-compatible binaries!" 525 # Otherwise with Leopard SDK 526 elif check_darwin_sdk /Developer/SDKs/MacOSX10.5.sdk 10.5; then 527 log "Generating Leopard-compatible binaries!" 528 else 529 local version=`sw_vers -productVersion` 530 log "Generating $version-compatible binaries!" 531 fi 532 ;; 533 esac 534 535 # Force generation of 32-bit binaries on 64-bit systems. 536 # We used to test the value of $HOST_TAG for *-x86_64, but this is 537 # not sufficient on certain systems. 538 # 539 # For example, Snow Leopard can be booted with a 32-bit kernel, running 540 # a 64-bit userland, with a compiler that generates 64-bit binaries by 541 # default *even* though "gcc -v" will report --target=i686-apple-darwin10! 542 # 543 # So know, simply probe for the size of void* by performing a small runtime 544 # compilation test. 545 # 546 cat > $TMPC <<EOF 547 /* this test should fail if the compiler generates 64-bit machine code */ 548 int test_array[1-2*(sizeof(void*) != 4)]; 549EOF 550 echo -n "Checking whether the compiler generates 32-bit binaries..." 551 HOST_GMP_ABI=32 552 log $CC $HOST_CFLAGS -c -o $TMPO $TMPC 553 $CC $HOST_CFLAGS -c -o $TMPO $TMPC >$TMPL 2>&1 554 if [ $? != 0 ] ; then 555 echo "no" 556 if [ "$TRY64" != "yes" ]; then 557 # NOTE: We need to modify the definitions of CC and CXX directly 558 # here. Just changing the value of CFLAGS / HOST_CFLAGS 559 # will not work well with the GCC toolchain scripts. 560 CC="$CC -m32" 561 CXX="$CXX -m32" 562 else 563 HOST_GMP_ABI=64 564 fi 565 else 566 echo "yes" 567 fi 568 569 # For now, we only support building 32-bit binaries anyway 570 if [ "$TRY64" != "yes" ]; then 571 force_32bit_binaries # to modify HOST_TAG and others 572 HOST_GMP_ABI="32" 573 fi 574 575 # Now handle the --mingw flag 576 if [ "$MINGW" = "yes" ] ; then 577 case $HOST_TAG in 578 linux-*) 579 ;; 580 *) 581 echo "ERROR: Can only enable mingw on Linux platforms !" 582 exit 1 583 ;; 584 esac 585 if [ "$TRY64" = "yes" ]; then 586 ABI_CONFIGURE_HOST=amd64-mingw32msvc 587 else 588 ABI_CONFIGURE_HOST=i586-mingw32msvc 589 fi 590 HOST_OS=windows 591 HOST_TAG=windows 592 HOST_EXE=.exe 593 # It turns out that we need to undefine this to be able to 594 # perform a canadian-cross build with mingw. Otherwise, the 595 # GMP configure scripts will not be called with the right options 596 HOST_GMP_ABI= 597 fi 598} 599 600parse_toolchain_name () 601{ 602 if [ -z "$TOOLCHAIN" ] ; then 603 echo "ERROR: Missing toolchain name!" 604 exit 1 605 fi 606 607 ABI_CFLAGS_FOR_TARGET= 608 ABI_CXXFLAGS_FOR_TARGET= 609 610 # Determine ABI based on toolchain name 611 # 612 case "$TOOLCHAIN" in 613 arm-eabi-*) 614 ARCH="arm" 615 ABI_CONFIGURE_TARGET="arm-eabi" 616 ABI_CONFIGURE_EXTRA_FLAGS="--with-binutils-version=2.19 --with-mpfr-version=2.3.0 --with-gmp-version=4.2.2" 617 ;; 618 arm-linux-androideabi-*) 619 ARCH="arm" 620 ABI_CONFIGURE_TARGET="arm-linux-androideabi" 621 ABI_CONFIGURE_EXTRA_FLAGS="--with-arch=armv5te" 622 # Disable ARM Gold linker for now, it doesn't build on Windows, it 623 # crashes with SIGBUS on Darwin, and produces weird executables on 624 # linux that strip complains about... Sigh. 625 #ABI_CONFIGURE_EXTRA_FLAGS="$ABI_CONFIGURE_EXTRA_FLAGS --enable-gold=both/gold" 626 627 # Enable C++ exceptions, RTTI and GNU libstdc++ at the same time 628 # You can't really build these separately at the moment. 629 ABI_CFLAGS_FOR_TARGET="-fexceptions" 630 ABI_CXXFLAGS_FOR_TARGET="-frtti" 631 ABI_CONFIGURE_EXTRA_FLAGS="$ABI_CONFIGURE_EXTRA_FLAGS --enable-libstdc__-v3" 632 # Stick to 6.6 for now. 7.1.x doesn't seem to work right now. 633 #GDB_VERSION=7.1.x 634 ;; 635 x86-*) 636 ARCH="x86" 637 ABI_INSTALL_NAME="x86" 638 ABI_CONFIGURE_TARGET="i686-android-linux" 639 # Enable C++ exceptions, RTTI and GNU libstdc++ at the same time 640 # You can't really build these separately at the moment. 641 ABI_CFLAGS_FOR_TARGET="-fexceptions -fPIC" 642 ABI_CXXFLAGS_FOR_TARGET="-frtti" 643 ABI_CONFIGURE_EXTRA_FLAGS="$ABI_CONFIGURE_EXTRA_FLAGS --enable-libstdc__-v3" 644 ;; 645 * ) 646 echo "Invalid toolchain specified. Expected (arm-eabi-*|x86-*)" 647 echo "" 648 print_help 649 exit 1 650 ;; 651 esac 652 653 log "Targetting CPU: $ARCH" 654 655 GCC_VERSION=`expr -- "$TOOLCHAIN" : '.*-\([0-9x\.]*\)'` 656 log "Using GCC version: $GCC_VERSION" 657 658 # Determine --host value when building gdbserver 659 case "$TOOLCHAIN" in 660 arm-*) 661 GDBSERVER_HOST=arm-eabi-linux 662 GDBSERVER_CFLAGS="-fno-short-enums" 663 ;; 664 x86-*) 665 GDBSERVER_HOST=i686-android-linux-gnu 666 GDBSERVER_CFLAGS= 667 ;; 668 esac 669 670} 671 672 673get_prebuilt_host_tag () 674{ 675 local RET=$HOST_TAG 676 case $RET in 677 linux-x86_64) 678 if [ "$TRY64" = "no" ]; then 679 RET=linux-x86 680 fi 681 ;; 682 darwin_x86_64) 683 if [ "$TRY64" = "no" ]; then 684 RET=darwin-x86 685 fi 686 ;; 687 esac 688 echo $RET 689} 690 691# Convert an ABI name into an Architecture name 692# $1: ABI name 693# Result: Arch name 694convert_abi_to_arch () 695{ 696 local RET 697 case $1 in 698 armeabi|armeabi-v7a) 699 RET=arm 700 ;; 701 x86) 702 RET=x86 703 ;; 704 *) 705 2> echo "ERROR: Unsupported ABI name: $1, use one of: armeabi, armeabi-v7a or x86" 706 exit 1 707 ;; 708 esac 709 echo "$RET" 710} 711 712# Retrieve the list of default ABIs supported by a given architecture 713# $1: Architecture name 714# Result: space-separated list of ABI names 715get_default_abis_for_arch () 716{ 717 local RET 718 case $1 in 719 arm) 720 RET="armeabi armeabi-v7a" 721 ;; 722 x86) 723 RET="x86" 724 ;; 725 *) 726 2> echo "ERROR: Unsupported architecture name: $1, use one of: arm x86" 727 exit 1 728 ;; 729 esac 730 echo "$RET" 731} 732 733# Return the default name for a given architecture 734# $1: Architecture name 735get_default_toolchain_name_for () 736{ 737 eval echo "\$DEFAULT_ARCH_TOOLCHAIN_$1" 738} 739 740# Return the default toolchain program prefix for a given architecture 741# $1: Architecture name 742get_default_toolchain_prefix_for () 743{ 744 eval echo "\$DEFAULT_ARCH_TOOLCHAIN_PREFIX_$1" 745} 746 747# Return the default binary path prefix for a given architecture 748# For example: arm -> toolchains/arm-linux-androideabi-4.4.3/prebuilt/<system>/bin/arm-linux-androideabi- 749# $1: Architecture name 750get_default_toolchain_binprefix_for_arch () 751{ 752 local NAME PREFIX DIR BINPREFIX 753 NAME=$(get_default_toolchain_name_for $1) 754 PREFIX=$(get_default_toolchain_prefix_for $1) 755 DIR=$(get_toolchain_install . $NAME) 756 BINPREFIX=${DIR#./}/bin/$PREFIX 757 echo "$BINPREFIX" 758} 759 760# Return default API level for a given arch 761# This is the level used to build the toolchains. 762# 763# $1: Architecture name 764get_default_api_level_for_arch () 765{ 766 # For now, always build the toolchain against API level 9 767 # (We have local toolchain patches under build/tools/toolchain-patches 768 # to ensure that the result works on previous platforms properly). 769 local LEVEL=9 770 echo $LEVEL 771} 772 773# Return the default platform sysroot corresponding to a given architecture 774# This is the sysroot used to build the toolchain and other binaries like 775# the STLport libraries. 776# $1: Architecture name 777get_default_platform_sysroot_for_arch () 778{ 779 local LEVEL=$(get_default_api_level_for_arch $1) 780 echo "platforms/android-$LEVEL/arch-$1" 781} 782 783# Guess what? 784get_default_platform_sysroot_for_abi () 785{ 786 local ARCH=$(convert_abi_to_arch $1) 787 $(get_default_platform_sysroot_for_arch $ARCH) 788} 789 790# Return the host/build specific path for prebuilt toolchain binaries 791# relative to $1. 792# 793# $1: target root NDK directory 794# $2: toolchain name 795# 796get_toolchain_install () 797{ 798 echo "$1/toolchains/$2/prebuilt/$(get_prebuilt_host_tag)" 799} 800 801 802# Set the toolchain target NDK location. 803# this sets TOOLCHAIN_PATH and TOOLCHAIN_PREFIX 804# $1: target NDK path 805# $2: toolchain name 806set_toolchain_ndk () 807{ 808 TOOLCHAIN_PATH=`get_toolchain_install "$1" $2` 809 log "Using toolchain path: $TOOLCHAIN_PATH" 810 811 TOOLCHAIN_PREFIX=$TOOLCHAIN_PATH/bin/$ABI_CONFIGURE_TARGET 812 log "Using toolchain prefix: $TOOLCHAIN_PREFIX" 813} 814 815# Check that a toolchain is properly installed at a target NDK location 816# 817# $1: target root NDK directory 818# $2: toolchain name 819# 820check_toolchain_install () 821{ 822 TOOLCHAIN_PATH=`get_toolchain_install "$1" $2` 823 if [ ! -d "$TOOLCHAIN_PATH" ] ; then 824 echo "ERROR: Toolchain '$2' not installed in '$NDK_DIR'!" 825 echo " Ensure that the toolchain has been installed there before." 826 exit 1 827 fi 828 829 set_toolchain_ndk $1 $2 830} 831 832 833# 834# The NDK_TMPDIR variable is used to specify a root temporary directory 835# when invoking toolchain build scripts. If it is not defined, we will 836# create one here, and export the value to ensure that any scripts we 837# call after that use the same one. 838# 839if [ -z "$NDK_TMPDIR" ]; then 840 NDK_TMPDIR=/tmp/ndk-$USER/tmp/build-$$ 841 mkdir -p $NDK_TMPDIR 842 if [ $? != 0 ]; then 843 echo "ERROR: Could not create NDK_TMPDIR: $NDK_TMPDIR" 844 exit 1 845 fi 846 export NDK_TMPDIR 847fi 848 849# 850# Common definitions 851# 852 853# Current list of platform levels we support 854# 855# Note: levels 6 and 7 are omitted since they have the same native 856# APIs as level 5. 857# 858API_LEVELS="3 4 5 8 9" 859 860# Location of the STLport sources, relative to the NDK root directory 861STLPORT_SUBDIR=sources/cxx-stl/stlport 862 863# Default ABIs for the prebuilt STLport binaries 864STLPORT_ABIS="armeabi armeabi-v7a" 865 866# Location of the GNU libstdc++ headers and libraries, relative to the NDK 867# root directory. 868GNUSTL_SUBDIR=sources/cxx-stl/gnu-libstdc++ 869 870# The date to use when downloading toolchain sources from android.git.kernel.org 871# Leave it empty for tip of tree. 872TOOLCHAIN_GIT_DATE=2011-02-23 873 874# Default toolchain names and prefix 875# 876# This is used by get_default_toolchain_name and get_default_toolchain_prefix 877# defined above 878DEFAULT_ARCH_TOOLCHAIN_arm=arm-linux-androideabi-4.4.3 879DEFAULT_ARCH_TOOLCHAIN_PREFIX_arm=arm-linux-androideabi- 880 881DEFAULT_ARCH_TOOLCHAIN_x86=x86-4.4.3 882DEFAULT_ARCH_TOOLCHAIN_PREFIX_x86=i686-android-linux- 883 884