-
Notifications
You must be signed in to change notification settings - Fork 1
/
install-toolchain.sh
executable file
·95 lines (83 loc) · 2.74 KB
/
install-toolchain.sh
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
#!/bin/bash
TOOLCHAIN_RELEASE="${TOOLCHAIN_RELEASE:-2017.11-rc1}"
exact_toolchain_version="7.2-${TOOLCHAIN_RELEASE}"
exact_toolchain_version_filename="7.2.1-${TOOLCHAIN_RELEASE}"
toolchain_base_url="http://snapshots.linaro.org/components/toolchain/binaries"
ARCH=arm64
ABI="hf"
ABIDIR="-gnueabihf"
usage()
{
echo -e "\ta, ARCH, default: ${ARCH}"
echo -e "\tr, TOOLCHAIN_RELEASE: set toolchain release, default: ${TOOLCHAIN_RELEASE}"
echo -e "\t\t\t Only used when ARCH is given!"
echo -e "\t\t\t Linaros toolchain releases are located here:"
echo -e "\t\t\t ${toolchain_base_url}/${exact_toolchain_version}/"
echo -e "\tf, if set toolchain *-gnueabi-gcc are used, default: *-gnueabihf-gcc"
}
find_toolchain_to_download()
{
toolchain_url="${toolchain_base_url}/${exact_toolchain_version}/arm-linux-gnueabi${ABI}/gcc-linaro-${exact_toolchain_version_filename}-x86_64_arm-linux-gnueabi${ABI}.tar.xz"
[[ ${ARCH} == "arm64" ]] && toolchain_url="${toolchain_base_url}/${exact_toolchain_version}/aarch64-linux-gnu/gcc-linaro-${exact_toolchain_version_filename}-x86_64_aarch64-linux-gnu.tar.xz"
echo $toolchain_url
[[ ${ARCH} == "arm64" ]] && ABIDIR=""
export tcbindir="${tcbindir:-$HOME/$ARCH${ABIDIR}-tc-${TOOLCHAIN_RELEASE}/bin}"
mkdir -p $(dirname ${tcbindir})
}
install_custom_toolchain()
{
test -d ${tcbindir} && return 0
test -z "${toolchain_url}" && return 0
toolchain=`basename ${toolchain_url}`
test -f ${toolchain} || curl -sSOL ${toolchain_url}
mkdir -p `dirname ${tcbindir}`
unxz ${toolchain}
toolchain=${toolchain%.xz}
tar --strip-components=1 -C `dirname ${tcbindir}` -xf ${toolchain}
if [[ $? -ne 0 ]]; then
echo "NO toolchain to extract..."
exit 1
fi
}
setup_compiler_prefix()
{
export PATH="${tcbindir}:$PATH"
if [ "${ARCH}" = "arm" ]; then
compiler_prefix="arm-linux-gnueabi${ABI}"
elif [ "$ARCH" = "arm64" ]; then
compiler_prefix="aarch64-linux-gnu"
fi
[[ -n ${compiler_prefix} ]] && export CROSS_COMPILE=${compiler_prefix}-
}
toolchain_prepare()
{
[[ -z ${ARCH} ]] && return
[[ ${ARCH} == "x86_32" ]] && return
find_toolchain_to_download
install_custom_toolchain
setup_compiler_prefix
[[ -n ${compiler_prefix} ]] && export CROSS_HOST="--host=${compiler_prefix}"
}
tc_cleanup(){
rm -rf ${ROOT_DIR}/gcc-linaro-*
}
while getopts "a:r:fh" arg; do
case $arg in
a)
ARCH="$OPTARG"
;;
r)
TOOLCHAIN_RELEASE="$OPTARG"
;;
f)
ABI=""
ABIDIR="-gnueabi"
;;
h)
usage
exit 0
;;
esac
done
toolchain_prepare
## vim: set ft=sh sw=4 sts=4 et foldmethod=syntax : ##