Home | History | Annotate | Download | only in tools
      1 #!/bin/sh
      2 #
      3 # Copyright (C) 2013 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 # Rebuild the host GCC toolchain binaries from sources.
     18 #
     19 # NOTE: this script does not rebuild gdb, see build-host-gdb.sh for this.
     20 #
     21 
     22 # include common function and variable definitions
     23 . `dirname $0`/prebuilt-common.sh
     24 
     25 PROGRAM_PARAMETERS=""
     26 PROGRAM_DESCRIPTION="\
     27 This program is used to deploy mclinker (ld.mcld) to GCC directories.
     28 Although ld.mcld depends on lots of LLVM modules and is built in
     29 build-llvm.sh to reduce long LLVM compilation time, it can be used as
     30 a drop-in replacement for ld.bfd and ld.gold in GCC.
     31 
     32 Running after completion of both build-llvm.sh and build-[host-]gcc.sh,
     33 this script copy toolchains/llvm-$DEFAULT_LLVM_VERSION/prebuilt/$SYSTEM/bin/ld.mcld[.exe]
     34 to be sibling of ld in all GCC directories with same HOST_OS and bitness,
     35 ie. {linux, darwin, windows} x {64, 32}
     36 
     37 If --systems isn't specified, this script discovers all ld.mcld[.exe] in
     38 toolchains/llvm-$DEFAULT_LLVM_VERSION
     39 
     40 Note that one copy of ld.mcld serves all GCC {4.8, 4.7, 4.6, 4.4.3} x {arm, x86, mips}.
     41 GCC passes -m flag for ld.mcld to figure out the right target.
     42 "
     43 NDK_DIR=
     44 register_var_option "--ndk-dir=<path>" NDK_DIR "NDK installation directory"
     45 
     46 PACKAGE_DIR=
     47 register_var_option "--package-dir=<path>" PACKAGE_DIR "Create archive tarball in specific directory"
     48 
     49 SYSTEMS=
     50 register_var_option "--systems=<list>" SYSTEMS "List of host systems to deply ld.mcld for"
     51 
     52 extract_parameters "$@"
     53 
     54 if [ -z "$NDK_DIR" ] ; then
     55     NDK_DIR=$ANDROID_NDK_ROOT
     56     log "Auto-config: --ndk-dir=$NDK_DIR"
     57 else
     58     if [ ! -d "$NDK_DIR" ] ; then
     59         echo "ERROR: NDK directory does not exists: $NDK_DIR"
     60         exit 1
     61     fi
     62 fi
     63 
     64 if [ "$PACKAGE_DIR" ]; then
     65     mkdir -p "$PACKAGE_DIR"
     66     fail_panic "Could not create package directory: $PACKAGE_DIR"
     67 fi
     68 
     69 cd $NDK_DIR
     70 
     71 if [ -z "$SYSTEMS" ]; then
     72     # find all ld.mcld
     73     ALL_MCLDS=`find toolchains/llvm-$DEFAULT_LLVM_VERSION -name "ld.mcld*"`
     74 
     75     for MCLD in $ALL_MCLDS; do
     76         # compute SYSTEM of this ld.mcld
     77         SYSTEM=${MCLD%%/bin/*}
     78         SYSTEM=${SYSTEM##*prebuilt/}
     79         SYSTEMS=$SYSTEMS" $SYSTEM"
     80     done
     81 fi
     82 
     83 for SYSTEM in $SYSTEMS; do
     84     HOST_EXE=
     85     if [ "$SYSTEM" != "${SYSTEM%%windows*}" ] ; then
     86         HOST_EXE=.exe
     87     fi
     88 
     89     MCLD=toolchains/llvm-$DEFAULT_LLVM_VERSION/prebuilt/$SYSTEM/bin/ld.mcld$HOST_EXE
     90     test -f "$MCLD" || fail_panic "Could not find $MCLD"
     91 
     92     # find all GNU ld with the same SYSTEM
     93     ALL_LDS=`find toolchains \( -name "*-ld" -o -name "ld" -o -name "*-ld.exe" -o -name "ld.exe" \) | egrep "/arm|/x86|/mips" | grep $SYSTEM/`
     94 
     95     ALL_LD_MCLDS=
     96     for LD in $ALL_LDS; do
     97         LD_NOEXE=${LD%%.exe}
     98         LD_MCLD=${LD_NOEXE}.mcld$HOST_EXE
     99         run rm -f "$LD_MCLD"
    100         if [ "$LD_NOEXE" != "${LD_NOEXE%%/ld}" ] ; then
    101           # ld in $ABI/bin/ld
    102             run ln -s "../../../../../../$MCLD" "$LD_MCLD"
    103         else
    104           # ld in bin/$ABI-ld
    105             run ln -s "../../../../../$MCLD" "$LD_MCLD"
    106         fi
    107         ALL_LD_MCLDS=$ALL_LD_MCLDS" $LD_MCLD"
    108     done
    109 
    110     # package
    111     if [ "$PACKAGE_DIR" ]; then
    112         ARCHIVE="ld.mcld-$SYSTEM.tar.bz2"
    113         #echo $ARCHIVE
    114         echo  "Packaging $ARCHIVE"
    115         pack_archive "$PACKAGE_DIR/$ARCHIVE" "$NDK_DIR" $ALL_LD_MCLDS
    116     fi
    117 done
    118 
    119 dump "Done."
    120