Compiling on (GNU/)Linux and *BSD

From OpenTTD
(Redirected from Compiling on Linux)
Jump to: navigation, search

A quick guide to get started with OpenTTD development on Linux and other *nix-like systems. For help with compiling on various platforms, join #openttd on OFTC.


1. Required/recommended software and how to install it

  • Compiler: gcc/g++ or CLang/CLang++ (this guide uses GCC). Required.
  • Libraries:
    • Graphics and sound: SDL and/or Allegro. Required except for dedicated servers. LibPNG (depends on ZLib) is also recommended, it allows making PNG screenshots.
    • Music: TiMidity, directly or with Allegro as a front-end. Other external MIDI players can also be used. Recommended; not strictly speaking a build requirement, but the only way to play music, since the music driver using the TiMidity library directly (libtimidity, doesn't work; the library itself hasn't been updated in years.
    • File compression/decompression: LZO2 (oldest saves), ZLib (most saves up to 1.0.5, as well as downloaded content), LZMA (newest saves). Strongly recommended.
    • Text: Freetype2, Fontconfig (TrueType fonts), ICU (list sorting). Recommended.
  • Utility programs:
    • Version control system, if you want to keep your source recent: Mercurial, Subversion or Git. Subversion is fastest and is thus the one used in this guide.
    • To apply patches: the patch utility.

Instructions for the various distributions should also be applicable to derivatives of them. Text that looks like this is a shell command.


(tested on Mandriva 2009 Spring)

urpmi gcc gcc-c++ libsdl-devel zlib1-devel subversion patch patchutils

Debian, Ubuntu

Tested on Ubuntu 13.10


To install the same dependencies used by the official packages, run:

sudo apt-get build-dep openttd

This will not install any utility programs. For that:

sudo apt-get install subversion patch



  • build-essential (for compilers)
  • pkg-config (required by configure script)
  • libsdl1.2-dev
  • zlib1g-dev
  • liblzo2-dev
  • liblzma-dev
  • libpng12-dev
  • subversion
  • patch
  • timidity
  • libfontconfig6-dev
  • libicu-dev

In one command:

sudo apt-get install build-essential pkg-config libsdl1.2-dev subversion patch zlib1g-dev liblzo2-dev liblzma-dev libfontconfig-dev libicu-dev

In at least one instance the package "libsdl1.2debian-all" was required for a full installation with a PowerPC build of Debian. Without this package, only the dedicated server would compile. [1] Remark: This was not needed on a custom Debian 2.6.26-2-amd64 server when compiling r20739.



For the same dependencies as the official package:

yum-builddep openttd -y

NOTE: This does not include gcc and gcc-c++ (which you can install via (sudo) yum install gcc/gcc-c++)


  • gcc-c++
  • SDL-devel
  • libicu-devel
  • libpng-devel
  • zlib-devel
  • lzo-devel
  • xz-devel
  • subversion
  • esound (optional, for soundtrack)

In one command (as root): yum install gcc-c++ SDL-devel zlib-devel subversion esound xz-devel lzo-devel -y



For the same dependencies as the official package:

zypper source-install --build-deps-only openttd


Use YaST to download:

  • gcc-c++
  • SDL-devel
  • zlib-devel
  • libpng-devel
  • libicu-devel
  • lzo-devel
  • freetype2-devel
  • xz-devel
  • subversion (optional, could also be mercurial or git)

You can use the command-line tool `zypper' as well:

zypper install gcc-c++ SDL-devel zlib-devel libpng-devel libicu-devel lzo-devel freetype2-devel subversion


As root run emerge --onlydeps -av openttd && emerge subversion This install all dependencies as well as Subversion.

If you want to use the most current version (aka TRUNK/SVN), run the following, again as root:

Arch Linux

As root run

pacman -S --needed openttd

and it will install all the OpenTTD dependencies. It will install OpenTTD and all the dependencies. Free graphics set (openttd-opengfx) and free soundset (openttd-opensfx) are also available in the official repositories.

If you just want development environment, this should do the trick:

sudo pacman -S --needed desktop-file-utils fontconfig freetype2 hicolor-icon-theme icu libpng lzo2 sdl xz zlib

Openttd-beta, openttd-svn and openttd-32bpp PKGBUILDs are available in the AUR.


To fetch, compile and install all necessary dependencies, as root run:

cd /usr/ports/games/openttd && make depends clean

If you are going to compile OpenTTD from subversion then again, as root run:

cd /usr/ports/devel/subversion && make install clean


To fetch, compile and install all necessary dependencies run:

cd /usr/pkgsrc/games/openttd && make depends clean

If you are going to compile OpenTTD from subversion then again run:

cd /usr/pkgsrc/devel/subversion-base && make install clean

You should be asked for the root password once the code is compiled and ready for installation.


As root, do (as root) pkg_add gmake openttd to install OpenTTD with its dependencies. If you only want the dependencies, run:

pkg_add gmake icu4c lzo2 png sdl xz

You may also want to pkg_add subversion.

Warning: Since OpenBSD 6.2, amd64 and i386 users must configure OpenTTD to use clang. A plain ./configure picks gcc, but the old gcc doesn't work with the ic4uc package. Use ./configure CC=clang CXX=clang++

2. Getting the source and applying patches


You can download the .tar.gz source files from the OpenTTD website. Extracting tarball will give you a directory called openttd-<version>, where <version> is the version you downloaded. Enter this directory, and you're ready to proceed to step 3.

Nightly builds

Similar to the release option above, you can download the latest source snapshot (made every day at 1900 GMT) from the OpenTTD website. Unpack and enter the directory in which it is unpacked. Now, proceed to step 3.

Most current version (aka Trunk/SVN)

The most current version of the official code is stored in our subversion repository. Subversion makes it easy to track various versions and provides an easily shareable single location for our code. For you as a user this means you can quickly get the newest sourcecode.

Initial download

To obtain the source code from the subversion server type:

svn checkout svn:// openttd

from command line to dump the code into the directory openttd/. We will refer to this directory as you "working copy" from now on. Also, all svn commands given from now on assume your working directory is the openttd/ directory.

You can now skip to step 3 if you just want to compile the latest version.


If you have previously downloaded the code and a new version is available (iow, new revisions have been committed), you can update your working copy to the latest version. Inside your working copy run the following:

svn update

Also, if you have made any local changes to the source, these will be preserved and merged with changes in svn. If a conflict between the changes occurs, it will be flagged as conflicted (Marked "C" in svn status) (still preserving your local changes). For more information about resolving conflicts, look at the SVN Book at [2].

Creating a patch file

If you have made changes to your source that you want to share or upload as a patch, you can ask svn to generate a diff file. The command

svn diff > mypatch.diff

creates a diff file (also referred to as "patch") which you can submit to the developers to share your improvements.


You can undo changes to a file with:

svn revert filename

or to your entire working directory with:

svn revert -R .

Applying a patch

To apply a patch (diff file) to the source code, update your source code to the patch file's revision. Let's say the patch file has been made on r1234. You can see this in the first lines of the patch:

Index: foo.c
--- foo.c (revision 1234)
+++ foo.c (working copy)

To update your source code to r1234, run

svn update -r 1234

Then you're ready to merge the patch file

patch -p0 < mydiff.diff

Now (optionally) update the source code to the newest revision with

svn update

If this produces conflicts (files marked with "C"), tough luck, the patch doesn't work for the latest revision (you can always revert and retry the patching, skipping this last step and playing an older version).

3. Compiling commands, running the compiled binary

cd <directory in which the OpenTTD source code is located> and


Your system's default compiler (usually GCC) will be used -- if you want to use a specific compiler, export CC and CXX in the environment, or pass them as configure arguments. Example for clang: $ ./configure CC=clang CXX=clang++

NOTE: Without a compiler configured, you will receive the "please define the CC/CXX environment to where it is located" message when running configure. Define (export) them, or pass them as given in the example above.

This will create a Makefile. The next step is to run make; BSD users may need to run gmake instead of make. If you have changed files or updated your source, only modified code will be recompiled. Now:

make --jobs=<#>

On multi-core systems, using a high thread number (the #) can speed up compiling greatly; it's commonly recommended to use the number of logical cores (obtainable using getconf _NPROCESSORS_ONLN on Linux at least; sysctl hw.ncpu on BSD) plus one. (The theory behind this is that if one compiling thread is currently limited by I/O speed, the others should still fully saturate the available hardware threads.) For example, on an Intel i5 with two hyper-threaded cores (i.e. four logical ones), make --jobs=5 took 1 minute and 33 seconds, and plain make three minutes and 18 seconds.

There should now be an OpenTTD executable in the bin subdirectory. To install the OpenTTD binary to a directory included in your PATH variable, so it can be run as only openttd<code>, do a <code>make install as root/using sudo.

Installing TiMidity and sound fonts

In Debian/Ubuntu:

sudo apt-get install timidity freepats

In Fedora:

yum install timidity++

Timidity wants to talk to ESD, so you will need to "enable software sound mixing (ESD)" (System → Preferences → Sound).

In Arch Linux:

 pacman -S timidity++ timidity-freepats
 cp /etc/timidity++/timidity-freepats.cfg /etc/timidity++/timidity.cfg

In OpenBSD:

pkg_add timidity--

Debian package


To Do
Doesn't actually work, at least not on Ubuntu 13.04.

You should be able to build a Debian package from the latest source using the supplied debian directory. You can replace step 3 by this. This Debian directory is, conforming to OpenTTD standards, put inside the os subdirectory and needs to be moved a level up first:

mv os/debian .

After that, use normal debian tools to build the package:

dpkg-buildpackage -rfakeroot -uc -us

Installing can then be done by executing (as root): dpkg -i ../openttd-<version>_<architecture>.deb

Data files (original TTD as well as replacement) will need to be manually copied to /usr/share/games/openttd/data, since they are not included in the .deb due to licensing issues.

Now, when you run openttd, you will always be starting the version you have just built and installed.

Personal tools