Last active
December 30, 2022 01:18
-
-
Save nanoant/fc76f0c03c249d81f515a3727f15e8b8 to your computer and use it in GitHub Desktop.
Builds GD32V riscv-gnu-toolchain on macOS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Builds GD32V riscv-gnu-toolchain on macOS | |
# | |
# Author: Adam Strzelecki <[email protected]> | |
# Released under MIT license. | |
# | |
# Assumes HomeBrew is installed and following packages too: | |
# brew install python3 gawk gnu-sed gmp mpfr libmpc isl zlib expat | |
# | |
# See: | |
# https://github.com/riscv-mcu/riscv-gnu-toolchain/blob/nuclei-master/Build_Nuclei.md | |
# https://github.com/riscv-collab/riscv-gnu-toolchain | |
# https://github.com/sipeed/platform-gd32v/issues/6 | |
# https://github.com/riscv-collab/riscv-gnu-toolchain/issues/509 | |
# | |
# Notes: | |
# Build uses approx. 6.4GB, sources use approx. 6.8GB. | |
# To save the disk from wear and make build run faster we can use 16GB ram-disk: | |
# ramdisk 16 && mdutil -i off -d /Volumes/RAM | |
# Build takes approx 15-20 min on mini i7-8700B. | |
# Tested on macOS Catalina 10.15.7 | |
# | |
# Usage: | |
# Go to /tmp or create 16GB ram-disk and cd into it, and then run this script. | |
# | |
set -e | |
set -x | |
srcdir=riscv-gnu-toolchain | |
prefix=$HOME/.platformio/packages/toolchain-gd32v | |
[ -d $srcdir ] || git clone --recursive --depth=1 https://github.com/riscv-mcu/riscv-gnu-toolchain.git $srcdir | |
cd $srcdir/riscv-gnu-toolchain/riscv-gcc/ && ./contrib/download_prerequisites && cd - | |
[ -d build ] || mkdir build | |
[ -d $prefix ] || mkdir -p $prefix | |
cd build | |
# NOTE: GD32V is rv32imac ilp32 | |
$srcdir/configure \ | |
--with-cmodel=medany \ | |
--with-arch=rv32imac \ | |
--with-abi=ilp32 \ | |
--enable-multilib \ | |
--prefix=$prefix | |
sed -i '' -e 's/make_tuple = riscv$(1)-unknown-$(2)/make_tuple = riscv-nuclei-$(2)/g' Makefile | |
export CPPFLAGS="-I/opt/brew/include -I/opt/brew/opt/expat/include" | |
export LDFLAGS="-L/opt/brew/lib -L/opt/brew/opt/expat/lib" | |
screen -d -m -L -S build caffeinate make -j12 | |
: Build running in background. | |
: Use screen -r build to reattach. | |
: Build log saved to screenlog.0. | |
# NOTES: | |
# build uses 6.4GB, sources use 6.8GB | |
# we need 16GB ram-disk for build | |
# > ramdisk 16 && mdutil -i off -d /Volumes/RAM | |
# build takes approx 15-20 min on i7-8700B | |
: Creating package files. | |
# To make platformio think everything is installed. | |
cat >$prefix/package.json <<EOF | |
{ | |
"description": "RISC-V GCC toolchain", | |
"name": "toolchain-gd32v", | |
"system": "darwin_x86_64", | |
"url": "https://github.com/riscv-mcu/riscv-gnu-toolchain", | |
"version": "9.2.0" | |
} | |
EOF | |
cat >$prefix/.piopm <<EOF | |
{ | |
"type": "tool", | |
"name": "toolchain-gd32v", | |
"version": "9.2.0", | |
"spec": { | |
"owner": "platformio", | |
"id": 9999, | |
"name": "toolchain-gd32v", | |
"requirements": null, | |
"url": null | |
} | |
} | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tried on M1 Mac mini, with homebrew located in /opt/local/homebrew, it just needs few changes to run this script (rev3) from /tmp: