IIR_
Posts: 2
Joined: Wed Dec 07, 2022 12:38 pm

Compiling mame on Linux / Ubuntu, with and without system libraries.

Hey, I've recently joined the forum and have been tinkering with Mame compilation on Linux systems for a while, mainly Debian-based (Ubuntu and Raspberry Pi). As I've seen some comments about how to compile it successfully I'll post my workings here; at one point I'll publish all findings into a Gist.

This has been working with all versions of Mame I've tried since 246 and GCC10/11/12.

I suggest installing the system Mame from apt first so the binaries and any config files are set up; if you don't want to overwrite an existing installation then you can change the directories to your liking; personally I haven't found any issue (and easier to configure GUIs) in overwriting with the compiled binaries.

Change

Code: Select all

-j7
to the number of CPU threads on your system minus one, unless you won't be using it during compilation :)

First of all, clone just the branch you need for your version, e.g. 250:

Code: Select all

git clone -b mame0250 --depth 1 https://github.com/mamedev/mame.git mame0250

NOTE: you can get 1%-2% more performace (and a smaller binary) by adding Link Time Optimization to the options:

Code: Select all

 LTO=1
- however, this will add a considerable compile time and will require your system to have +20GB RAM. There's a new linker that greatly reduces LTO memory usage / compile time but currently not supported (as of GCC12 stable or below). You can add:

Code: Select all

-Wl,--no-keep-memory
to

Code: Select all

ARCHOPTS=
to inform the LTO linker not to keep as many files in memory.

I'm using

Code: Select all

 -march=native
in

Code: Select all

ARCHOPTS=
as I want it to squeeze the utmost CPU-specific optimizations for the host architecture as I don't copy the binaries over to other machines. Remove this option if you want your code a bit more architecture-generic.

For compiling Mame using system libraries
First, install needed development libraries using APT:

Code: Select all

sudo apt install libexpat1-dev libflac-dev libfontconfig1-dev libglm-dev libjpeg-dev liblua5.3-dev libportmidi-dev libpugixml-dev libsdl2-dev libsdl2-ttf-dev libsqlite3-dev libutf8proc-dev libxinerama-dev portaudio19-dev python3-dev qtbase5-dev rapidjson-dev zlib1g-dev libomp-dev

Compile Mame with system libraries

Code: Select all

make -j7 REGENIE=1 TARGETOS=linux TARGET=mame SUBTARGET=mame PTR64=1 STRIP_SYMBOLS=1 TOOLS=1 OPENMP=1 SEPARATE_BIN=1 DEBUG=0 USE_QTDEBUG=0 ARCHOPTS="-march=native -fuse-ld=gold" NOWERROR=1 OSD=sdl DISTRO=debian-stable PYTHON_EXECUTABLE=python3 USE_SYSTEM_LIB_ASIO= USE_SYSTEM_LIB_EXPAT=1 USE_SYSTEM_LIB_ZLIB=1 USE_SYSTEM_LIB_JPEG=1 USE_SYSTEM_LIB_FLAC=1 USE_SYSTEM_LIB_LUA=lua5.3:/usr/include/lua5.3 USE_SYSTEM_LIB_SQLITE3=1 USE_SYSTEM_LIB_PORTMIDI=1 USE_SYSTEM_LIB_PORTAUDIO=1 USE_BUNDLED_LIB_SDL2= USE_SYSTEM_LIB_UTF8PROC=1 USE_SYSTEM_LIB_GLM=1 USE_SYSTEM_LIB_RAPIDJSON=1 USE_SYSTEM_LIB_PUGIXML=1 SDL_INI_PATH=/etc/mame
Then install the binaries (see below).

For compiling Mame using libraries supplied with Mame

Code: Select all

make -j7 REGENIE=1 TARGETOS=linux TARGET=mame SUBTARGET=mame PTR64=1 STRIP_SYMBOLS=1 TOOLS=1 SEPARATE_BIN=1 DEBUG=0 USE_QTDEBUG=0 OSD=sdl OPENMP=1 OPTIMIZE="fast" ARCHOPTS="-march=native -fuse-ld=gold"
Then install the binaries (see below).

Installing the binaries including tools from the separate build dirs

Code: Select all

sudo cp build/linux_gcc/bin/x64/Release/mame /usr/games/mame
sudo cp build/linux_gcc/bin/x64/Release/{castool,chdman,floptool,imgtool,jedutil,ldresample,ldverify,romcmp} /usr/bin/

Feel free to ask any questions!

Return to “MAME Discussion”