Skip to content

Instantly share code, notes, and snippets.

@WillSams
Last active October 23, 2022 18:06
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WillSams/f592f9d494b51119945440f7e91079b0 to your computer and use it in GitHub Desktop.
Save WillSams/f592f9d494b51119945440f7e91079b0 to your computer and use it in GitHub Desktop.
Setup for Motorola 68000 (Sega, Neo Geo) Cross Compiler on Windows-based System
#!/bin/bash
echo "==================================================================="
echo
echo " My m68000 Development Setup "
echo " You may be prompted by UAC for credentials to complete the install "
echo
echo " Pre-req: Latest 64-bit MSYS2 from http://www.msys2.org/ "
echo
echo " Howto: Use 'wget' to download the raw version of this script "
echo " and execute the following from the MSys2 command-line: "
echo " chmod +x m68k_dev_setup.sh "
echo " ./m68k_dev_setup.sh "
echo
echo " Not fully tested, but this *should* work for most Windows users. "
echo " Toolchain is GNU so it expects you to write AT&T style assembly. "
echo " If you want the Linux (Debian) script, it's here: "
echo " https://gist.github.com/WillSams/c4cbf6235b467d8b595693969342237e "
echo " This may take forever to install on Windows. How do you live? "
echo "===================================================================="
set -o nounset # unset variables are errors
SCRIPTVERSION="2019.04.26-Windows"
SCRIPTNAME="m68k_dev_setup.sh"
SCRIPTFULLNAME="$0"
GENDEV="/opt/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/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))
#*****************************************************************************
TEMPBUILDDIR=/tmp/m68kbuild
GCCBUILDIR=$TEMPBUILDDIR/pkgs/gcc-build
GCC_VERSION=4.9.0
BINUTILS_VERSION=2.24
NEWLIB_VERSION=2.1.0
pacman -Sy --needed mingw-w64-x86_64-toolchain
pacman -Sy --needed texinfo tar diffutils make cmake unrar git patch zlib
pacman -Sy --needed mingw-w64-x86_64-SDL2 autoconf automake libtool
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-elf --prefix=$GENDEV --with-cpu=m68000 --enable-install-libbfd --disable-nls --disable-werror
PATH=$PATH:$GENDEV make all install
# GCC - this will take awhile, especially on Windows....
cd $TEMPBUILDDIR/pkgs
wget http://ftp.gnu.org/gnu/gcc/gcc-$GCC_VERSION/gcc-$GCC_VERSION.tar.bz2
wget ftp://gcc.gnu.org/pub/gcc/infrastructure/isl-0.12.2.tar.bz2
wget ftp://gcc.gnu.org/pub/gcc/infrastructure/cloog-0.18.1.tar.gz
tar xvjf gcc-$GCC_VERSION.tar.bz2
mkdir $GCCBUILDIR $TEMPBUILDDIR/pkgs/gcc-$GCC_VERSION/isl $TEMPBUILDDIR/pkgs/gcc-$GCC_VERSION/cloog
tar xvjf isl-0.12.2.tar.bz2 -C $TEMPBUILDDIR/pkgs/gcc-$GCC_VERSION/isl --strip-components=1
tar xzf cloog-0.18.1.tar.gz -C $TEMPBUILDDIR/pkgs/gcc-$GCC_VERSION/cloog --strip-components=1
cd $TEMPBUILDDIR/pkgs/gcc-$GCC_VERSION
./contrib/download_prerequisites
cd $GCCBUILDIR
../gcc-$GCC_VERSION/configure --target=m68k-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
PATH=$PATH:$GENDEV make all-gcc install-gcc
# NEWLIB - this will take awhile, especially on Windows....
cd $TEMPBUILDDIR/pkgs
wget ftp://sources.redhat.com/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
export PATH=$PATH:$GENDEV/bin
./configure --prefix=$GENDEV --with-cpu=m68000 --disable-newlib-multithread --disable-newlib-io-float --enable-lite-exit --disable-newlib-supplied-syscalls
PATH=$PATH:$GENDEV make all 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/
# Blast 'Em - Sega Genesis/Megadrive, MasterSystem/MarkIII, Atari Jaquar emulator
cd $TEMPBUILDDIR/tools
wget https://www.retrodev.com/blastem/blastem-win32-0.6.2.zip
unzip blastem-win32-0.6.2.zip && cd $TEMPBUILDDIR/tools/blastem-win32-0.6.2
make && cd $TEMPBUILDDIR/tools
mv $TEMPBUILDDIR/tools/blastem-win32-0.6.2 $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."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment