Skip to content

Instantly share code, notes, and snippets.

@snacsnoc
Forked from WillSams/m68k_dev_setup.sh
Last active May 10, 2024 08:12
Show Gist options
  • Select an option

  • Save snacsnoc/d0fde167688f04d0b0ad81844fe6900e to your computer and use it in GitHub Desktop.

Select an option

Save snacsnoc/d0fde167688f04d0b0ad81844fe6900e to your computer and use it in GitHub Desktop.
Setup for Motorola 68000 (m68k) 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="2024.05.10-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 -j4 && 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/
#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/
# 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