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 25PROGRAM_PARAMETERS="" 26PROGRAM_DESCRIPTION="\ 27This program is used to deploy mclinker (ld.mcld) to GCC directories. 28Although ld.mcld depends on lots of LLVM modules and is built in 29build-llvm.sh to reduce long LLVM compilation time, it can be used as 30a drop-in replacement for ld.bfd and ld.gold in GCC. 31 32Running after completion of both build-llvm.sh and build-[host-]gcc.sh, 33this script copy toolchains/llvm-$DEFAULT_LLVM_VERSION/prebuilt/$SYSTEM/bin/ld.mcld[.exe] 34to be sibling of ld in all GCC directories with same HOST_OS and bitness, 35ie. {linux, darwin, windows} x {64, 32} 36 37If --systems isn't specified, this script discovers all ld.mcld[.exe] in 38toolchains/llvm-$DEFAULT_LLVM_VERSION 39 40Note that one copy of ld.mcld serves all GCC {4.8, 4.7, 4.6, 4.4.3} x {arm, x86, mips}. 41GCC passes -m flag for ld.mcld to figure out the right target. 42" 43NDK_DIR= 44register_var_option "--ndk-dir=<path>" NDK_DIR "NDK installation directory" 45 46PACKAGE_DIR= 47register_var_option "--package-dir=<path>" PACKAGE_DIR "Create archive tarball in specific directory" 48 49SYSTEMS= 50register_var_option "--systems=<list>" SYSTEMS "List of host systems to deply ld.mcld for" 51 52extract_parameters "$@" 53 54if [ -z "$NDK_DIR" ] ; then 55 NDK_DIR=$ANDROID_NDK_ROOT 56 log "Auto-config: --ndk-dir=$NDK_DIR" 57else 58 if [ ! -d "$NDK_DIR" ] ; then 59 echo "ERROR: NDK directory does not exists: $NDK_DIR" 60 exit 1 61 fi 62fi 63 64if [ "$PACKAGE_DIR" ]; then 65 mkdir -p "$PACKAGE_DIR" 66 fail_panic "Could not create package directory: $PACKAGE_DIR" 67fi 68 69cd $NDK_DIR 70 71if [ -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 81fi 82 83for 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 117done 118 119dump "Done." 120