1
1
#! /bin/bash
2
2
3
- # 定义工具链下载链接
4
3
declare -A download_urls=(
5
4
[" arm-none-eabi-gcc" ]=" https://github.com/RT-Thread/toolchains-ci/releases/download/v1.3/gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2"
6
- [" mips-sde-elf-gcc" ]=" https://github.com/RT-Thread/toolchains-ci/releases/download/v1.6/gcc-arm-10.2-2020.11-x86_64-aarch64-none-elf.tar.xz"
5
+ [" mips-sde-elf-gcc" ]=" https://github.com/RT-Thread/toolchains-ci/releases/download/v1.1/mips-2016.05-7-mips-sde-elf-i686-pc-linux-gnu.tar.bz2"
6
+ [" aarch64-none-elf-gcc" ]=" https://github.com/RT-Thread/toolchains-ci/releases/download/v1.6/gcc-arm-10.2-2020.11-x86_64-aarch64-none-elf.tar.xz"
7
7
[" riscv64-unknown-elf-gcc" ]=" https://github.com/RT-Thread/toolchains-ci/releases/download/v1.4/riscv64-unknown-elf-toolchain-10.2.0-2020.12.8-x86_64-linux-ubuntu14.tar.gz"
8
8
[" riscv32-unknown-elf-gcc" ]=" https://github.com/hpmicro/riscv-gnu-toolchain/releases/download/2022.05.15/riscv32-unknown-elf-newlib-multilib_2022.05.15_linux.tar.gz"
9
- [" llvm-arm" ]=" https://github.com/ARM-software/LLVM-embedded-toolchain-for-Arm/releases/download/release-16.0.0/LLVMEmbeddedToolchainForArm-16.0.0-Linux-x86_64.tar.gz"
10
9
[" riscv-none-embed-gcc" ]=" https://github.com/RT-Thread/toolchains-ci/releases/download/v1.5/xpack-riscv-none-embed-gcc-8.3.0-2.3-linux-x64.tar.gz"
11
10
[" riscv32-esp-elf-gcc" ]=" https://github.com/espressif/crosstool-NG/releases/download/esp-2022r1-RC1/riscv32-esp-elf-gcc11_2_0-esp-2022r1-RC1-linux-amd64.tar.xz"
12
11
[" clang" ]=" https://github.com/ARM-software/LLVM-embedded-toolchain-for-Arm/releases/download/release-16.0.0/LLVMEmbeddedToolchainForArm-16.0.0-Linux-x86_64.tar.gz"
@@ -22,16 +21,18 @@ show_help() {
22
21
23
22
extract_file () {
24
23
local file_name=$1
25
- local destination=${2:-/ opt} # 默认解压到/opt目录
24
+ local destination=$2
25
+ echo " Extracting $file_name to $destination ..."
26
26
case " $file_name " in
27
- * .tar.bz2) tar -xjf " $file_name " -C " $destination " ;;
28
- * .tar.gz) tar -xzf " $file_name " -C " $destination " ;;
29
- * .tar.xz) tar -xJf " $file_name " -C " $destination " ;;
27
+ * .tar.bz2) tar -xjf " $file_name " -C " $destination " --strip-components=1 ;;
28
+ * .tar.gz) tar -xzf " $file_name " -C " $destination " --strip-components=1 ;;
29
+ * .tar.xz) tar -xJf " $file_name " -C " $destination " --strip-components=1 ;;
30
30
* ) echo " Unsupported file format: $file_name " ; exit 1;;
31
31
esac
32
32
echo " Extracted to $destination "
33
33
}
34
34
35
+
35
36
install_toolchain () {
36
37
local toolchain_name=$1
37
38
local url=" ${download_urls[$toolchain_name]} "
@@ -43,17 +44,49 @@ install_toolchain() {
43
44
echo " Downloading $file_name ..."
44
45
wget -q " $url "
45
46
echo " Extracting $file_name ..."
46
- extract_file " $file_name "
47
- local extracted_dir=" /opt/$( basename " $file_name " .tar.* ) "
48
- echo " Installed: $extracted_dir "
47
+
48
+ local target_dir=" /opt/$toolchain_name "
49
+ echo " target_dir $target_dir ..."
50
+ mkdir -p " $target_dir "
51
+ extract_file " $file_name " " $target_dir "
52
+
53
+ rm $file_name
54
+
55
+ echo " Installed: $target_dir "
56
+
57
+ local toolchain_bin=" $target_dir /bin"
58
+ if [[ " :$PATH :" != * " :$toolchain_bin :" * ]]; then
59
+ echo " Adding $toolchain_bin to PATH..."
60
+ export PATH=" $PATH :$toolchain_bin "
61
+ echo " export PATH=\$ PATH:$toolchain_bin " >> ~ /.bashrc
62
+ fi
63
+ # need source toolchain.sh or source ~/.bashrc to work
64
+
65
+ # local toolchain_exec=$(find "$toolchain_bin" -type f -executable | head -n 1)
66
+ local toolchain_exec=$( which " $toolchain_name " )
67
+ if [ -x " $toolchain_exec " ]; then
68
+ echo " Testing executable: $toolchain_exec "
69
+ $toolchain_exec --version
70
+ else
71
+ echo " No executable found in $toolchain_bin "
72
+ fi
49
73
}
50
74
51
- if [[ " $1 " == " help" ]]; then
52
- show_help
53
- elif [ " $1 " == " all" ]; then
54
- for toolchain in " ${! download_urls[@]} " ; do
55
- install_toolchain " $toolchain "
56
- done
75
+ if [[ $# -eq 1 ]]; then
76
+ if [[ " $1 " == " help" ]]; then
77
+ show_help
78
+ elif [ " $1 " == " all" ]; then
79
+ for toolchain in " ${! download_urls[@]} " ; do
80
+ install_toolchain " $toolchain "
81
+ done
82
+ else
83
+ install_toolchain " $1 "
84
+ fi
57
85
else
58
- install_toolchain " $1 "
86
+ show_help
59
87
fi
88
+
89
+
90
+
91
+
92
+
0 commit comments