Skip to content

Instantly share code, notes, and snippets.

@WillSams
Last active May 10, 2024 08:10
Show Gist options
  • Save WillSams/c4cbf6235b467d8b595693969342237e to your computer and use it in GitHub Desktop.
Save WillSams/c4cbf6235b467d8b595693969342237e to your computer and use it in GitHub Desktop.
Setup for Motorola 68000 (Sega, Neo Geo) Cross Compiler on Debian-based System
#!/bin/bash
echo "==================================================================="
echo
echo " My m68000 Development Setup "
echo " You may be prompted for root credentials to complete the install. "
echo
echo " Toolchain is GNU so it expects you to write AT&T style assembly. "
echo " If you want the Windows (MSYS2) script, it's here: "
echo " https://gist.github.com/WillSams/f592f9d494b51119945440f7e91079b0 "
echo "==================================================================="
set -o nounset # unset variables are errors
SCRIPTVERSION="2022.11.30-Debian"
SCRIPTNAME="m68k_dev_setup.sh"
SCRIPTFULLNAME="$0"
GENDEV="/opt/toolchains/m68k"
USERNAME=$(whoami)
echoerror() { printf "\033[1;31m * ERROR\033[0m: %s\\n" "$@" 1>&2; }
usage() {
cat << EOT
Usage : ${SCRIPTNAME} [options]
Options:
-h Display this message
-v Display script version
-d Location you want to install the m68K cross compiler. Default is /opt/toolchains/m68k.
EOT
} # ---------- end of function usage ----------
while getopts ':hvd:' opt
do
case "${opt}" in
h ) usage; exit 0 ;;
v ) echo "$0 -- Version $SCRIPTVERSION"; exit 0 ;;
d ) GENDEV=$OPTARG ;;
\?) echo
echoerror "Option does not exist : $OPTARG"
usage
exit 1
;;
esac # --- end of case ---
done
shift $((OPTIND-1))
sudo bash -c "apt-get update && apt upgrade -y"
#*****************************************************************************
TEMPBUILDDIR=/tmp/m68kbuild
GCCBUILDIR=$TEMPBUILDDIR/pkgs/gcc-build
BINUTILS_VERSION=2.39
GCC_VERSION=7.1.0
NEWLIB_VERSION=2.0.0
sudo bash -c "apt install -y build-essential texinfo cmake unrar git tar libglew-dev"
sudo bash -c "mkdir -p $GENDEV/tools && chown -R $USER:$USER $GENDEV"
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=m68k-unknown-elf --prefix=$GENDEV --with-cpu=m68000 --enable-install-libbfd --disable-nls
make && make install
PATH=$PATH:$GENDEV
# NEWLIB - this will take awhile, especially on Windows....
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
sed -i -e 's/ssize_t/_READ_WRITE_RETURN_TYPE/g' $TEMPBUILDDIR/pkgs/newlib-$NEWLIB_VERSION/libgloss/m68k/io-read.c
sed -i -e 's/ssize_t/_READ_WRITE_RETURN_TYPE/g' $TEMPBUILDDIR/pkgs/newlib-$NEWLIB_VERSION/libgloss/m68k/io-write.c
./configure --prefix=$GENDEV --with-cpu=m68000 --disable-newlib-multithread --disable-newlib-io-float --enable-lite-exit --disable-newlib-supplied-syscalls
make && make install
# 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=m68k-unknown-elf --prefix=$GENDEV --with-cpu=m68000 --enable-languages=c,c++ --with-newlib --disable-libmudflap --disable-libssp --disable-libgomp --disable-libstdcxx-pch --disable-threads --disable-nls --disable-libquadmath --with-gnu-as --with-gnu-ld --without-headers --disable-werror
make && make install
# libGCC
cd $GCCBUILDIR
PATH=$PATH:$GENDEV make all-target-libgcc install-target-libgcc
cp $GENDEV/lib/gcc/m68k-elf/$GCC_VERSION/libgcc.a $GENDEV/m68k-elf/lib
#BIN2C
cd $TEMPBUILDDIR/tools
wget http://downloads.sourceforge.net/project/bin2c/1.0/bin2c-1.0.zip
unzip bin2c-1.0.zip && cd $TEMPBUILDDIR/tools/bin2c
gcc bin2c.c -o bin2c
mv $TEMPBUILDDIR/tools/bin2c/bin2c $GENDEV/tools/
#SJASM - Z80 assembler
cd $TEMPBUILDDIR/tools
wget -O sjasm39g6.zip https://github.com/samsaga2/sjasm/archive/master.zip
unzip sjasm39g6.zip && cd $TEMPBUILDDIR/tools/sjasm-master
cmake . && make
mv TEMPBUILDDIR/tools/sjasm-master/sjasm $GENDEV/tools/
#ZASM - Z80 assembler - 8-bit
cd $TEMPBUILDDIR/tools
wget http://k1.spdns.de/Develop/Projects/zasm/Distributions/old%20versions/zasm-3.0.21-source-linux-2011-06-19.zip
unzip zasm-3.0.21-source-linux-2011-06-19.zip
cd $TEMPBUILDDIR/tools/zasm-3.0.21-i386-ubuntu-linux-2011-06-19/source
make
mv zasm $GENDEV/tools/
#HEX2BIN - Tool for converting our hexadecimal M68k files into a binary
cd $TEMPBUILDDIR/tools
wget http://downloads.sourceforge.net/project/hex2bin/hex2bin/Hex2bin-1.0.10.tar.bz2
tar xvjf Hex2bin-1.0.10.tar.bz2
mv $TEMPBUILDDIR/tools/Hex2bin-1.0.10/hex2bin $GENDEV/tools/
#SIXPACK - Tool for converting images to graphics data suitable for our games
cd $TEMPBUILDDIR/tools
wget http://jiggawatt.org/badc0de/sixpack/sixpack-13.zip
unzip sixpack-13.zip
mv $TEMPBUILDDIR/tools/sixpack-12/bin/sixpack $GENDEV/tools/
chmod +x $GENDEV/tools/sixpack
#VGMTOOLS - Tools for the Video Game Music audio file format
# 11/30/2022 - this seems broken, fill fix later
#cd $TEMPBUILDDIR/tools
#wget -O VGMTools_src.rar http://www.smspower.org/forums/download.php?id=3201
#wget https://raw.githubusercontent.com/andwn/gendev/master/files/vgm_cmp.diff
#mkdir -p $TEMPBUILDDIR/tools/vgmtools && unrar x VGMTools_src.rar vgmtools
#cd $TEMPBUILDDIR/tools/vgmtools && patch -u vgm_cmp.c ../vgm_cmp.diff
#gcc -c chip_cmp.c -o chip_cmp.o && gcc chip_cmp.o vgm_cmp.c -lz -o vgm_cmp
#mv $TEMPBUILDDIR/tools/vgmtools/vgm_cmp $GENDEV/tools/
# Blast 'Em - Sega Genesis/Megadrive, MasterSystem/MarkIII, Atari Jaquar emulator
# Note: This may fail, you may need to change all references to `#include <SDL.h>` to `#include <SDL2/SDL.h>`.
cd $TEMPBUILDDIR/tools
wget https://www.retrodev.com/repos/blastem/archive/8aeac7bd9fa7.tar.gz
tar zxvf 8aeac7bd9fa7.tar.gz
cd $TEMPBUILDDIR/tools/blastem-8aeac7bd9fa7 && make
cd $TEMPBUILDDIR/tools && mv $TEMPBUILDDIR/tools/blastem-8aeac7bd9fa7 $GENDEV/tools/blastem
# 'Ye sanity check
git clone https://github.com/WillSams/pascal_animation $TEMPBUILDDIR/sanity_check
cd $TEMPBUILDDIR/sanity_check && make clean all run
# Remove the temp build directory
rm -rf $TEMPBUILDDIR
#*****************************************************************************
echo "$SCRIPTFULLNAME ($SCRIPTVERSION) complete."
@WillSams
Copy link
Author

Fixed this broken script.

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