|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +set -euo pipefail |
| 4 | + |
| 5 | +# Defaults |
| 6 | +SKIP_RISCV=${SKIP_RISCV-0} |
| 7 | +SKIP_OPENOCD=${SKIP_OPENOCD-0} |
| 8 | + |
| 9 | +# Install prerequisites |
| 10 | +/usr/local/bin/brew install jq libtool libusb automake hidapi --quiet |
| 11 | +# RISC-V prerequisites |
| 12 | +echo "Listing local" |
| 13 | +ls /usr/local/bin |
| 14 | +rm /usr/local/bin/2to3* |
| 15 | +rm /usr/local/bin/idle3* |
| 16 | +rm /usr/local/bin/pip* |
| 17 | +rm /usr/local/bin/py* |
| 18 | +/usr/local/bin/brew install python3 gawk gnu-sed gmp mpfr libmpc isl zlib expat texinfo flock libslirp --quiet |
| 19 | + |
| 20 | +repos=$(cat config/repositories.json | jq -c '.repositories.[]') |
| 21 | +export version=$(cat ./version.txt) |
| 22 | +suffix="mac" |
| 23 | +builddir="build" |
| 24 | + |
| 25 | +# nproc alias |
| 26 | +alias nproc="sysctl -n hw.logicalcpu" |
| 27 | + |
| 28 | +mkdir -p $builddir |
| 29 | +mkdir -p "bin" |
| 30 | + |
| 31 | +while read -r repo |
| 32 | +do |
| 33 | + tree=$(echo "$repo" | jq -r .tree) |
| 34 | + href=$(echo "$repo" | jq -r .href) |
| 35 | + filename=$(basename -- "$href") |
| 36 | + extension="${filename##*.}" |
| 37 | + filename="${filename%.*}" |
| 38 | + filename=${filename%"-rp2350"} |
| 39 | + repodir="$builddir/${filename}" |
| 40 | + |
| 41 | + echo "${href} ${tree} ${filename} ${extension} ${repodir}" |
| 42 | + rm -rf "${repodir}" |
| 43 | + git clone -b "${tree}" --depth=1 -c advice.detachedHead=false "${href}" "${repodir}" |
| 44 | +done < <(echo "$repos") |
| 45 | + |
| 46 | + |
| 47 | +cd $builddir |
| 48 | +if [[ "$SKIP_OPENOCD" != 1 ]]; then |
| 49 | + if ! ../packages/macos/openocd/build-openocd.sh; then |
| 50 | + echo "OpenOCD Build failed" |
| 51 | + SKIP_OPENOCD=1 |
| 52 | + fi |
| 53 | +fi |
| 54 | +if [[ "$SKIP_RISCV" != 1 ]]; then |
| 55 | + # Takes ages to build |
| 56 | + ../packages/macos/riscv/build-riscv-gcc.sh |
| 57 | +fi |
| 58 | + |
| 59 | +topd=$PWD |
| 60 | +if [[ "$SKIP_OPENOCD" != 1 ]]; then |
| 61 | + # Package OpenOCD separately as well |
| 62 | + |
| 63 | + version=($("./$builddir/openocd-install/usr/local/bin/openocd" --version 2>&1)) |
| 64 | + version=${version[0]} |
| 65 | + version=${version[3]} |
| 66 | + version=$(echo $version | cut -d "-" -f 1) |
| 67 | + |
| 68 | + echo "OpenOCD version $version" |
| 69 | + |
| 70 | + filename="openocd-${version}-x64-${suffix}.zip" |
| 71 | + |
| 72 | + echo "Saving OpenOCD package to $filename" |
| 73 | + pushd "$builddir/openocd-install/usr/local/bin" |
| 74 | + tar -a -cf "$topd/bin/$filename" * -C "../share/openocd" "scripts" |
| 75 | + popd |
| 76 | +fi |
| 77 | + |
| 78 | +if [[ "$SKIP_RISCV" != 1 ]]; then |
| 79 | + # Package riscv toolchain separately as well |
| 80 | + version="14" |
| 81 | + echo "Risc-V Toolchain version $version" |
| 82 | + |
| 83 | + filename="riscv-toolchain-${version}-x64-${suffix}.zip" |
| 84 | + |
| 85 | + echo "Saving RISC-V Toolchain package to $filename" |
| 86 | + pushd "$builddir/riscv-install/" |
| 87 | + tar -a -cf "$topd/bin/$filename" * |
| 88 | + popd |
| 89 | +fi |
0 commit comments