aboutsummaryrefslogtreecommitdiff
path: root/build/tools/deploy-host-mcld.sh
blob: 2b2cd1e1bd562760cca87ea989bf05bdf3a65214 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/bin/sh
#
# Copyright (C) 2013 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Rebuild the host GCC toolchain binaries from sources.
#
# NOTE: this script does not rebuild gdb, see build-host-gdb.sh for this.
#

# include common function and variable definitions
. `dirname $0`/prebuilt-common.sh

PROGRAM_PARAMETERS=""
PROGRAM_DESCRIPTION="\
This program is used to deploy mclinker (ld.mcld) to GCC directories.
Although ld.mcld depends on lots of LLVM modules and is built in
build-llvm.sh to reduce long LLVM compilation time, it can be used as
a drop-in replacement for ld.bfd and ld.gold in GCC.

Running after completion of both build-llvm.sh and build-[host-]gcc.sh,
this script copy toolchains/llvm-$DEFAULT_LLVM_VERSION/prebuilt/$SYSTEM/bin/ld.mcld[.exe]
to be sibling of ld in all GCC and LLVM directories with same HOST_OS and bitness,
ie. {linux, darwin, windows} x {64, 32}

If --systems isn't specified, this script discovers all ld.mcld[.exe] in
toolchains/llvm-$DEFAULT_LLVM_VERSION

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
LLVM {3.4, 3.5}.

GCC passes -m flag for ld.mcld to figure out the right target.
"
NDK_DIR=
register_var_option "--ndk-dir=<path>" NDK_DIR "NDK installation directory"

PACKAGE_DIR=
register_var_option "--package-dir=<path>" PACKAGE_DIR "Create archive tarball in specific directory"

SYSTEMS=
register_var_option "--systems=<list>" SYSTEMS "List of host systems to deply ld.mcld for"

extract_parameters "$@"

if [ -z "$NDK_DIR" ] ; then
    NDK_DIR=$ANDROID_NDK_ROOT
    log "Auto-config: --ndk-dir=$NDK_DIR"
else
    if [ ! -d "$NDK_DIR" ] ; then
        echo "ERROR: NDK directory does not exists: $NDK_DIR"
        exit 1
    fi
fi

if [ "$PACKAGE_DIR" ]; then
    mkdir -p "$PACKAGE_DIR"
    fail_panic "Could not create package directory: $PACKAGE_DIR"
fi

cd $NDK_DIR

if [ -z "$SYSTEMS" ]; then
    # find all ld.mcld
    ALL_MCLDS=`find toolchains/llvm-$DEFAULT_LLVM_VERSION -name "ld.mcld*"`

    for MCLD in $ALL_MCLDS; do
        # compute SYSTEM of this ld.mcld
        SYSTEM=${MCLD%%/bin/*}
        SYSTEM=${SYSTEM##*prebuilt/}
        SYSTEMS=$SYSTEMS" $SYSTEM"
    done
fi

for SYSTEM in $SYSTEMS; do
    HOST_EXE=
    if [ "$SYSTEM" != "${SYSTEM%%windows*}" ] ; then
        HOST_EXE=.exe
    fi

    MCLD=toolchains/llvm-$DEFAULT_LLVM_VERSION/prebuilt/$SYSTEM/bin/ld.mcld$HOST_EXE
    test -f "$MCLD" || fail_panic "Could not find $MCLD"

    ALL_LD_MCLDS=

    # find all GNU ld with the same SYSTEM
    ALL_LDS=`find toolchains \( -name "*-ld" -o -name "ld" -o -name "*-ld.exe" -o -name "ld.exe" \) | egrep "/arm|/x86|/mips|/aarch64" | grep $SYSTEM/`
    for LD in $ALL_LDS; do
        LD_NOEXE=${LD%%.exe}
        LD_MCLD=${LD_NOEXE}.mcld$HOST_EXE
        run rm -f "$LD_MCLD"
        if [ "$LD_NOEXE" != "${LD_NOEXE%%/ld}" ] ; then
          # ld in $ABI/bin/ld
            run ln -s "../../../../../../$MCLD" "$LD_MCLD"
        else
          # ld in bin/$ABI-ld
            run ln -s "../../../../../$MCLD" "$LD_MCLD"
        fi
        ALL_LD_MCLDS=$ALL_LD_MCLDS" $LD_MCLD"
    done

    # find all llvm-* which isn't llvm-$DEFAULT_LLVM_VERSION
    for LLVM in $DEFAULT_LLVM_VERSION_LIST; do
        if [ "$LLVM" != "$DEFAULT_LLVM_VERSION" ]; then
            LD_MCLD=toolchains/llvm-$LLVM/prebuilt/$SYSTEM/bin/ld.mcld$HOST_EXE
            run rm -f "$LD_MCLD"
            run ln -s "../../../../../$MCLD" "$LD_MCLD"
            ALL_LD_MCLDS=$ALL_LD_MCLDS" $LD_MCLD"
	fi
    done

    # package
    if [ "$PACKAGE_DIR" ]; then
        ARCHIVE="ld.mcld-$SYSTEM.tar.bz2"
        #echo $ARCHIVE
        echo  "Packaging $ARCHIVE"
        pack_archive "$PACKAGE_DIR/$ARCHIVE" "$NDK_DIR" $ALL_LD_MCLDS
    fi
done

dump "Done."