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 and LLVM 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.9, 4.8, 4.7, 4.6, 4.4.3} x {arm, x86, mips} and
     41 LLVM {3.3, 3.4}.
     42 
     43 GCC passes -m flag for ld.mcld to figure out the right target.
     44 "
     45 NDK_DIR=
     46 register_var_option "--ndk-dir=<path>" NDK_DIR "NDK installation directory"
     47 
     48 PACKAGE_DIR=
     49 register_var_option "--package-dir=<path>" PACKAGE_DIR "Create archive tarball in specific directory"
     50 
     51 SYSTEMS=
     52 register_var_option "--systems=<list>" SYSTEMS "List of host systems to deply ld.mcld for"
     53 
     54 extract_parameters "$@"
     55 
     56 if [ -z "$NDK_DIR" ] ; then
     57     NDK_DIR=$ANDROID_NDK_ROOT
     58     log "Auto-config: --ndk-dir=$NDK_DIR"
     59 else
     60     if [ ! -d "$NDK_DIR" ] ; then
     61         echo "ERROR: NDK directory does not exists: $NDK_DIR"
     62         exit 1
     63     fi
     64 fi
     65 
     66 if [ "$PACKAGE_DIR" ]; then
     67     mkdir -p "$PACKAGE_DIR"
     68     fail_panic "Could not create package directory: $PACKAGE_DIR"
     69 fi
     70 
     71 cd $NDK_DIR
     72 
     73 if [ -z "$SYSTEMS" ]; then
     74     # find all ld.mcld
     75     ALL_MCLDS=`find toolchains/llvm-$DEFAULT_LLVM_VERSION -name "ld.mcld*"`
     76 
     77     for MCLD in $ALL_MCLDS; do
     78         # compute SYSTEM of this ld.mcld
     79         SYSTEM=${MCLD%%/bin/*}
     80         SYSTEM=${SYSTEM##*prebuilt/}
     81         SYSTEMS=$SYSTEMS" $SYSTEM"
     82     done
     83 fi
     84 
     85 for SYSTEM in $SYSTEMS; do
     86     HOST_EXE=
     87     if [ "$SYSTEM" != "${SYSTEM%%windows*}" ] ; then
     88         HOST_EXE=.exe
     89     fi
     90 
     91     MCLD=toolchains/llvm-$DEFAULT_LLVM_VERSION/prebuilt/$SYSTEM/bin/ld.mcld$HOST_EXE
     92     test -f "$MCLD" || fail_panic "Could not find $MCLD"
     93 
     94     ALL_LD_MCLDS=
     95 
     96     # find all GNU ld with the same SYSTEM
     97     ALL_LDS=`find toolchains \( -name "*-ld" -o -name "ld" -o -name "*-ld.exe" -o -name "ld.exe" \) | egrep "/arm|/x86|/mips|/aarch64" | grep $SYSTEM/`
     98     for LD in $ALL_LDS; do
     99         LD_NOEXE=${LD%%.exe}
    100         LD_MCLD=${LD_NOEXE}.mcld$HOST_EXE
    101         run rm -f "$LD_MCLD"
    102         if [ "$LD_NOEXE" != "${LD_NOEXE%%/ld}" ] ; then
    103           # ld in $ABI/bin/ld
    104             run ln -s "../../../../../../$MCLD" "$LD_MCLD"
    105         else
    106           # ld in bin/$ABI-ld
    107             run ln -s "../../../../../$MCLD" "$LD_MCLD"
    108         fi
    109         ALL_LD_MCLDS=$ALL_LD_MCLDS" $LD_MCLD"
    110     done
    111 
    112     # find all llvm-* which isn't llvm-$DEFAULT_LLVM_VERSION
    113     for LLVM in $DEFAULT_LLVM_VERSION_LIST; do
    114         if [ "$LLVM" != "$DEFAULT_LLVM_VERSION" ]; then
    115             LD_MCLD=toolchains/llvm-$LLVM/prebuilt/$SYSTEM/bin/ld.mcld$HOST_EXE
    116             run rm -f "$LD_MCLD"
    117             run ln -s "../../../../../$MCLD" "$LD_MCLD"
    118             ALL_LD_MCLDS=$ALL_LD_MCLDS" $LD_MCLD"
    119 	fi
    120     done
    121 
    122     # package
    123     if [ "$PACKAGE_DIR" ]; then
    124         ARCHIVE="ld.mcld-$SYSTEM.tar.bz2"
    125         #echo $ARCHIVE
    126         echo  "Packaging $ARCHIVE"
    127         pack_archive "$PACKAGE_DIR/$ARCHIVE" "$NDK_DIR" $ALL_LD_MCLDS
    128     fi
    129 done
    130 
    131 dump "Done."
    132