Building Freeciv from source

This page documents the steps necessary to build Freeciv from source,
either from a prepackaged download, or direct from the project
subversion repository.
==Initial assumptions==
These instructions assume the following about your system:
* You are using a Unix or Unix-like operating system. This includes Unix, Linux, OSX, Cygwin and others.
* You have a C compiler available, meeting the minimum C compiler requirements.
* You have the zlib open source compression library, or compatible alternative installed.
* You have the following GNU programs, or compatible alternatives installed:
** GNU Make
** GNU Libtool
** GNU gettext
If you intend to install from a prepackaged download, you will need one
of the following file decompression/archive utilities, or compatible
alternative.
* bunzip2 and tar (file format) tar file archive utility, or compatible alternative, such as GNU Tar
* gunzip and tar (file format) tar file archive utility, or compatible alternative, such as GNU Tar
* infozip
If you intend to install from the subversion repository, or wish to
rebuild the configuration script, you will need the following programs,
or compatible alternatives installed:
* GNU Autoconf
* GNU Automake
If compiling for MinGW, you need the following dependencies:
* Libcurl development files
==Downloading and upacking==
===Prepackaged downloads===
* In a working directory, download Freeciv distribution using one of the following links:
** freeciv-2.2.1.tar.bz2
** freeciv-2.2.1.tar.gz
** freeciv-2.2.1.zip
: If you have the GNU Wget utility, you can do this using one of the following commands:
 wget http://sourceforge.net/projects/freeciv/files/Freeciv%202.2/2.2.1/freeciv-2.2.1.tar.bz2/download
 wget http://sourceforge.net/projects/freeciv/files/Freeciv%202.2/2.2.1/freeciv-2.2.1.tar.gz/download
 wget http://sourceforge.net/projects/freeciv/files/Freeciv%202.2/2.2.1/freeciv-2.2.1.zip/download
: Note: If you have installed wget in a non-standard location, you may have to specify the full path the the executable.
* Unpack the Freeciv distribution using the appropriate one of the following commands:
 bunzip2 --stdout freeciv-2.2.1.tar.bz2 | tar tf -
 gunzip --stdout freeciv-2.2.1.tar.gz | tar tf -
 unzip freeciv-2.2.1.zip
: Note: If you have installed bunzip2, gunzip, unzip or tar, in a non-standard location, you may have to specify the full path the the executable.
: You should now have a new subdirectory called freeciv-2.2.1
* Change into the newly-created directory:
 cd freeciv-2.2.1
===Subversion repository===
* Check out the latest development version of Freeciv using subversion:
 svn co svn://svn.gna.org/svn/freeciv/trunk freeciv-trunk
* Change into the newly-created directory:
 cd freeciv-trunk
==Building the configuration script==
If you are building from a distribution package, the necessary
configuration script should already be present, and you may choose to
skip this stage and go straight to configuring the build
If autoconf has been installed in a non-standard location,
you will need to set the PATH environment variable to allow the build
process to find the executable. For example, if autoconf is
installed in $HOME/install/autoconf, you will need:
 PATH="$PATH:$HOME/install/autoconf/bin"
If automake has been installed in a non-standard location,
you will need to set the PATH environment variable to allow the build
process to find the executable. For example, if automake is
installed in $HOME/install/automake, you will need:
 PATH="$PATH:$HOME/install/automake/bin"
If libtool has been installed in a non-standard location,
you will need to set the PATH environment variable to allow the build
process to find the executable, and the ACLOCAL_FLAGS environment variable
to allow autoconf to find the necessary macros to configure
Freeciv's use of libtool. For example, if libtool
is installed in $HOME/install/libtool, you will need:
 PATH="$PATH:$HOME/install/libtool/bin"
 ACLOCAL_FLAGS="-I $HOME/install/libtool/share/aclocal"; export ACLOCAL_FLAGS
If gettext has been installed in a non-standard location,
you will need to set the PATH environment variable to allow the build
process to find the executable. For example, if gettext is
installed in $HOME/install/gettext, you will need:
 PATH="$PATH:$HOME/install/gettext/bin"
You should now be able to build the configuration scripts:
 ./autogen.sh --no-configure-run
This will examine your system setup and build a suitable configuration
script. A successful result should look something like this:
+ checking for autoconf >= 2.58 ... found 2.65, ok.
+ checking for autoheader >= 2.58 ... found 2.65, ok.
+ checking for automake >= 1.6 ... found 1.9, ok.
+ checking for aclocal >= 1.6 ... found 1.9, ok.
+ checking for libtoolize >= 1.4.3 ... found 2.2, ok.
+ checking for xgettext >= 0.10.36 ... found 0.18, ok.
+ checking for msgfmt >= 0.10.36 ... found 0.18, ok.
+ running aclocal ...
+ running autoheader ... 
+ running autoconf ... 
+ running libtoolize ... 
libtoolize: putting auxiliary files in AC_CONFIG_AUX_DIR, `bootstrap'.
libtoolize: linking file `bootstrap/ltmain.sh'
libtoolize: putting macros in AC_CONFIG_MACRO_DIR, `m4'.
libtoolize: linking file `m4/libtool.m4'
libtoolize: linking file `m4/ltoptions.m4'
libtoolize: linking file `m4/ltsugar.m4'
libtoolize: linking file `m4/ltversion.m4'
libtoolize: linking file `m4/lt~obsolete.m4'
+ running automake ... 
configure.ac: installing `bootstrap/install-sh'
configure.ac: installing `bootstrap/missing'
ai/Makefile.am: installing `bootstrap/depcomp'
configure.ac:11: installing `bootstrap/config.guess'
configure.ac:11: installing `bootstrap/config.sub'
+ removing config.cache ... 
Now type 'configure' to configure freeciv.
==Dependencies==
Freeciv requires the development libraries to be available for a number of other packages. If using Ubuntu, the following command will install the dependency packages used by the Ubuntu version of Freeciv:
 sudo apt-get build-dep freeciv
Not all these packages are actually needed for building each client. For example, to build freeciv-gtk3 you will probably need to install libgtk3-dev with its prerequisites but no Qt5-related packages.
==Configuring the build==
If zlib has been installed in a non-standard location, you will
need to set the CFLAGS environment variable to allow the C compiler
and linker to find the necessary files. For example, if zlib
is installed in $HOME/install/zlib, you will need:
 CFLAGS="$CFLAGS -I $HOME/install/zlib/include"; export CFLAGS
 LDFLAGS="$LDFLAGS -L$HOME/install/zlib/lib"; export LDFLAGS
You will now need to run the configuration script, either as
provide in the source code distribution, or built using the above
instructions. To build just the Freeciv server, we will use the
--enable-client=stub option.
You will need to decide where you want the Freeciv files installed.
This is specified using the --prefix option. For example,
if you want to install Freeciv in $HOME/install/freeciv
you will need to specify --prefix=$HOME/install/freeciv.
Other configuration options are available, and are discussed elsewhere.
When you are ready, run configure with your chosen options.
For example:
 ./configure --enable-client=stub --prefix=$HOME/install/freeciv
This will examine your system setup and build suitable makefiles. A
successful result should look something like this:
==Building Freeciv==
Once everything is configured, building Freeciv should be straightforward. Run make:
 make
This will build Freeciv.
==Installing Freeciv==
To install Freeciv to the directory which you specifed earlier, use
make:
 make install
This will install Freeciv.
== Workarounds ==
=== When you update git branch origin and build is failed due to build in root of source directory was dissalowed ===
# Switch to 9a85bbe2c04e83742df3d5e233fec08658e36a7d (git checkout 9a85bbe2c04e83742df3d5e233fec08658e36a7d)
# clean source directory (make distclean)
# Switch back (git switch -)
# Create new directory to build (mkdir build-autoconf)
# Go inside newly created directory (cd build-autoconf)
# Perform autoconf (../autoconf.sh <your-configure-parameters>)
# That's it!
==Running the Freeciv server==
The Freeciv requires access to certain runtime libraries in order
to execute correctly. If these are installed in a standard location
on your system, they should be found automatically.
If zlib has been installed in a non-standard location, you
will need to set the LD_LIBRARY_PATH environment variable to allow the
operating system to find the runtime libraries. For example, if zlib
is installed in $HOME/install/zlib, you will need:
 LD_LIBRARY_PATH="$HOME/install/zlib/lib:$LD_LIBRARY_PATH"; export LD_LIBRARY_PATH
To start the Freeciv server, simply run the executable from the directory
into which it was installed, as specified when the build was
configured. For example, if you installed Freeciv in
$HOME/install/freeciv, you would run:
 $HOME/install/freeciv/bin/freeciv-server
This will start the Freeciv server, and wait for user input. A successful
result should look something like this:
 This is the server for Freeciv version 2.2.99-dev
 You can learn a lot about Freeciv at http://www.freeciv.org/
 2: Loading rulesets
 2: AI*1 has been added as Easy level AI-controlled player.
 2: AI*2 has been added as Easy level AI-controlled player.
 2: AI*3 has been added as Easy level AI-controlled player.
 2: AI*4 has been added as Easy level AI-controlled player.
 2: AI*5 has been added as Easy level AI-controlled player.
 2: Now accepting new client connections.
 
 For introductory help, type 'help'.
 > 
To stop the server, type the following at the > prompt:
 quit