Skip to content

Instantly share code, notes, and snippets.

@WillSams
Last active December 3, 2022 17:15
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 WillSams/635d047324271ed2832e8ac49fb556d0 to your computer and use it in GitHub Desktop.
Save WillSams/635d047324271ed2832e8ac49fb556d0 to your computer and use it in GitHub Desktop.
Saturn/32x Tool chain
#!/bin/bash
# I'm just going by what I've done before and the configuration flags found here:
# https://github.com/kentosama/sh2-elf-gcc/
TEMPBUILDDIR=/tmp/saturn
GCCBUILDIR=$TEMPBUILDDIR/pkgs/gcc-build
BINUTILS_VERSION=2.39
GCC_VERSION=7.1.0
NEWLIB_VERSION=2.0.0
SH2DEV=/opt/toolchains/saturn
sudo bash -c "mkdir -p $SH2DEV/tools && chown -R $USER:$USER $SH2DEV"
mkdir -p $TEMPBUILDDIR/tools $TEMPBUILDDIR/pkgs
# BINUTILS - If you just want to write assembly code, you can just install this, really.
cd $TEMPBUILDDIR/pkgs
wget http://ftp.gnu.org/gnu/binutils/binutils-$BINUTILS_VERSION.tar.bz2
tar xvjf binutils-$BINUTILS_VERSION.tar.bz2
cd $TEMPBUILDDIR/pkgs/binutils-$BINUTILS_VERSION
./configure --target=sh-none-elf --prefix=$SH2DEV --disable-werror --disable-nls --enable-languages=c
make && make install
PATH=$PATH:$SH2DEV
# GCC - this will take awhile
cd $TEMPBUILDDIR/pkgs
wget http://ftp.gnu.org/gnu/gcc/gcc-$GCC_VERSION/gcc-$GCC_VERSION.tar.bz2
tar xvjf gcc-$GCC_VERSION.tar.bz2
mkdir $GCCBUILDIR
cd $TEMPBUILDDIR/pkgs/gcc-$GCC_VERSION
./contrib/download_prerequisites # i.e., gmp, mpfr, mpc
cd $GCCBUILDIR
../gcc-$GCC_VERSION/configure --target=sh-none-elf --prefix=$SH2DEV --with-cpu=m2 --with-newlib --with-gnu-ld --with-gnu-as --with-gcc \
--without-headers --without-included-gettext \
--enable-lto --enable-languages=c,c++ \
--disable-threads --disable-libmudflap --disable-libgomp --disable-nls --disable-werror --disable-libssp --disable-shared --disable-libgcj --disable-libstdcxx --disable-multilib --disable-libstdcx
make && make install && make install-target-libgcc
# NEWLIB - this will take awhile
cd $TEMPBUILDDIR/pkgs
wget ftp://sourceware.org/pub/newlib/newlib-$NEWLIB_VERSION.tar.gz && \
tar xzf newlib-$NEWLIB_VERSION.tar.gz
cd $TEMPBUILDDIR/pkgs/newlib-$NEWLIB_VERSION
./configure --prefix=$SH2DEV --enable-newlib-nano-malloc --enable-target-optspace
make && make install
# Use the Mednafen for testing/debugging
sudo apt install mednafen
# Important -> add the needed Saturn bios file(s) to ~/.medafen/firmware
# Tools - CueMaker and binmerge
cd $SH2DEV/tools
wget https://github.com/johannes-fetz/joengine/raw/master/Compiler/LINUX/Other%20Utilities/CueMaker
chmod +x $SH2DEV/tools/CueMaker
wget https://github.com/putnam/binmerge/raw/master/binmerge
mv binmerge binmerge.py
# Use Johannes Fetz's Jo Engine for a better development experience
cd $SH2DEV/sh-none-elf/lib
wget https://github.com/johannes-fetz/joengine/raw/master/Compiler/LINUX/sh-none-elf/lib/libc.a
wget https://github.com/johannes-fetz/joengine/raw/master/Compiler/LINUX/sh-none-elf/lib/libnosys.a
wget https://github.com/johannes-fetz/joengine/raw/master/Compiler/LINUX/sh-none-elf/lib/nosys.specs
svn checkout https://github.com/johannes-fetz/joengine/trunk/JoMapEditor $SH2DEV/tools/JoMapEditor
svn checkout https://github.com/johannes-fetz/joengine/trunk/jo_engine $SH2DEV/include/jo_engine
svn checkout https://github.com/johannes-fetz/joengine/trunk/Compiler/COMMON $SH2DEV/COMMON
sed -i -e 's/JO_ENGINE_SRC_DIR=..\/..\/jo_engine/JO_ENGINE_SRC_DIR=$(SH2DEV)\/include\/jo_engine/g' $SH2DEV/COMMON/jo_engine_makefile
sed -i -e 's/COMPILER_DIR=..\/..\/Compiler/COMPILER_DIR=$(SH2DEV)/g' $SH2DEV/COMMON/jo_engine_makefile
sed -i -e 's/sh-none-elf-gcc-8.2.0/sh-none-elf-gcc/g' $SH2DEV/COMMON/jo_engine_makefile
sed -i -e 's/$(COMPILER_DIR)\/LINUX/$(COMPILER_DIR)/g' $SH2DEV/COMMON/jo_engine_makefile
sed -i -e 's/Other Utilities/tools/g' $SH2DEV/COMMON/jo_engine_makefile
# Sanity check - JoEngine
# 1 - Execute `svn checkout https://github.com/johannes-fetz/joengine/trunk/Samples`
# 2 - In the ./demo1 path, modify the Makefile.
# a. Remove the JO_ENGINE_SRC_DIR and COMPILER_DIR variables.
# b. In place of the removed lines, add `SH2DEV=/opt/toolchains/saturn`.
# c. Change `include $(COMPILER_DIR)/COMMON/jo_engine_makefile` to `include $(SH2DEV)/COMMON/jo_engine_makefile`.
# 3. Executing `make` should result in binaries and a CD image.
# 4. To burn the image with k3b and to run with Mednafen, we need to modify the cue file further. Execute `python3 /opt/toolchains/saturn/tools/binmerge.py game.cue fixed-game.cue`.
# 5. Finally, execute `mednafen ./fixed-game.cue` to view the demo.
# Yaul is an excellent engine as well
cd $TEMPBUILDDIR/pkgs
git clone https://github.com/ijacquez/libyaul.git
cd libyaul
cp yaul.env.inc ~/.yaul.env
sed -i -e 's/YAUL_INSTALL_ROOT=\/opt\/tool-chains\/sh2eb-elf/YAUL_INSTALL_ROOT=\/opt\/toolchains\/saturn/g' ~/.yaul.env
sed -i -e 's/export YAUL_PROG_SH_PREFIX=/export YAUL_PROG_SH_PREFIX=sh-non-elf/g' ~/.yaul.env
sed -i -e 's/YAUL_ARCH_SH_PREFIX=sh2eb-elf/YAUL_ARCH_SH_PREFIX=sh-none-elf/g' ~/.yaul.env
sed -i -e 's/YAUL_ARCH_M68K_PREFIX=m68keb-elf/YAUL_ARCH_M68K_PREFIX=m68k-unknown-elf/g' ~/.yaul.env
sed -i -e 's/YAUL_BUILD_ROOT=${HOME}\/libyaul/YAUL_BUILD_ROOT=${YAUL_INSTALL_ROOT}\/lib/g' ~/.yaul.env
sed -i -e 's/YAUL_BUILD=build/YAUL_BUILD=.\//g' ~/.yaul.env
# Sanity check - Yaul
# 1. Execute `source ~/.yaul.env` to load Yaul environment variables.
# 2. Execute `git clone https://github.com/ijacquez/libyaul-examples.git`
# 3. Within the newly cloned repository, in the `vdp2-zooming` folder, execute `make`. You should have a good build.
# 5. Finally, execute `mednafen *.cue` to view the demo.
# Remove the temp build directory
rm -rf $TEMPBUILDDIR
#*****************************************************************************
echo "$SCRIPTFULLNAME ($SCRIPTVERSION) complete."
@WillSams
Copy link
Author

WillSams commented Dec 3, 2022

Added Yaul...fixed...something?

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