Compiling Zandronum on Linux

From Zandronum Wiki

Open a terminal and copy and paste the whole code box for each step.

Install dependencies

Zandronum needs certain tools and development files in order to compile:

  • Required
    • gcc 4.6 or later
    • make
    • cmake 2.8.7 or later
    • SDL 1.2.8 or later 1.2.x versions
    • libGL and libGLU (SDL or libSDL pull in libGLU) or any other GL implementation provider.
    • FMOD Ex 4.44.64
    • libopenssl (for Zandronum 1.3 or later)
    • libopus (for Zandronum 3.2 or later)
  • Recommended
    • GTK2
    • mercurial (needed in order to download the source and compile in commit meta data)
      • mercurial-evolve (optional, includes the topic and evolve extensions, which are needed only if you intend to compile a specific topic. Some distros may include these as part of their base Mercurial package)
    • nasm 0.98.39 or later (x86-32 only)
  • Optional
    • zlib (Zandronum has a copy of it and will be statically compiled in if not found)
    • libbzip2 (possibly static)
    • libjpeg (possibly static)
  • Runtime
    • gxmessage (optional - needed to show the crash log in a window)
    • kdialog (optional - for KDE users)
    • fluidsynth or timidity (optional - for MIDI playback)

Install the following as root/superuser:

Debian/Ubuntu

sudo apt-get install g++ make cmake libsdl1.2-compat-dev mercurial mercurial-evolve zlib1g-dev \
libbz2-dev libjpeg-dev libfluidsynth-dev libgtk2.0-dev timidity nasm \
libgl1-mesa-dev libssl-dev tar libglew-dev libopus-dev

Fedora

dnf install gcc-c++ make cmake SDL-devel mercurial zlib-devel \
bzip2-devel libjpeg-turbo-devel fluidsynth-devel gtk2-devel timidity++ nasm \
mesa-libGL-devel openssl-devel glew glew-devel tar

openSUSE

zypper install gcc-c++ make cmake libSDL-devel mercurial zlib-devel \
libbz2-devel libjpeg-devel fluidsynth-devel gtk2-devel timidity nasm \
Mesa-libGL-devel libopenssl-devel tar glew glew-devel

Mageia

a='' && [ "$(uname -m)" = x86_64 ] && a=64
urpmi gcc-c++ make cmake lib${a}SDL-devel mercurial lib${a}zlib-devel \
lib${a}bzip2-devel lib${a}jpeg-devel lib${a}fluidsynth-devel \
lib${a}gtk+2.0-devel lib${a}cairo-devel TiMidity++ nasm \
lib${a}mesagl1-devel lib${a}openssl-devel tar

Arch Linux

pacman -S --needed gcc make cmake sdl12-compat mercurial zlib bzip2 libjpeg-turbo \
fluidsynth gtk2 timidity++ nasm mesa glu openssl tar glew

Gentoo

emerge -avn sys-devel/gcc sys-devel/make dev-util/cmake media-libs/libsdl \
dev-vcs/mercurial sys-libs/zlib app-arch/bzip2 media-libs/libjpeg-turbo media-sound/fluidsynth \
x11-libs/gtk+ media-sound/timidity++ dev-lang/nasm media-libs/mesa media-libs/glu \
dev-libs/openssl app-arch/tar

PCLinuxOS

a='' && [ "$(uname -m)" = x86_64 ] && a=64
apt-get install gcc-c++ make cmake lib${a}SDL-devel mercurial zlib1-devel \
lib${a}bzip2-devel lib${a}jpeg62-devel lib${a}fluidsynth1-devel \
lib${a}gtk+2.0_0-devel TiMidity++ nasm lib${a}mesagl1-devel \
lib${a}openssl-devel tar

Solus

sudo eopkg install g++ make cmake binutils glibc-devel pkg-config \
sdl1-devel mercurial zlib-devel bzip2-devel libjpeg-turbo-devel \
fluidsynth-devel libgtk-2-devel nasm mesalib-devel libglu-devel \
openssl-devel tar

Do the following sections as normal user.

Enable Mercurial extensions

This section is optional, and is required only if you intend to build a specific topic. Doing so requires the topic and evolve extensions to be enabled. Some distros may package these separately from the base Mercurial package, so check your package manager.

Add the following to the extensions section of ~/.hgrc:

[extensions]
topic = 
evolve =

Create zandronum_build directory

mkdir -pv ~/zandronum_build

Download and prepare the source

Download the Zandronum source and create buildclient and buildserver directories:

cd ~/zandronum_build &&
hg clone https://foss.heptapod.net/zandronum/zandronum-stable zandronum &&
mkdir -pv zandronum/buildclient zandronum/buildserver

Download FMOD

Download FMOD 4.44.64 and extract files to zandronum directory:

cd ~/zandronum_build &&
wget -nc https://zandronum.com/essentials/fmod/fmodapi44464linux.tar.gz &&
tar -xvzf fmodapi44464linux.tar.gz -C zandronum

Compiling

To compile Zandronum client:

a='' && [ "$(uname -m)" = x86_64 ] && a=64
c="$(lscpu -p | grep -v '#' | sort -u -t , -k 2,4 | wc -l)" ; [ "$c" -eq 0 ] && c=1
cd ~/zandronum_build/zandronum/buildclient &&
rm -f output_sdl/liboutput_sdl.so &&
if [ -d "../fmodapi44464linux" ]; then
f="-DFMOD_LIBRARY=../fmodapi44464linux/api/lib/libfmodex${a}-4.44.64.so \
-DFMOD_INCLUDE_DIR=../fmodapi44464linux/api/inc"; else
f='-UFMOD_LIBRARY -UFMOD_INCLUDE_DIR'; fi &&
cmake .. -DCMAKE_BUILD_TYPE=Release -DSERVERONLY=OFF -DRELEASE_WITH_DEBUG_FILE=OFF $f &&
make -j$c

A development version of Zandronum client will be compiled if you do not do #Latest stable version.

Assuming all goes well, a zandronum binary should be produced. To start Zandronum client, the following command should work:

./zandronum

To compile Zandronum server:

c="$(lscpu -p | grep -v '#' | sort -u -t , -k 2,4 | wc -l)" ; [ "$c" -eq 0 ] && c=1
cd ~/zandronum_build/zandronum/buildserver &&
cmake .. -DCMAKE_BUILD_TYPE=Release -DSERVERONLY=ON -DRELEASE_WITH_DEBUG_FILE=OFF &&
make -j$c

A development version of Zandronum server will be compiled if you do not do #Latest stable version.

Assuming all goes well, a zandronum-server binary should be produced. To start Zandronum server, the following command should work:

./zandronum-server

If Zandronum complains you do not have any IWADs set up, make sure that you have your IWAD files placed in the same directory as Zandronum, in ~/.config/zandronum/, ~/.zandronum/, $DOOMWADDIR, or /usr/local/share/. Alternatively, you can edit ~/.config/zandronum/zandronum.ini or ~/.zandronum/zandronum.ini to set the path for your IWADs.

Latest stable version

Show the latest stable version:

cd ~/zandronum_build/zandronum &&
u="$(hg log -l1 -k 'changed the version string to' \
--template '{node|short}\n')"; echo "$u ZA_$(hg log -r $u --template '{desc}\n' |
sed -n 's/.*changed the version string to \(.*\)/\1/p')"

If you want to compile the latest stable version, run:

cd ~/zandronum_build/zandronum &&
hg update -c $(hg log -l1 -k 'changed the version string to' --template '{node}\n')

and compile.

After compiling, backing up and optionally installing the latest stable version, run:

cd ~/zandronum_build/zandronum &&
hg update

A specific Zandronum version by UTC commit date

To compile a specific Zandronum version, for example 3.0-alpha-170806-2040; first, checkout the commit that matches 170806-2040. From left to right, 17 (2017) is the year, 08 is the month, 06 is the day, 20 is the hour, 40 is the minute and the time zone is +0000:

cd ~/zandronum_build/zandronum &&
hg update -cd '2017-08-06 20:40 +0000'

Now go to #Compiling.

After compiling, backing up and optionally installing Zandronum, run:

cd ~/zandronum_build/zandronum &&
hg update

Older versions

First, show the Zandronum version you are currently on:

w='r ' && [ "$(uname -s)" = Linux ] && w='d @'
cd ~/zandronum_build/zandronum &&
v="$(sed -n 's/.*#define GAMEVER_STRING "\(.*\)".*/\1/p' src/version.h)\
$(sed -n 's/.*#define DOTVERSIONSTR GAMEVER_STRING "\(.*\)".*/\1/p' src/version.h)\
$(date -u$w$(hg log -r . --template '{date}\n' | cut -d'.' -f1) +'-%y%m%d-%H%M')\
$(hg id -i | sed '/+$/!s/.*//;s/.*+$/M/')" &&
echo $v

If the Zandronum version you are currently on is 2.x or lower, do the following:

To compile Zandronum 2.x or older versions, you need to install gcc 4.9 or lower:

sudo apt-get install gcc-4.9 g++-4.9

Inside the buildclient and buildserver directories, run cmake with these arguments -DCMAKE_C_COMPILER=/path/to/compiler/gcc -DCMAKE_CXX_COMPILER=/path/to/compiler/g++, for example:

cd ~/zandronum_build/zandronum/buildclient &&
cmake .. -DCMAKE_C_COMPILER=/usr/bin/gcc-4.9 \
-DCMAKE_CXX_COMPILER=/usr/bin/g++-4.9
cd ~/zandronum_build/zandronum/buildserver &&
cmake .. -DCMAKE_C_COMPILER=/usr/bin/gcc-4.9 \
-DCMAKE_CXX_COMPILER=/usr/bin/g++-4.9

and compile.

If you are going to compile Zandronum 1.0 (120819-2011) and your Mesa version is 9.x or higher:

glxinfo | grep 'OpenGL version'

apply the fix from commit a69d59da0f51, otherwise the Zandronum client will not compile.

Backup

If you want to backup Zandronum, do the following:

Create and name a directory with the corresponding Zandronum version/revision, build type and copy zandronum, zandronum-server, zandronum.pk3, skulltag_actors.pk3 and liboutput_sdl.so to it:

cd ~/zandronum_build/zandronum &&
e=buildclient && i=buildserver && if [ -f "$e/CMakeCache.txt" ]; then
j="$(sed -n 's/.*CMAKE_BUILD_TYPE:STRING=\(.*\)/\1/p' $e/CMakeCache.txt)"; else j=''; fi &&
if [ -f "$i/CMakeCache.txt" ]; then
k="$(sed -n 's/.*CMAKE_BUILD_TYPE:STRING=\(.*\)/\1/p' $i/CMakeCache.txt)"; else k=''; fi &&
if [ -n "$j" ]; then b="-BuildType$j"; elif [ -n "$k" ]; then b="-BuildType$k"; else b=''; fi &&
r=src/svnrevision.h && if [ -f "$r" ] && [ "$(hg status $r)" != "? $r" ]; then r=$r; else
r=src/gitinfo.h; fi && h="$(sed -n 's/.*#define HG_REVISION_HASH_STRING "\(.*\)".*/\1/p' $r)" &&
BACKUPZANDRONUM="../$(hg cat -r $h src/version.h | sed -n 's/.*#define GAMEVER_STRING "\(.*\)".*/\1/p')\
$(hg cat -r $h src/version.h | sed -n 's/.*#define DOTVERSIONSTR GAMEVER_STRING "\(.*\)".*/\1/p')\
$(sed -n 's/.*#define SVN_REVISION_STRING "\(.*\)".*/\-\1/p' $r)\
$(sed -n 's/.*#define HG_TIME "\(.*\)".*/\-\1/p' $r)-$h$b" &&
mkdir -pv "$BACKUPZANDRONUM" &&
x="$e" && y="$e/zandronum.pk3" && z="$i/zandronum.pk3" &&
if [ -f "$y" ] && [ -f "$z" ] && [ "$z" -nt "$y" ]; then
x="$i"; elif [ ! -f "$y" ] && [ -f "$z" ]; then x="$i"; fi &&
o="$e/output_sdl/liboutput_sdl.so" && if [ -f "$o" ]; then l="$o"; else l=''; fi &&
cp -v $e/zandronum $i/zandronum-server $x/zandronum.pk3 $x/skulltag_actors.pk3 $l \
"$BACKUPZANDRONUM"/

Files are located at:

/home/<your username>/zandronum_build/<your newly created directory>

Updating

When you wish to update Zandronum, copy and paste the following:

cd ~/zandronum_build/zandronum &&
hg pull ; hg update

When the update finish, go to #Compiling.

Installation

  • zandronum / zandronum-server = Stable version
  • zandronum-alpha / zandronum-server-alpha = Development version

Commands beginning with "sudo" will require temporary superuser privileges.

If you want to install Zandronum, do the following:

Create /usr/games/zandronum and /usr/games/zandronum-alpha directories:

sudo mkdir -pv /usr/games/zandronum /usr/games/zandronum-alpha

Copy zandronum, zandronum-server, zandronum.pk3, skulltag_actors.pk3, liboutput_sdl.so and the FMOD library file to /usr/games/zandronum/ or /usr/games/zandronum-alpha/:

a='' && [ "$(uname -m)" = x86_64 ] && a=64
cd ~/zandronum_build/zandronum &&
e=buildclient && i=buildserver &&
r=src/svnrevision.h && if [ -f "$r" ] && [ "$(hg status $r)" != "? $r" ]; then r=$r; else
r=src/gitinfo.h; fi && h="$(sed -n 's/.*#define HG_REVISION_HASH_STRING "\(.*\)".*/\1/p' $r)" &&
t="$(hg id -tr $h)" && d='' && if [ -z "$(hg log -r $h -k 'changed the version string to')" ]; then
if [ "$t" = tip ] || [ -z "$t" ]; then d=-alpha; fi; fi &&
x="$e" && y="$e/zandronum.pk3" && z="$i/zandronum.pk3" &&
if [ -f "$y" ] && [ -f "$z" ] && [ "$z" -nt "$y" ]; then
x="$i"; elif [ ! -f "$y" ] && [ -f "$z" ]; then x="$i"; fi &&
o="$e/output_sdl/liboutput_sdl.so" && if [ -f "$o" ]; then l="$o \
fmodapi44464linux/api/lib/libfmodex${a}-4.44.64.so"; else l=''; fi &&
sudo cp -v $e/zandronum $i/zandronum-server $x/zandronum.pk3 $x/skulltag_actors.pk3 $l \
/usr/games/zandronum$d/

Create launch scripts:

cd ~/zandronum_build/zandronum &&
r=src/svnrevision.h && if [ -f "$r" ] && [ "$(hg status $r)" != "? $r" ]; then r=$r; else
r=src/gitinfo.h; fi && h="$(sed -n 's/.*#define HG_REVISION_HASH_STRING "\(.*\)".*/\1/p' $r)" &&
t="$(hg id -tr $h)" && d='' && if [ -z "$(hg log -r $h -k 'changed the version string to')" ]; then
if [ "$t" = tip ] || [ -z "$t" ]; then d=-alpha; fi; fi &&
printf %s "\
#! /bin/sh
export LD_LIBRARY_PATH=/usr/games/zandronum$d
exec /usr/games/zandronum$d/zandronum \"\$@\"
" > zandronum$d.sh &&
printf %s "\
#! /bin/sh
exec /usr/games/zandronum$d/zandronum-server \"\$@\"
" > zandronum-server$d.sh &&
chmod 755 zandronum$d.sh zandronum-server$d.sh &&
sudo mv -v zandronum$d.sh /usr/bin/zandronum$d &&
sudo mv -v zandronum-server$d.sh /usr/bin/zandronum-server$d

Now from a terminal you should be able to run zandronum / zandronum-alpha or zandronum-server / zandronum-server-alpha from any user account.

Uninstallation

Remove /usr/games/zandronum directory and all its files:

sudo rm -rfv /usr/games/zandronum

Remove zandronum script:

sudo rm -fv /usr/bin/zandronum

Remove zandronum-server script:

sudo rm -fv /usr/bin/zandronum-server

Remove /usr/games/zandronum-alpha directory and all its files:

sudo rm -rfv /usr/games/zandronum-alpha

Remove zandronum-alpha script:

sudo rm -fv /usr/bin/zandronum-alpha

Remove zandronum-server-alpha script:

sudo rm -fv /usr/bin/zandronum-server-alpha

Developing

This page has helped you compile Zandronum, but perhaps you are interested in debugging the code or submitting code changes or fixes for inclusion. This section is intended for more advanced users who may be unfamiliar to CMake or debugging on Linux systems.

Debugging Zandronum client

Prerequisite:

Maybe you have found a way to make Zandronum client crash, and are interested in debugging it. First, you need to compile a debug build of Zandronum client. Inside the buildclient directory, invoke CMake to set up for compiling, but this time, the build type is set to Debug:

cd ~/zandronum_build/zandronum/buildclient
cmake .. -DCMAKE_BUILD_TYPE=Debug -DSERVERONLY=OFF

Optionally, you may want to use some of the #Build options.

After CMake is done, run make or to speed up compilation, run make -j<number>, a recommended value for the -j option is the number of physical cores:

make

To run Zandronum client under a debugger such as gdb, use the following command:

gdb zandronum

Now gdb should have you in its own command prompt:

(gdb)

You probably want to log the output, so lets output to a file zandronumclientdebug.log:

(gdb) set logging on zandronumclientdebug.log

Now start Zandronum client by typing in run, and pressing enter:

(gdb) run

Or put any command line parameters to zandronum after run:

(gdb) run <command line parameters>

If Zandronum client crashes, gdb may be able to tell you the source file and line number it crashed in. Typing in the command backtrace or bt will produce information telling the last function calls, showing how execution got to the point where it crashed:

(gdb) backtrace

All output will be copied into the zandronumclientdebug.log, which can then be scrutinized later, or perhaps posted to the Bug Tracker for other developers to look at.

To exit gdb's command prompt, type quit, q or press Ctrl-D:

(gdb) quit

If you want to free up space, run make clean to remove the files generated by the compilation.

Debugging Zandronum server

Prerequisite:

Maybe you have found a way to make Zandronum server crash, and are interested in debugging it. First, you need to compile a debug build of Zandronum server. Inside the buildserver directory, invoke CMake to set up for compiling, but this time, the build type is set to Debug:

cd ~/zandronum_build/zandronum/buildserver
cmake .. -DCMAKE_BUILD_TYPE=Debug -DSERVERONLY=ON

Optionally, you may want to use some of the #Build options.

After CMake is done, run make or to speed up compilation, run make -j<number>, a recommended value for the -j option is the number of physical cores:

make

To run Zandronum server under a debugger such as gdb, use the following command:

gdb zandronum-server

Now gdb should have you in its own command prompt:

(gdb)

You probably want to log the output, so lets output to a file zandronumserverdebug.log:

(gdb) set logging on zandronumserverdebug.log

Now start Zandronum server by typing in run, and pressing enter:

(gdb) run

Or put any command line parameters to zandronum-server after run:

(gdb) run <command line parameters>

If Zandronum server crashes, gdb may be able to tell you the source file and line number it crashed in. Typing in the command backtrace or bt will produce information telling the last function calls, showing how execution got to the point where it crashed:

(gdb) backtrace

All output will be copied into the zandronumserverdebug.log, which can then be scrutinized later, or perhaps posted to the Bug Tracker for other developers to look at.

To exit gdb's command prompt, type quit, q or press Ctrl-D:

(gdb) quit

If you want to free up space, run make clean to remove the files generated by the compilation.

Build options

CMake options
Options Description Example
SERVERONLY=ON Build a server only binary. cmake .. -DSERVERONLY=ON
NO_GTK=ON Disable GTK+ dialogs. cmake .. -DNO_GTK=ON
NO_SOUND=ON Disable sound support. cmake .. -DNO_SOUND=ON
NO_GL=ON Disable OpenGL support. cmake .. -DNO_GL=ON
NO_ASM=ON Disable assembly code. cmake .. -DNO_ASM=ON
RELEASE_WITH_DEBUG_FILE=ON Create the debug symbols file for the release build. cmake .. -DRELEASE_WITH_DEBUG_FILE=ON
FMOD_LIBRARY Set path for FMOD library file. cmake .. -DFMOD_LIBRARY=/path/to/libfmodex(64)-x.y.z.so
FMOD_INCLUDE_DIR Set path for FMOD include directory. cmake .. -DFMOD_INCLUDE_DIR=/path/to/include/dir
CMAKE_C_COMPILER Set path for C compiler. cmake .. -DCMAKE_C_COMPILER=/path/to/compiler/gcc
CMAKE_CXX_COMPILER Set path for C++ compiler. cmake .. -DCMAKE_CXX_COMPILER=/path/to/compiler/g++
CMake build types
Types Description Example
Debug Debug information, -O1 optimization. cmake .. -DCMAKE_BUILD_TYPE=Debug
Release No debug information, -O3 optimization. cmake .. -DCMAKE_BUILD_TYPE=Release
RelWithDebInfo Debug information, -O2 optimization. Useful for finding optimization bugs that only show up in Release. cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo
MinSizeRel Similar to Release but with less optimizations in order to save space. cmake .. -DCMAKE_BUILD_TYPE=MinSizeRel

How to increase Zandronum/GZDoom OpenGL FPS

Commands beginning with "sudo" will require temporary superuser privileges.

Run Zandronum/GZDoom, start a new game, open console and type vid_fps 1, see how many FPS are displayed and exit Zandronum/GZDoom.

If you do not use Intel graphics, go to #Disable Vertical Synchronization for Zandronum/GZDoom.

Enable SandyBridge's New Acceleration

Prerequisite:

Debian/Ubuntu

  • xserver-xorg-video-intel >= 2.19

Fedora

  • xorg-x11-drv-intel >= 2.19

openSUSE

  • xf86-video-intel >= 2.19

Mageia

  • x11-driver-video-intel >= 2.19

Arch Linux

  • xf86-video-intel >= 2.19

Gentoo

  • x11-drivers/xf86-video-intel >= 2.19

PCLinuxOS

  • x11-driver-video-intel >= 2.19

Solus

  • xorg-driver-video-intel >= 2.19

If your Intel driver version is 2.21.14-1 / 2.21.15-2 or higher:

grep 'SNA compiled:' /var/log/Xorg.0.log

go to #Disable Vertical Synchronization for Zandronum/GZDoom.

Intel SNA is useful on all Intel graphics, not just SandyBridge.

Create /etc/X11/xorg.conf.d directory:

sudo mkdir -pv /etc/X11/xorg.conf.d

Create 99-intel.conf file:

cat <<'EOF' > 99-intel.conf
Section "Device"
    Identifier "Intel Graphics"
    Driver "intel"
    Option "AccelMethod" "sna"
EndSection
EOF

Move 99-intel.conf to /etc/X11/xorg.conf.d/:

sudo mv -v 99-intel.conf /etc/X11/xorg.conf.d/

and logout and login.

Disable Vertical Synchronization for Zandronum/GZDoom

Do the following step if you are using a GZDoom version prior to commit 4eb32a50e. The following step works for the open-source graphics drivers.

Create ~/.drirc file:

cat <<'EOF' > ~/.drirc
<driconf>
    <device screen="0" driver="dri2">
        <application name="zandronum" executable="zandronum">
            <option name="vblank_mode" value="0"/>
        </application>
        <application name="gzdoom" executable="gzdoom">
            <option name="vblank_mode" value="0"/>
        </application>
    </device>
</driconf>
EOF

Run Zandronum/GZDoom, start a new game, open console and type vid_fps 1, see how many FPS are displayed, you should get more FPS than before.

Reverting changes

Remove ~/.drirc file:

rm -fv ~/.drirc

Remove 99-intel.conf file:

sudo rm -fv /etc/X11/xorg.conf.d/99-intel.conf

and logout and login.