Compile UZDoom on Linux

From ZDoom Wiki
Jump to navigation Jump to search

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

Install dependencies

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

  • Required
    • gcc 4.8 or later
    • make
    • cmake 2.8.7 or later
    • SDL 2.0.2 or later
    • libGL and libGLU (SDL or libSDL pull in libGLU) or any other GL implementation provider.
    • libopenal
    • libmpg123
    • libsndfile
    • ZMusic
  • Recommended
    • GTK3 or GTK2
    • git (needed in order to download the source and compile in commit meta data)
    • nasm 0.98.39 or later (x86-32 only)
  • Optional
    • zlib (UZDoom has a copy of it and will be statically compiled in if not found)
    • libbzip2 (possibly static)
    • libjpeg (possibly static)
    • libgme or game-music-emu (possibly static)
  • Runtime
    • gxmessage (optional - needed to show the crash log in a window)
    • kdialog (optional - for KDE users)
    • fluidsynth (optional - for MIDI playback)

Install the following as root/superuser:

Debian/Ubuntu

sudo apt-get install g++ make cmake libsdl2-dev git zlib1g-dev \
libbz2-dev libjpeg-dev libfluidsynth-dev libgme-dev libopenal-dev \
libmpg123-dev libsndfile1-dev libgtk-3-dev timidity nasm libgl1-mesa-dev \
libvpx-dev ninja-build waylandpp-dev libwebp-dev

Fedora

dnf install gcc-c++ make cmake SDL2-devel git zlib-devel bzip2-devel \
libjpeg-turbo-devel fluidsynth-devel game-music-emu-devel openal-soft-devel \
libmpg123-devel libsndfile-devel gtk3-devel timidity++ nasm mesa-libGL-devel \
libvpx-devel ninja-build waylandpp-devel libwebp-devel

openSUSE

zypper install gcc-c++ make cmake libSDL2-devel git zlib-devel \
libbz2-devel libjpeg-devel fluidsynth-devel libgme-devel openal-soft-devel \
mpg123-devel libsndfile-devel gtk3-devel timidity nasm Mesa-libGL-devel \
libvpx-devel ninja waylandpp-devel libwebp-devel

Mageia

a='' && [ "$(uname -m)" = x86_64 ] && a=64
urpmi gcc-c++ make cmake lib${a}sdl2.0-devel git lib${a}zlib-devel \
lib${a}bzip2-devel lib${a}jpeg-devel lib${a}fluidsynth-devel \
lib${a}gme-devel lib${a}openal-devel lib${a}mpg123-devel lib${a}sndfile-devel \
lib${a}gtk+3.0-devel lib${a}cairo-devel TiMidity++ nasm lib${a}mesagl1-devel \
lib${a}vpx-devel ninja lib${a}waylandpp-devel lib${a}webp-devel

Arch Linux

pacman -S --needed gcc make cmake sdl2 git zlib bzip2 libjpeg-turbo \
fluidsynth libgme openal mpg123 libsndfile gtk3 timidity++ nasm \
mesa glu libvpx ninja waylandpp libwebp

Gentoo

emerge -avn sys-devel/gcc sys-devel/make dev-util/cmake media-libs/libsdl2 \
dev-vcs/git sys-libs/zlib app-arch/bzip2 media-libs/libjpeg-turbo media-sound/fluidsynth \
media-libs/game-music-emu media-libs/openal media-sound/mpg123 media-libs/libsndfile \
x11-libs/gtk+ media-sound/timidity++ dev-lang/nasm media-libs/mesa media-libs/glu \
media-libs/libvpx dev-build/ninja dev-cpp/waylandpp media-libs/libwebp

PCLinuxOS

a='' && [ "$(uname -m)" = x86_64 ] && a=64
apt-get install gcc-c++ make cmake lib${a}sdl2.0-devel git zlib1-devel lib${a}bzip2-devel \
lib${a}jpeg62-devel lib${a}fluidsynth1-devel lib${a}gme-devel lib${a}openal-devel \
lib${a}mpg123-devel lib${a}sndfile-devel lib${a}gtk+3.0-devel TiMidity++ nasm lib${a}mesagl1-devel \
lib${a}vpx-devel ninja lib${a}waylandpp-devel lib${a}webp-devel

Solus

sudo eopkg install g++ make cmake binutils glibc-devel pkg-config sdl2-devel \
git zlib-devel bzip2-devel libjpeg-turbo-devel fluidsynth-devel openal-soft-devel \
mpg123-devel libsndfile-devel libgtk-3-devel nasm mesalib-devel libglu-devel \
libvpx-devel ninja libwebp-devel

Do the following sections as normal user.

Compile ZMusic

Create zmusic_build directory:

mkdir -pv ~/zmusic_build

Download the ZMusic source and create build directory:

cd ~/zmusic_build &&
git clone https://github.com/ZDoom/ZMusic.git zmusic &&
mkdir -pv zmusic/build

To compile ZMusic:

cd ~/zmusic_build/zmusic/build &&
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr &&
make

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

cd ~/zmusic_build/zmusic &&
git pull

and compile.

To install ZMusic:

cd ~/zmusic_build/zmusic/build &&
sudo make install

To uninstall ZMusic:

cd ~/zmusic_build/zmusic/build &&
while IFS= read -r file || [ -n "$file" ]; do
sudo rm -v -- "$file"
done < install_manifest.txt

Create uzdoom_build directory

mkdir -pv ~/uzdoom_build

Download and prepare the source

Download the UZDoom source and create an out of tree build directory:

cd ~/uzdoom_build &&
git clone https://github.com/UZDoom/UZDoom.git uzdoom &&
mkdir -pv uzdoom/build

Compiling

To compile UZDoom:

cd ~/uzdoom_build/uzdoom/build &&
cmake .. -DCMAKE_BUILD_TYPE=Release -G Ninja &&
ninja

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

Assuming all goes well, a uzdoom binary should be produced. To start UZDoom, the following command should work:

./uzdoom

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

Latest stable version

Show the latest stable version:

cd ~/uzdoom_build/uzdoom &&
git tag -l | grep -v 9999 | grep -E '^g[0-9]+([.][0-9]+)*$' |
sed 's/^g//' | sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4 |
tail -n 1 | sed 's/^/g/'

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

cd ~/uzdoom_build/uzdoom &&
Tag="$(git tag -l | grep -v 9999 | grep -E '^g[0-9]+([.][0-9]+)*$' |
sed 's/^g//' | sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4 |
tail -n 1 | sed 's/^/g/')" &&
git checkout --detach refs/tags/$Tag

and compile.

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

cd ~/uzdoom_build/uzdoom &&
git checkout trunk

Backup

If you want to backup UZDoom, do the following:

Create and name a directory with the corresponding UZDoom version/revision, build type and copy uzdoom, uzdoom.pk3, lights.pk3, brightmaps.pk3, game_support.pk3 and game_widescreen_gfx.pk3 to it:

cd ~/uzdoom_build/uzdoom/build &&
if [ -f CMakeCache.txt ]; then
k="$(sed -n 's/.*CMAKE_BUILD_TYPE:STRING=\(.*\)/\1/p' CMakeCache.txt)"; else k=''; fi &&
if [ -n "$k" ]; then b="-BuildType$k"; else b=''; fi &&
BACKUPUZDOOM="../../$(sed -n 's/.*#define GIT_DESCRIPTION "\(.*\)".*/\1/p' gitinfo.h)$b" &&
mkdir -pv "$BACKUPUZDOOM" &&
cp -v uzdoom uzdoom.pk3 lights.pk3 brightmaps.pk3 game_widescreen_gfx.pk3 game_support.pk3 \
"$BACKUPUZDOOM"/

Files are located at:

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

Updating

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

cd ~/uzdoom_build/uzdoom &&
git pull

When the update finish, go to #Compiling.

Installation

  • uzdoom = Stable version
  • uzdoom-alpha = Development version

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

If you want to install UZDoom, do the following:

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

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

Copy uzdoom, uzdoom.pk3, lights.pk3, brightmaps.pk3, game_support.pk3, game_widescreen_gfx.pk3 and the soundfonts and fm_banks directories to /usr/games/uzdoom/ or /usr/games/uzdoom-alpha/:

cd ~/uzdoom_build/uzdoom/build &&
h="$(sed -n 's/.*#define GIT_HASH "\(.*\)".*/\1/p' gitinfo.h)" &&
if [ -z "$(git describe --exact-match --tags $h 2>/dev/null)" ]; then
d=-alpha; else d=''; fi &&
sudo cp -rv uzdoom uzdoom.pk3 lights.pk3 brightmaps.pk3 game_widescreen_gfx.pk3 game_support.pk3 soundfonts fm_banks \
/usr/games/uzdoom$d/

Create launch script:

cd ~/uzdoom_build/uzdoom/build &&
h="$(sed -n 's/.*#define GIT_HASH "\(.*\)".*/\1/p' gitinfo.h)" &&
if [ -z "$(git describe --exact-match --tags $h 2>/dev/null)" ]; then
d=-alpha; else d=''; fi &&
printf '%s\n' '#!/bin/sh' "exec /usr/games/uzdoom$d/uzdoom \"\$@\"" \
> uzdoom$d.sh &&
chmod 755 uzdoom$d.sh &&
sudo mv -v uzdoom$d.sh /usr/bin/uzdoom$d

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

Uninstallation

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

sudo rm -rfv /usr/games/uzdoom

Remove uzdoom script:

sudo rm -fv /usr/bin/uzdoom

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

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

Remove uzdoom-alpha script:

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

Developing

This page has helped you compile UZDoom, 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

Prerequisite:

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

cd ~/uzdoom_build/uzdoom/build
cmake .. -DCMAKE_BUILD_TYPE=Debug

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

Now run the following command to start compiling UZDoom:

cmake --build .

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

gdb uzdoom

Now gdb should have you in its own command prompt:

(gdb)

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

(gdb) set logging on uzdoomdebug.log

Now start UZDoom by typing in run, and pressing enter:

(gdb) run

Or put any command line parameters to uzdoom after run:

(gdb) run <command line parameters>

If UZDoom 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 uzdoomdebug.log, which can then be scrutinized later, or perhaps posted to the GitHub issues or Bugs forum 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
NO_GTK=ON Disables GTK+ dialogs. cmake .. -DNO_GTK=ON
NO_OPENAL=ON Disables OpenAL sound support. cmake .. -DNO_OPENAL=ON
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_EXPORT_COMPILE_COMMANDS=ON Enables the generation of a compile_commands.json file. cmake .. -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
BUILD_SHARED_LIBS=OFF Disables shared libraries. cmake .. -DBUILD_SHARED_LIBS=OFF
G Ninja Use Ninja for the compilation process. cmake .. -G Ninja
G "Unix Makefiles" Use Make for the compilation process. cmake .. -G "Unix Makefiles"
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

External links