AdaCasio/build-gcc.sh
2026-04-15 19:23:44 +02:00

88 lines
2.5 KiB
Bash
Executable file

#!/usr/bin/env bash
# Copyright (c) 2026 Ada Orbit. All Rights Reserved.
# simple small script to build gcc with superh and ada support
set -e
# Definitions
ADACASIO_BINUTILS_VERSION="2.46.0"
ADACASIO_GCC_VERSION="15.2.0"
ADACASIO_BINUTILS_URL="https://ftp.gnu.org/gnu/binutils/binutils-$ADACASIO_BINUTILS_VERSION.tar.gz"
ADACASIO_GCC_URL="https://ftp.gnu.org/gnu/gcc/gcc-15.2.0/gcc-$ADACASIO_GCC_VERSION.tar.gz"
ADACASIO_PREFIX="$(pwd)/sysroot"
ADACASIO_TARGET="sh3eb-elf"
# Install dependencies
# For now I have only tested Fedora 43. YMMV
#sudo -i
#dnf install mg
#dnf upgrade
#dnf install @c-development gnat gprbuild gmp-devel mpfr-devel libmpc-devel git
# prepare configure and build enviornment
#wget -O binutils.tar.gz $ADACASIO_BINUTILS_URL
#wget -O gcc.tar.gz $ADACASIO_GCC_URL
tar -xf binutils.tar.gz
tar -xf gcc.tar.gz
# Got the command list from https://git.planet-casio.com/Lephenixnoir/sh-elf-binutils Method 3
# Step 2. configure and build GCC and binutils
mkdir build-binutils build-gcc $ADACASIO_PREFIX
cd build-binutils
../binutils-*/configure \
--prefix="$ADACASIO_PREFIX" \
--target="sh3eb-elf" \
--with-multilib-list="m3,m4-nofpu" \
--program-prefix="" \
--enable-libssp \
--enable-lto
make -j$(nproc)
make install-strip
# Build GCC the same way as Lephenixnoir does but also add ada
# https://git.planet-casio.com/Lephenixnoir/sh-elf-gcc
cd ../build-gcc/
../gcc-*/configure \
--prefix="$ADACASIO_PREFIX" \
--target="sh3eb-elf" \
--with-multilib-list="m3,m4-nofpu" \
--enable-languages="c,c++,ada" \
--disable-libada \
--without-headers \
--program-prefix="$ADACASIO_TARGET-" \
--enable-libssp \
--enable-lto \
--enable-clocale="generic" \
--enable-libstdcxx-allocator \
--disable-threads \
--disable-libstdcxx-verbose \
--enable-cxx-flags="-fno-exceptions"
make -j$(nproc) all-gcc all-target-libgcc
make install-strip-gcc install-strip-target-libgcc
# TODO: C++ support is currenlty not working on gcc15 with superh target
# It does work with gcc14 but ada does not :/
# I'll leave the c++ flags here for future use
cd ..
export PATH="$PATH:$ADACASIO_PREFIX/bin"
ADACASIO_GCCPREFIX="$($ADACASIO_TARGET-gcc --print-file-name=.)"
# WARNING: this library uses "sh3eb-elf-gcc"
# TODO: replace sh3eb-elf-gcc with $ADACASIO_TARGET-gcc
git clone https://github.com/Jonimoose/libfxcg.git
cd libfxcg
make
cp lib/* ../sysroot/lib/
cp -r include/* ../sysroot/lib/gcc/sh3eb-elf/15.2.0/include/
# Going back to gcc-build to build gnattools using the libc
cd ../build-gcc
make -C gcc cross-gnattools
make install-strip