Compiling MAME on Raspberry Pi 2 & 3

Starting with MAME 0.177 the default compiler on Raspberry Pi (GCC 4.9.2) will no longer work. MAME needs a minimum of GCC5 to compile. This tutorial has been updated to reflect that.

Compiling MAME on a Raspberry Pi is pretty easy. It’s been a supported compile target for a few revisions now. The bare minimum you need to do to get a working compile is an updated GCC and this…

apt-get install git build-essential libsdl2-dev libsdl2-ttf-dev libfontconfig-dev qt5-default

This will give you a build of MAME that works but I don’t think anyone would call it usable on a board as slow as a Raspberry Pi. So what can we do to speed things up a bit?

The biggest thing we can do is update SDL2 from 2.0.2 to 2.0.5 (which supports the Raspberry Pi gpu hardware).

It’s a little bit more complicated, but not much and you can expect 20-30% faster MAME as a result. That’s not a lot, but it is enough to put most of the classic era games in playable range. Overclock your Pi and reduce the screen resolution and you have an emulator that is usable for a lot of the games.

For this tutorial I am starting with a fresh install of Raspbian Jessie.

After first boot, do all the standard stuff:

  • Set Wi-Fi
  • Set Hostname
  • Set Password
  • Set Boot to CLI
  • Set memory split to 16
  • Set Locale, Time Zone, Keyboard, Wi-Fi Country
  • sudo apt-get update
  • sudo apt-get upgrade
  • Reboot

Then, because I’m a Mac user I sudo apt-get install netatalk so I can see the Pi on my network and get to the home folder.

Next we need to install SDL2-2.0.5. Follow the tutorial for that and I’ll meet you back here.

Install SDL2-2.0.5

Welcome back! We’re almost ready, now we need to install a newer version of GCC so we can compile MAME, follow the tutorial for that and I’ll meet you back here when you’re done.

Install GCC6.2

Aren’t you glad we won’t have to do any of that again for a while? Me too!

If you are downloading my MAME builds, this is as far as you need to go, just download the latest build unzip it and skip to the end of this tutorial. 

Next we will need a larger swapfile.

sudo nano /etc/dphys-swapfile

Find the line that says CONF_SWAPSIZE=100 and change the value so that it reads

Save, exit & reboot.

OK now we can get on with the MAME… *phew!*

Let’s put it all somewhere sensible.

mkdir code
cd code
mkdir mame

Download and unzip

unzip -d mame
cd mame

Now edit the makefile

nano makefile

Look for the section that says this

# BUILDDIR = build
# TARGETOS = windows

and change it to say this

# BUILDDIR = build
# TARGETOS = windows

Save and exit. Now just type…

make -j5

…and wait, and wait, and wait some more. Eventually it should finish.

Don’t forget to turn the swap file back to 100mb.

sudo nano /etc/dphys-swapfile

Find the line that says CONF_SWAPSIZE=2048 and change the value so that it reads
CONF_SWAPSIZE=100. Save and exit, then adjust the memory split to something more sensible for running MAME, so run sudo raspi-config and set the memory split to 256.


Once we’re back up we can run MAME. The first thing we need is a set of default mame options.

cd code/mame
./mame -cc
mkdir roms

That created the default mame.ini file and added a roms folder where MAME can see it by default. Put your MAME roms in the newly created roms folder and test run

./mame gridlee