Skip to content

Instantly share code, notes, and snippets.

@nanoant
Last active December 30, 2022 01:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nanoant/fc76f0c03c249d81f515a3727f15e8b8 to your computer and use it in GitHub Desktop.
Save nanoant/fc76f0c03c249d81f515a3727f15e8b8 to your computer and use it in GitHub Desktop.
Builds GD32V riscv-gnu-toolchain on macOS
#!/bin/bash
#
# Builds GD32V riscv-gnu-toolchain on macOS
#
# Author: Adam Strzelecki <nanoant@users.noreply.github.com>
# 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
@digdog
Copy link

digdog commented Apr 24, 2022

Tried on M1 Mac mini, with homebrew located in /opt/local/homebrew, it just needs few changes to run this script (rev3) from /tmp:

34c34
< cd $srcdir/riscv-gnu-toolchain/riscv-gcc/ && ./contrib/download_prerequisites && cd -
---
> cd $srcdir/riscv-gcc/ && ./contrib/download_prerequisites && cd -
39c39
< $srcdir/configure \
---
> ../$srcdir/configure \
47,48c47,48
< export CPPFLAGS="-I/opt/brew/include -I/opt/brew/opt/expat/include"
< export LDFLAGS="-L/opt/brew/lib -L/opt/brew/opt/expat/lib"
---
> export CPPFLAGS="-I/opt/homebrew/include -I/opt/homebrew/opt/expat/include"
> export LDFLAGS="-L/opt/homebrew/lib -L/opt/homebrew/opt/expat/lib"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment