Compile MAME 0.171 on a Raspberry Pi 2

Successfully compiled the full and complete version of MAME 0.171+ on a Raspberry Pi 2.

Why would I want to compile the full version of MAME?  Because it’s the latest version and is continually being updated with more accurate emulation of old hardware.  A lot of the emulation I want is from the early 1980’s and it successfully emulates games and computers of this era at 100%.   Plus it has some really powerful imgtools to work with emulated disks and cassette/cartridge files for computer emulations.  Version 0.171 now incorporates BGFX the unified GPU backend which speeds up emulation.

I’m an old programmer who came from programming my CoCo (TRS-80 Color Computer) in BASIC then I learned 6809 Assembly language.  I have given learning ‘C’ many tries over the years but I always have problems compiling my code once my programs start getting big.  I waste more time fighting with compiling than I do writing my programs in these structured languages, so please don’t think I’m a guru at compiling ‘C’ source code.

With the help of Steve Boswell and his site located here and some good compiling info for the Raspberry Pi here and more specifically SDL2 on a Raspberry Pi here.

The MAME source code compiles on the Raspberry Pi 2 without any modification to the source code. But you have to tweak a line in the MAME makefile, which I describe below (thanks to Steve Boswell).  You just have to make sure you have the proper libraries installed on the Pi and you give it enough RAM to compile and you are good to go.  It does take a long time to compile, the first “tiny” test build takes 31 minutes.  The main MAME compile afterwards took 5 hours and 32 minutes using the make -j4 option which uses all four of the Pi 2 cores.  This is on my Pi 2 overclocked @ 1000 Mhz.  I did a brand new install of the latest Raspbian build called “Jessie” to a Class 10 – 16 GB microSD card. This version of Raspbian comes with GCC 4.9.

As always update apt:

 sudo apt-get update
 sudo apt-get upgrade

Install the required libraries:

sudo apt-get install libjpeg-dev libtiff-dev libgl1-mesa-dev qt5-default libxinerama-dev
sudo apt-get install build-essential libfreeimage-dev libopenal-dev libpango1.0-dev libsndfile-dev libudev-dev libasound-dev libwebp-dev automake

You might already have this, if not it should be added (Doesn’t hurt to add it)

sudo apt-get install libx11-dev Install mercurial hg command (hg seems to be similar to git) and the latest SDL 2.0.4+ under SDL Mercurial.  The make -j4 takes about 4 minutes and 37 seconds:

sudo apt-get install mercurial 
hg clone
cd SDL
./configure --disable-pulseaudio --disable-esd --disable-video-mir --disable-video-wayland --host=armv7l-raspberry-linux-gnueabihf
make -j4
sudo make install

Install the latest True Type Font handling of SDL, you can find it on the SDL website:

Look for the file SDL2_ttf-2.x.xx.tar.gz at the time of this writing it was

SDL2_ttf-2.0.14.tar.gz so that is what is used in the next section substitute the version you found on the line below

 tar zxvf SDL2_ttf-2.0.14.tar.gz
 cd SDL2_ttf-2.0.14
 ./  (don't worry about any warning: autoconf input should be named '', not '' that's normal)
 make -j4
 sudo make install

Now the main event – get version 0.171 version of MAME

mkdir mame0171
unzip -d mame0171
cd mame0171

use nano and edit the makefile, change the one line with # ARCHOPTS to

ARCHOPTS = -mcpu=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard

Make sure to remove the # at the start of the line.  (Lines that start with # are ignored in the makefile)

nano makefile


ARCHOPTS = -mcpu=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard

CTRL-X   Y   Return

Let’s get ready to compile the complete MAME version, as of version 0.162 it also includes the MESS emulator so when you are done you can also use MAME to emulate your favourite old computer. You don’t need a separate MESS command anymore. MAME has MESS built in. First let’s give the Pi all the RAM we can:

sudo raspi-config

Go to Advanced Options then select Memory Split and hit Return and change this value to 16, then OK and Finish, No don’t reboot yet.

sudo nano /etc/dphys-swapfile

Change CONF_SWAPSIZE=100 to CONF_SWAPSIZE=2048, then hit CTRL-X, Y and hit Enter

It is not good for your SD cards lifespan to keep it this way so don’t forget to change it back after you are done.  I do show you how to set it back to normal below.

sudo reboot

Once your Pi reboots it’s time to compile the complete version of MAME this includes building the tools to help if we are using the Emulator with disk and files for specific old computers this took 4 hours and 9 minutes:

 cd ~/mame
 make -j4 TARGET=mame

To build the tools for using cassette and floppy images with MAME’s computer emulation do the following (seems like the makefile is broken it should work with make -j4 TOOLS=1):

 nano makefile

remove the # symbol on the line

# TOOLS = 1

so it looks like


Ctrl-X, Y , Return

make -j4

After MAME is compiled you must allocate more RAM to the GPU before you can use it otherwise SDL will give an error when you try to run MAME.  We set the GPU back to normal in the steps below.

Once the compiling is all done lets switch our memory usage back to normal:

sudo raspi-config

Go to Advanced Options then select Memory Split and hit Return and change this value to 256, then OK and Finish, No don’t reboot yet.

Now lets put the swap space back to normal to extend our SD cards lifespan

sudo nano /etc/dphys-swapfile

Change CONF_SWAPSIZE=2048 to CONF_SWAPSIZE=100, then hit CTRL-X, Y and hit Enter

Now we reboot to take our new changes:

sudo reboot

Once the Pi 2 reboots, there is one last step, for MAME to run the SDL Library has to be configured differently once it is used to compile MAME. Follow this step to get MAME working…

cd SDL
./configure --disable-pulseaudio --disable-esd --disable-video-mir --disable-video-wayland --disable-video-x11 --disable-video-opengl --host=armv7l-raspberry-linux-gnueabihf
make -j4
sudo make install

We are now ready to use the full version of MAME.  You will have to look elsewhere on the internet to find ROMs – I can’t help you with that other than the free ones from the website under downloads | ROMs.  You will have to make a directory called roms in the MAME directory

cd mame0171
mkdir roms

Put your .zip or .7z (either will work fine) versions of your ROMs of old games and computers in the ~/mame0171/roms folder and play them with the command:

cd ~/mame0171
./mame galaxy

I’ll do some speed comparison tests later today with my previous post of version 0.167 and I’ll update this section with the results.  Hopefully the BGFX features of 0.171 make a difference…

 Game           Speed Percentage
           mame0.167     mame0.171
           RPI2 @900Mhz  RPI2 @1000Mhz
 1942      73.72         80
 arkanoid  100           100
 armora    47.78         100
 asteroid  78.38         99.91
 berzerk   100           100
 ckong     100           100
 defender  99.98         100
 galaga    100           need new roms :(
 joust     100           100
 invaders  100           100
 mooncrst  90.99         99.79
 mpatrol   100           100
 phoenix   98.35         99.84
 puckman   100           100
 robotron  100           100
 scramble  69.63         82.04
 spacduel  59.08         82.03
 starcas   91.43         100

So 1942, Scramble & Space Duel still aren’t 100%.  I guess there were new Galaga ROMs found and are used for 0.171.

I found a cool little trick on Stack overflow that makes it easy to time how long some process takes.  Useful for timing compiling times and such.

# do some work (like compiling some code)
echo "$(($duration / 3600)) hours, $((($duration / 60) % 60)) minutes and $(($duration % 60)) seconds elapsed."

So in one line this would be:

SECONDS=0 ; make -j4 ; duration=$SECONDS ; echo "$(($duration / 3600)) hours, $((($duration / 60) % 60)) minutes and $(($duration % 60)) seconds elapsed."

Cheers, Glen

This entry was posted in Emulation and tagged , , , . Bookmark the permalink.

16 Responses to Compile MAME 0.171 on a Raspberry Pi 2

  1. Pegaz says:

    Hi Glen,
    I finnaly made to compile 0171 with your great tutorial.
    Emulator works, but it seems only in soft mode (set to auto by default) and if I choose something else for video option (opengl or bfgx) emulator crashed with Segmentation fault and Raspberry Pi 2 freeze.
    Just for comparision, can you start this computer with ./mame galaxy and tell me what speed you get.
    In older version with hwblit scalemode and slight frameskip I acheive near 100% speed, but with 0171, just 62%.
    I noticed da this latest version doesnt work with hwblit scalemode at all, even with soft video mode set.
    Can you please tell me whats going on here, compile process went flawlessly and I hope to get more speed gain, but nothin happens at least with several computers Im tryin.

  2. nowhereman999 says:

    Hi Pegaz,

    I’m glad this tutorial was helpful to you. I’m just compiling the emulator tools, it seem like the options on the command line aren’t being accepted by the make command unless I’m doing something wrong. I tried to compile the tools with “make -j4 TOOLS=1” but it didn’t do anything. I then edited the makefile and made the same option available and it is now compiling the tools So maybe we can compile it again with NO_X11 and NO_OPENGL selected from the makefile manually… I’ll have to do more testing and I’ll update this post when I do.

    I’ll try ./mame galaxy and I’ll tell you what speed I get, but it will have to wait a little while.


  3. nowhereman999 says:

    Hi again Pegaz,

    I tested ./mame galaxy after rebooting my RPI2 to the console (not the desktop) overclocked at 1000 Mhz and it only ran at 35.77% (no frame skip or any tweaks). Just curious, what computer emulator is this?

    I’ll test some other roms and see how they compare to my speeds of the 0.167 compile I did a few months ago.

    Afterwards I’ll mess around with the makefile and see if I can compile it with NO_X11 and NO_OPENGL to see if that helps. I’ll update this post with the results.


  4. Pegaz says:

    Well, something definitelly isnt good, becouse I have near 100% with same machine in 0170 build with soft rendering.
    I tested Steve 0171 binary and get the same result with galaxy about 30% of speed, without overclock.
    Is there a way to determine whether this is really bfgx or maybe software renderer is still active?
    Every time when I choose OpenGl or bfgx in video options, Rpi2 crashed and freeze, so maybe we still not activate acceleration support.
    Can you check this video options in your setup to be sure?
    It would be nice to ask Steve to test also, becouse he said that speed is better overal.
    He also said that doesnt have experimental Opengl driver installed ( and I still dont get it, how he managed to activate hw acceleration or we are all mistaken.
    Btw, galaxy is old eastern Europe computer.

    • nowhereman999 says:

      Hi Pegaz,

      There are definite speed improvements on some of the games vs 0.167 like Armora. I wonder if it is because it’s a vector graphics based game? Same with Asteroids and Space Duel. They have sped up too. So maybe certain types of graphics are being helped by the BGFX features of 0.171 but it must have slowed down the CPU/motherboard emulation somehow according to your comparisons with 0.170.

      I don’t know enough about compiling and the various options that can be selected. I think you should ask Steve to see if he can look into it further.

      Another thought, sometimes programmers will add in new features to a program and not optimize it until it is proven that it is working properly. Maybe when they added BGFX they had to tweak other features in MAME to work with BGFX that is causing your slow down… If that is what happened maybe the next release of MAME will be more optimized.

      FYI – I download the bleeding edge version of MAME from GIT and tried to compile it but it required GCC 5.1 which isn’t available for RPI. There are some people who have compiled their own GCC 5.1 and one post mentioned that they added multithreading support called click (or something). If it’s possible to compile MAME to use the multiple cores of the RPi2 that would be awesome. One core for the CPU emulation, one Core for other parts of the motherboard. Of course this is just me dreaming right now, but maybe one day. MAME already has a -multithread option. 🙂

      I hope Steve can help you figure out why 0.171 is slower for your emulation needs,

  5. Pegaz says:

    Thanks Glen, thats my toughts exactly.
    I think that Mess part in 0171 doesnt have benefit of hardware acceleration, like mame arcade games.
    Steve already tried few computers (Atari 800xl and BBC B) and speed is also very slow and unusable.
    For now, best bet for me is tryin to compile old versions like 0149, mentioned in Steves blog.
    The problem is, that I have problem to compile those old versions, but I will give another try.
    I dont want to bother you with this, but if you have time to look at it, I will apprecite it.
    Your tweak with scalemode, makes many of my wandered old computers to work and I am very grateful for this.

  6. Eric says:

    Glen, I successfully compiled mame 0.171 on my Pi2 using your step by step guide. Thank you! Looks like hardware acceleration is slowly being figured out. Nice!

  7. Eric says:

    I just tried this exact same method with the newer 0.172 source code. It compiled ok without error, but took over an hour longer. I still need to transfer some roms over to it and test though. If there are any tips during the process to get a more optimized compile with 0.172, please let us know.

    • nowhereman999 says:

      Hi Eric,

      I haven’t tried to compile .172 yet and I’m not an expert at compiling, but when I do give it a try I’ll report my findings. I noticed myself that different microSD cards can affect compile time a lot. Are you using the same microSD card? I’m just curious…

      • Eric says:

        Can remember if it’s the same card. The one I use now is a class 4 card, so maybe that’s the slowdown.

  8. Eric says:

    Ok, I tested it. While version 0.172 compiles without error. It does not seem to run without error. I get the following error when trying to run any game. So it’s a no go so far. and that first line does show up twice.

    pure virtual method called
    pure virtual method called
    Segmentation fault

    • nowhereman999 says:

      Did you give the Pi back it’s GPU memory? Maybe it needs a little more? Just a thought…

      • Eric says:

        Yes tried more memory but it still does not work. I will try to recompile again from scratch, just in case I made a mistake.

  9. Eric says:

    Had time to try and compile again, but still no luck. Started with fresh and updated Raspbian image. Followed same exact procedure from 0.171, but getting errors on program execution with 0.172, even though it compiles without error, and it’s above my capability to figure out why it does not work. I also tried binaries from another site, but still same errors on most games. Like you Glen, I’m no expert at compiling either. Thank you for the earlier guide, and please do report your findings when you give 0.172 a go. Thanks!

  10. allenhuffman says:

    Awesome. I guess I have a new winter project. (And another, when I get my CoCo 3 set up and try your Space Invaders port 😉

  11. huskeyw says:

    this has been a while but I get hung up on the compile of mame

    the errors I get are:

    “makefile:1040: recipe for target ‘linux’ failed” when compiling Mame I am running retropie1 4.4.38-v7+ #938 SMP Thu Dec 15 15:22:21 GMT 2016 armv7l GNU/Linux

    gcc ver
    Target: arm-linux-gnueabihf
    Configured with: ../src/configure -v –with-pkgversion=’Raspbian 4.9.2-10′ –with-bugurl=file:///usr/share/doc/gcc-4.9/README.Bugs –enable-languages=c,c++,java,go,d,fortran,objc,obj-c++ –prefix=/usr –program-suffix=-4.9 –enable-shared –enable-linker-build-id –libexecdir=/usr/lib –without-included-gettext –enable-threads=posix –with-gxx-include-dir=/usr/include/c++/4.9 –libdir=/usr/lib –enable-nls –with-sysroot=/ –enable-clocale=gnu –enable-libstdcxx-debug –enable-libstdcxx-time=yes –enable-gnu-unique-object –disable-libitm –disable-libquadmath –enable-plugin –with-system-zlib –disable-browser-plugin –enable-java-awt=gtk –enable-gtk-cairo –with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.9-armhf/jre –enable-java-home –with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.9-armhf –with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.9-armhf –with-arch-directory=arm –with-ecj-jar=/usr/share/java/eclipse-ecj.jar –enable-objc-gc –enable-multiarch –disable-sjlj-exceptions –with-arch=armv6 –with-fpu=vfp –with-float=hard –enable-checking=release –build=arm-linux-gnueabihf –host=arm-linux-gnueabihf –target=arm-linux-gnueabihf
    Thread model: posix
    gcc version 4.9.2 (Raspbian 4.9.2-10)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s