|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +declare -A download_urls=( |
| 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" |
| 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 | +["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 | +["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 | +["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" |
| 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" |
| 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" |
| 12 | + |
| 13 | +) |
| 14 | + |
| 15 | +show_help() { |
| 16 | + echo "Available toolchains:" |
| 17 | + for key in "${!download_urls[@]}"; do |
| 18 | + echo " - $key" |
| 19 | + done |
| 20 | +} |
| 21 | + |
| 22 | +extract_file() { |
| 23 | + local file_name=$1 |
| 24 | + local destination=$2 |
| 25 | + echo "Extracting $file_name to $destination..." |
| 26 | + case "$file_name" in |
| 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 | + *) echo "Unsupported file format: $file_name"; exit 1;; |
| 31 | + esac |
| 32 | + echo "Extracted to $destination" |
| 33 | +} |
| 34 | + |
| 35 | + |
| 36 | +install_toolchain() { |
| 37 | + local toolchain_name=$1 |
| 38 | + local url="${download_urls[$toolchain_name]}" |
| 39 | + if [ -z "$url" ]; then |
| 40 | + echo "Toolchain not found." |
| 41 | + exit 1 |
| 42 | + fi |
| 43 | + local file_name=$(basename "$url") |
| 44 | + echo "Downloading $file_name..." |
| 45 | + wget -q "$url" |
| 46 | + echo "Extracting $file_name..." |
| 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 |
| 73 | +} |
| 74 | + |
| 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 |
| 85 | +else |
| 86 | + show_help |
| 87 | +fi |
0 commit comments