Compiling on (GNU/)Linux

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.

Contents

Required/recommended software

  • Compiler: gcc and g++. CLang supposedly works, but CC=clang CXX=clang ./configure && make doesn't even work for endian_check.cpp. 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.
    • 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: 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: patch.

Mandriva

(tested on Mandriva 2009 Spring) urpmi gcc gcc-c++ libsdl-devel zlib1-devel subversion patch patchutils

Debian and Ubuntu

Tested on Ubuntu 12.10

Automatically

For the same dependencies as the official package:

sudo apt-get build-dep openttd

This will not install any utility programs. For that:

sudo apt-get install subversion patch

Manually

Install:

  • build-essential (for compilers)
  • pkg-config (required by configure script)
  • libsdl1.2-dev
  • zlib1g-dev
  • liblzo2-dev
  • liblzma-dev
  • libpng12-dev
  • subversion
  • patch
  • libtimidity (broken at this time)
  • 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

libtimidity must be manually installed by downloading the source from http://sourceforge.net/projects/libtimidity/files/libtimidity/0.1.0/ and compiling (./configure --prefix=/usr && make && sudo make install) and doesn't work anyway - there's no music.

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.

Fedora

Automatically

For the same dependencies as the official package:

yum-builddep openttd -y

Manually

  • 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

openSUSE

Automatically

For the same dependencies as the official package:

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

Manually

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

Gentoo

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 openttdand 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.

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

FreeBSD

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

NetBSD

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.

Getting the source

Releases

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://svn.openttd.org/trunk 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.

Updating

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.

Reverting

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, type

$ 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).

Compiling and running

Compile OpenTTD with:

$ ./configure

This will create a Makefile, then run make. If you have changed files or updated your source, only modified code will be recompiled.

$ make -j<#>

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 plus one. For example, on an Intel i5 with two hyper-threaded cores (i.e. four logical ones), make -j5 took 1 minute and 33 seconds, and plain make three minutes and 18 seconds.

There should now be an OpenTTD executable in the bin directory.

Optional original TTD data files

Copy the GRF files from Transport Tycoon Deluxe to the data/ directory:

Windows version

  • sample.cat
  • trg1r.grf
  • trgcr.grf
  • trghr.grf
  • trgir.grf
  • trgtr.grf

DOS version

  • SAMPLE.CAT
  • TRG1.GRF
  • TRGC.GRF
  • TRGH.GRF
  • TRGI.GRF
  • TRGT.GRF

Playing the soundtrack

If you want the original TTD music you need to copy the whole gm/ directory. Additionally the TiMidity program is required:

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). To run OpenTTD with music support: $ ./openttd -m extmidi

In Arch Linux:

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

Debian package

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/ directory 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>_<something>.deb

You now have OpenTTD installed.

In step 3 you need to copy the datafiles to /usr/share/games/openttd/data, since they are not included in the .deb due to licensing issues.

Instead of running OpenTTD as $ ./openttd, you can just type $ openttd to start it.

In step 5, you need to copy the music files from the gm directory into /usr/share/games/openttd.

Personal tools