Skip to content

Commit

Permalink
add toolchain/bin
Browse files Browse the repository at this point in the history
  • Loading branch information
supperthomas committed Sep 16, 2024
1 parent d35a73c commit 32ae0ea
Showing 1 changed file with 50 additions and 17 deletions.
67 changes: 50 additions & 17 deletions tools/ci/toolchain.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#!/bin/bash

# 定义工具链下载链接
declare -A download_urls=(
["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"
["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"
["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"
["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"
["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"
["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"
["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"
["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"
["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"
["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"
Expand All @@ -22,16 +21,18 @@ show_help() {

extract_file() {
local file_name=$1
local destination=${2:-/opt} # 默认解压到/opt目录
local destination=$2
echo "Extracting $file_name to $destination..."
case "$file_name" in
*.tar.bz2) tar -xjf "$file_name" -C "$destination";;
*.tar.gz) tar -xzf "$file_name" -C "$destination";;
*.tar.xz) tar -xJf "$file_name" -C "$destination";;
*.tar.bz2) tar -xjf "$file_name" -C "$destination" --strip-components=1;;
*.tar.gz) tar -xzf "$file_name" -C "$destination" --strip-components=1;;
*.tar.xz) tar -xJf "$file_name" -C "$destination" --strip-components=1;;
*) echo "Unsupported file format: $file_name"; exit 1;;
esac
echo "Extracted to $destination"
}


install_toolchain() {
local toolchain_name=$1
local url="${download_urls[$toolchain_name]}"
Expand All @@ -43,17 +44,49 @@ install_toolchain() {
echo "Downloading $file_name..."
wget -q "$url"
echo "Extracting $file_name..."
extract_file "$file_name"
local extracted_dir="/opt/$(basename "$file_name" .tar.*)"
echo "Installed: $extracted_dir"

local target_dir="/opt/$toolchain_name"
echo "target_dir $target_dir..."
mkdir -p "$target_dir"
extract_file "$file_name" "$target_dir"

rm $file_name

echo "Installed: $target_dir"

local toolchain_bin="$target_dir/bin"
if [[ ":$PATH:" != *":$toolchain_bin:"* ]]; then
echo "Adding $toolchain_bin to PATH..."
export PATH="$PATH:$toolchain_bin"
echo "export PATH=\$PATH:$toolchain_bin" >> ~/.bashrc
fi
#need source toolchain.sh or source ~/.bashrc to work

#local toolchain_exec=$(find "$toolchain_bin" -type f -executable | head -n 1)
local toolchain_exec=$(which "$toolchain_name")
if [ -x "$toolchain_exec" ]; then
echo "Testing executable: $toolchain_exec"
$toolchain_exec --version
else
echo "No executable found in $toolchain_bin"
fi
}

if [[ "$1" == "help" ]]; then
show_help
elif [ "$1" == "all" ]; then
for toolchain in "${!download_urls[@]}"; do
install_toolchain "$toolchain"
done
if [[ $# -eq 1 ]]; then
if [[ "$1" == "help" ]]; then
show_help
elif [ "$1" == "all" ]; then
for toolchain in "${!download_urls[@]}"; do
install_toolchain "$toolchain"
done
else
install_toolchain "$1"
fi
else
install_toolchain "$1"
show_help
fi





0 comments on commit 32ae0ea

Please sign in to comment.