Home | History | Annotate | Download | only in tools
      1 #!/bin/sh
      2 #
      3 # Copyright (C) 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 
     18 # Rebuild all prebuilts. This requires that you have a toolchain source tree
     19 #
     20 
     21 . `dirname $0`/prebuilt-common.sh
     22 PROGDIR=`dirname $0`
     23 
     24 NDK_DIR=$ANDROID_NDK_ROOT
     25 register_var_option "--ndk-dir=<path>" NDK_DIR "Put binaries into NDK install directory"
     26 
     27 BUILD_DIR=/tmp/ndk-$USER/build
     28 register_var_option "--build-dir=<path>" BUILD_DIR "Specify temporary build directory"
     29 
     30 ARCHS=$(find_ndk_unknown_archs)
     31 ARCHS="$DEFAULT_ARCHS $ARCHS"
     32 register_var_option "--arch=<arch>" ARCHS "Specify target architectures"
     33 
     34 NO_GEN_PLATFORMS=
     35 register_var_option "--no-gen-platforms" NO_GEN_PLATFORMS "Don't generate platforms/ directory, use existing one"
     36 
     37 GCC_VERSION_LIST="default" # it's arch defined by default so use default keyword
     38 register_var_option "--gcc-version-list=<vers>" GCC_VERSION_LIST "List of GCC release versions"
     39 
     40 LLVM_VERSION_LIST=$DEFAULT_LLVM_VERSION_LIST
     41 register_var_option "--llvm-version-list=<vers>" LLVM_VERSION_LIST "List of LLVM release versions"
     42 
     43 SYSTEMS=$HOST_TAG32
     44 if [ "$HOST_TAG32" = "linux-x86" ]; then
     45     SYSTEMS=$SYSTEMS",windows"
     46     # If darwin toolchain exist, build darwin too
     47     if [ -f "${DARWIN_TOOLCHAIN}-gcc" ]; then
     48         SYSTEMS=$SYSTEMS",darwin-x86"
     49     fi
     50 fi
     51 CUSTOM_SYSTEMS=
     52 register_option "--systems=<list>" do_SYSTEMS "Specify host systems"
     53 do_SYSTEMS () { CUSTOM_SYSTEMS=true; SYSTEMS=$1; }
     54 
     55 ALSO_64=
     56 register_option "--also-64" do_ALSO_64 "Also build 64-bit host toolchain"
     57 do_ALSO_64 () { ALSO_64=yes; }
     58 
     59 RELEASE=`date +%Y%m%d`
     60 PACKAGE_DIR=/tmp/ndk-$USER/prebuilt-$RELEASE
     61 register_var_option "--package-dir=<path>" PACKAGE_DIR "Put prebuilt tarballs into <path>."
     62 
     63 DARWIN_SSH=
     64 if [ "$HOST_OS" = "linux" ] ; then
     65 register_var_option "--darwin-ssh=<hostname>" DARWIN_SSH "Specify Darwin hostname for remote build."
     66 fi
     67 
     68 register_try64_option
     69 
     70 PROGRAM_PARAMETERS="<toolchain-src-dir>"
     71 PROGRAM_DESCRIPTION=\
     72 "This script is used to rebuild all host and target prebuilts from scratch.
     73 You will need to give the path of a toolchain source directory, one which
     74 is typically created with the download-toolchain-sources.sh script.
     75 
     76 Unless you use the --ndk-dir option, all binaries will be installed to the
     77 current NDK directory.
     78 
     79 All prebuilts will then be archived into tarball that will be stored into a
     80 specific 'package directory'. Unless you use the --package-dir option, this
     81 will be: $PACKAGE_DIR
     82 
     83 Please read docs/DEV-SCRIPTS-USAGE.TXT for more usage information about this
     84 script.
     85 "
     86 
     87 extract_parameters "$@"
     88 
     89 SRC_DIR="$PARAMETERS"
     90 check_toolchain_src_dir "$SRC_DIR"
     91 
     92 if [ "$DARWIN_SSH" -a -z "$CUSTOM_SYSTEMS" ]; then
     93     SYSTEMS=$SYSTEMS",darwin-x86"
     94 fi
     95 
     96 FLAGS=
     97 if [ "$DRYRUN" = "yes" ]; then
     98     FLAGS=$FLAGS" --dryrun"
     99 fi
    100 if [ "$VERBOSE" = "yes" ]; then
    101     FLAGS=$FLAGS" --verbose"
    102 fi
    103 if [ "$VERBOSE2" = "yes" ]; then
    104     FLAGS=$FLAGS" --verbose"
    105 fi
    106 FLAGS=$FLAGS" --ndk-dir=$NDK_DIR"
    107 FLAGS=$FLAGS" --package-dir=$PACKAGE_DIR"
    108 FLAGS=$FLAGS" --arch=$(spaces_to_commas $ARCHS)"
    109 
    110 if [ ! -z "$NO_GEN_PLATFORMS" ]; then
    111     FLAGS=$FLAGS" --no-gen-platforms"
    112 fi
    113 
    114 HOST_FLAGS=$FLAGS" --systems=$(spaces_to_commas $SYSTEMS)"
    115 if [ "$GCC_VERSION_LIST" != "default" ]; then
    116     HOST_FLAGS=$HOST_FLAGS" --gcc-version-list=$(spaces_to_commas $GCC_VERSION_LIST)"
    117 fi
    118 HOST_FLAGS=$HOST_FLAGS" --llvm-version-list=$(spaces_to_commas $LLVM_VERSION_LIST)"
    119 
    120 TARGET_FLAGS=$FLAGS
    121 
    122 if [ "$TRY64" = "yes" ]; then
    123     HOST_FLAGS=$HOST_FLAGS" --try-64"
    124     # If we build only 64-bit host we need to use this flag as well so that correct toolchain is found on target tools build
    125     TARGET_FLAGS=$TARGET_FLAGS" --try-64"
    126 fi
    127 if [ "$DARWIN_SSH" ]; then
    128     HOST_FLAGS=$HOST_FLAGS" --darwin-ssh=$DARWIN_SSH"
    129 fi
    130 
    131 if [ "$ALSO_64" = "yes" -a "$TRY64" != "yes" ] ; then
    132     echo "COMMAND: $PROGDIR/build-host-prebuilts.sh $HOST_FLAGS $SRC_DIR --try-64"
    133     $PROGDIR/build-host-prebuilts.sh $HOST_FLAGS "$SRC_DIR" --try-64
    134     fail_panic "Could not build host prebuilts in 64-bit!"
    135 fi
    136 echo "COMMAND: $PROGDIR/build-host-prebuilts.sh $HOST_FLAGS $SRC_DIR"
    137 $PROGDIR/build-host-prebuilts.sh $HOST_FLAGS "$SRC_DIR"
    138 fail_panic "Could not build host prebuilts!"
    139 
    140 if [ ! -z "$LLVM_VERSION_LIST" ]; then
    141     LLVM_VERSIONS=$(commas_to_spaces $LLVM_VERSION_LIST)
    142     LLVM_VERSION=${LLVM_VERSIONS%% *}
    143     TARGET_FLAGS=$TARGET_FLAGS" --llvm-version=$LLVM_VERSION"
    144     if [ "$GCC_VERSION_LIST" != "default" ]; then
    145        for ARCH in $(commas_to_spaces $ARCHS); do
    146          if [ "$ARCH" != "${ARCH%%64*}" ] ; then
    147            if [ "${GCC_VERSION_LIST%%$DEFAULT_LLVM_GCC64_VERSION*}" = "$GCC_VERSION_LIST" ]; then
    148               echo "ERROR: LLVM $LLVM_VERSION require GCC $DEFAULT_LLVM_GCC64_VERSION for $ARCH to be available. Try to include it in build list."
    149               exit 1
    150            fi
    151          else
    152            if [ "${GCC_VERSION_LIST%%$DEFAULT_LLVM_GCC32_VERSION*}" = "$GCC_VERSION_LIST" ]; then
    153               echo "ERROR: LLVM $LLVM_VERSION require GCC $DEFAULT_LLVM_GCC32_VERSION for $ARCH to be available. Try to include it in build list."
    154               exit 1
    155            fi
    156          fi
    157        done
    158     fi
    159 fi
    160 if [ "$GCC_VERSION_LIST" != "default" ]; then
    161    TARGET_FLAGS=$TARGET_FLAGS" --gcc-version-list=$(spaces_to_commas $GCC_VERSION_LIST)"
    162 fi
    163 
    164 echo "COMMAND: $PROGDIR/build-target-prebuilts.sh $TARGET_FLAGS $SRC_DIR"
    165 $PROGDIR/build-target-prebuilts.sh $TARGET_FLAGS "$SRC_DIR"
    166 fail_panic "Could not build target prebuilts!"
    167 
    168 echo "Done, see $PACKAGE_DIR:"
    169 ls -l $PACKAGE_DIR
    170 
    171 exit 0
    172