-
Notifications
You must be signed in to change notification settings - Fork 14
/
install-toolchain.sh
executable file
·75 lines (59 loc) · 2.11 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
#!/bin/bash
# set -x # display execution trace
########################################################
# Toolchain name
TOOLCHAIN_NAME=rv64gc-multilib
TOOLCHAIN_CONFIG=--enable-multilib
BUILD_JOBS=4
# Toolchain install root directory (Note: Toolchain will be installed inside a folder named TOOLCHAIN_NAME in the TOOLCHAIN_ROOTPATH)
TOOLCHAIN_ROOTPATH=/home/${user}/opt/riscv
#########################################################
# You sould not change anything below this
TOOLCHAIN_INSTALL_PATH=${TOOLCHAIN_ROOTPATH}/${TOOLCHAIN_NAME}
BUILD_DIR=build/${TOOLCHAIN_NAME}
CWDIR=$(pwd)
RED="\e[31m"
GREEN="\e[32m"
ORANGE="\e[33m"
NOCOLOR="\e[0m"
# Checking for any existing toolchain installation
echo -e "${GREEN}Checking for any existing toolchains...${NOCOLOR}"
if [ -d ${TOOLCHAIN_INSTALL_PATH} ]
then
echo "Found an existing installation of ${TOOLCHAIN_NAME}"
read -p "This operation will remove it completely, Are you sure? [y/n] " -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]
then
# Remove installation
echo -e "${GREEN}Removing existing toolchain... ${NOCOLOR}"
rm -rf ${TOOLCHAIN_INSTALL_PATH}/*
else
echo -e "${RED}Abort ${NOCOLOR}"
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1
fi
else
echo "Not found"
# Create installation directory
mkdir -p ${TOOLCHAIN_INSTALL_PATH}
fi
echo -e "${GREEN}Building toolchain... ${NOCOLOR}"
# Create build directory
rm -rf ${BUILD_DIR}
mkdir -p ${BUILD_DIR}
# Build toolchain
cd ${BUILD_DIR}
echo "../../configure --prefix=$(pwd) ${TOOLCHAIN_CONFIG}"
../../configure --prefix=$(pwd) ${TOOLCHAIN_CONFIG}
echo "make -j${BUILD_JOBS}"
make -j${BUILD_JOBS}
# Copy files to the installation directory
echo -e "${GREEN}Copying... ${NOCOLOR}"
rsync -r --progress * ${TOOLCHAIN_INSTALL_PATH}/
cd ${CWDIR}
echo "*** Toolchain Installation Successful! ***"
echo "Toolchain : ${TOOLCHAIN_NAME}"
echo "Install location : ${TOOLCHAIN_INSTALL_PATH}"
echo ""
echo "You should now append the following lines to your \".bashrc\" file"
echo " export PATH=\"${TOOLCHAIN_INSTALL_PATH}/bin:\$PATH\""