Difference between revisions of "CompilingWesnoth"

From The Battle for Wesnoth Wiki
Line 57: Line 57:
  sudo apt-get install liblua-5.1-dev
  sudo apt-get install liblua-5.1-dev
In the repo of Ubunty Jaunty (64) the above line should be the following instead:
In Ubunty Jaunty (64) the above line should be the following instead:
   sudo apt-get install liblua5.1-0-dev
   sudo apt-get install liblua5.1-0-dev

Revision as of 23:07, 15 September 2009

[edit]Compiling Wesnoth


Compiling Wesnoth

This page covers compilation on a Unix-like system. See also:

Forcemstr has cross compiled for Windows using the free mingw32 tools, running under Linux.

Here's documentation of another cross compilation attempt: CompilingWesnoth/CrossCompiling

For detailed instructions and full prerequisites, please consult the current INSTALL file in the source code.

NOTE: it seems the compilation of trunk has problems with Debian Sarge see [1]


You need to have the development packages of these libraries and a compiler (such as gcc) installed to build Wesnoth. You will also need the runtime packages to actually run Wesnoth.

The following libraries are optional. If they are available at configure time, desktop notifications will be enabled:

If you attempt to build from the stable or development version from svn you will also need those packages:

  • autoconf >=2.60
  • automake >=1.9



The various SDL libraries can be found at http://www.libsdl.org/

On all linux distributions that are based on Debian (like eg Ubuntu) it should be enough to use this command (if your distribution does ship the respective series, otherwise dependencies might be outdated and you have to install the respective dependencies by hand, i.e. if your distribution does only ship wesnoth-1.4 you won't get the build dependencies for 1.6 with the following command):

sudo apt-get build-dep wesnoth

To make sure Wesnoth svn head (>=1.7.0-svn) builds, too, you might need these:

sudo apt-get install liblua-5.1-dev

In Ubunty Jaunty (64) the above line should be the following instead:

 sudo apt-get install liblua5.1-0-dev


You can get it here:

Compiling (Development branch)

In the development branch, the autotools build is deprecated and unsupported. Our future choice of build system is not yet final -- SCons and CMake are both in contention -- but for the moment all three build systems (autotools, SCons and CMake) should in general work though bugs will probably only be fixed for SCons and CMake.

Building with SCons

To build using SCons, simply type

$ scons 

in the Wesnoth top-level directory. This will perform the equivalent of "configure --enable-editor --enable-tools; make" under autotools, buiding all client-side tools. To find out more about build options, type

$ scons --help

Equivalents of many configure options will be available, and you can easily build individual targets such as wesnothd.

Because scons checks for out-of-dateness with MD5 checksums of a target's ancestors and its build environment (including compiler and linker flags), the "make clean" and "make uninstall" preliminaries that you need for safety under autotools won't be necessary.

Building with CMake

CMake supports so called "out of tree" builds. That is you compile in a place completely different from the folder where your checkout is in. To do so, simply create a folder to compile in and call cmake with the path to your checkout. Of course you can also just call cmake from the checkout folder with a plain cmake ., but this is boring, isn't it?

To have cmake build wesnoth in a new dir called cmake_build_dir, just use these commands (PATH/TO/WESNOTH/TOPLEVEL-DIR means the base of your svn checkout or the folder where you extracted the tarball to, not src/ in there!):

$ mkdir cmake_build_dir
$ cd cmake_build_dir

This will perform the equivalent of "configure --enable-editor --enable-server" under autotools. To get an interface for editing settings, just type

$ ccmake .

in the cmake_build_dir. When done with your changes hit 'c' to configure and 'g' to generate the files and exit. In general you can either add commands to your cmake PATH/TO/WESNOTH/TOPLEVEL-DIR call, or change the parameters later on via ccmake or a cmake gui. Equivalents of many configure options are be available.

In the 2nd step you just have to build the game. This is done as with autotools using

$ make

This by default builds all the targets you activated. If you want to you can also just build specific targets like wesnothd.

Because CMake checks for out-of-dateness, the "make clean" and "make uninstall" preliminaries that you need for safety under autotools won't be necessary.

Compiling (Stable branch)

If you have an older installation, first uninstall that by changing into its source directory (i.e. the directory where you unpacked the older package) and by typing:

$ make uninstall

(It's very likely that you'll need root privileges to uninstall. To do this, check the Installing section.)

Change directory by typing

$ cd ..

You may want to delete the older unpacked package. You can do that now (or later) by typing:

$ rm -r wesnoth-1.x

(If you do it later be sure that you don't erase the new unpacked package.)

Untar the new package:

$ tar xfjv wesnoth-1.x.tar.bz2

then change directory:

$ cd wesnoth-1.x

If you have downloaded from svn run autogen.sh

$ ./autogen.sh

Once you have unpacked the source and uninstalled the old version,

$ ./configure

(you might want extra arguments to configure, for instance to build the map editor or to install with prefix, if so see below). Finally, compile with

$ make

Note: Users compiling SVN sources should 'make clean' before 'make' after any tree update.

- You can pass certain options to configure by the way, see the following example. It will install the whole game to /opt/games/wesnoth-1.2 and create the binary for the editor. The editor binary will be called wesnoth_editor.

$ ./configure --prefix=/opt/games/wesnoth-1.2 --enable-editor

- You also can specify compiler options using environment variables. For example, if you want to build a version using optimization you would run the following before running ./configure. (Post 1.1.8 note: the default optimization is now -O2)

$ CXXFLAGS="-O2" ; export CXXFLAGS

- If you would like to keep a version separated from other versions and attach a version suffix you could do this. In your users dir you will have the dir .wesnoth-1.2 for your preferences. The program itself will be called wesnoth-1.2 and the datadir will be the in the default path but named wesnoth-1.2. Remember that the path to the preferences dir is always relative. Absolute paths are not supported.

$ ./configure --with-preferences-dir=.wesnoth-1.2 --program-suffix=-1.2 --with-datadir-name=wesnoth-1.2

Some more configure options are shown when running ./configure --help.


Become superuser, so that you have permission to install.

$ su
  Password: /*doesn't show*/

Now that you have permission, install it. If you are using autotools:

# make install

or for smaller binaries,

# make install-strip

Installing using SCons

If you are using SCons:

# scons install

Installing using CMake

If you are using CMake, installing basically happens the same way as when using autotools. When authorized as admin (see above), just type this:

# make install

See also