This file provides information on how to build and install Dune Legacy.

Prerequirements
---------------

- gcc or any other standard compliant C++ compiler
- autotools
- SDL 2
- SDL2-mixer


Building
--------

Dune Legacy can read the needed data from different locations. If you want 
to keep everything in one directory you should use the first method. You also
may decide to install Dune Legacy on your system. The use the second method.

Method 1: Data read from local directory
----------------------------------------
Extract the Dune Legacy source code and run at the top level directory
the following command:

autoreconf --install
./buildlocal.sh

This will configure and build Dune Legacy and you will find afterwards
a "dunelegacy" binary in the top level directory. The data is read from
the data subdirectory. There you shoud copy all the PAK-files from Dune 2

Method 2: Install Dune Legacy on your system
--------------------------------------------
Extract the Dune Legacy source code and run at the top level directory
the following commands:

autoreconf --install
./configure
make
make install

You may decide to change configure's default prefix to something else, e.g.
./configure --prefix=/usr



Updating localization
---------------------

Dune Legacy uses po files as generated by gettext. To update the template file data/locale/dunelegacy.pot and update the localizations in the *.po files run

./updatelocale.sh

To create a new locale run the following command (replacing "de" with your locale)

msginit --locale=de --input=dunelegacy.pot --output=German.de.po



Packaging/Distributions
------------

Source:
To package the source code go to the build directory and type

make dist-bzip2

This creates dunelegacy-?.tar.bz2. You might want to add a "src" to the name to get dunelegacy-?-src.tar.bz2


Debian/Ubuntu:
Make sure you have the following packages installed: build-essential, debhelper, autoconf, libsdl2-dev, libsdl2-mixer-dev and libsdl2-ttf-dev
Extract the source code from the bz2 file and change inside the source root directory (which contains configure). From there you run the following command:

dpkg-buildpackage -rfakeroot

You will get a dunelegacy_0.96-1_*.deb file one directory above.


Fedora:
You need the source tarball (see Packaging/Source in this file) and the following packages: rpm-build, gcc, gcc-c++, libstdc++-devel, SDL2-devel, SDL2_mixer-devel. Then run the following command:

rpmbuild -tb dunelegacy-?-src.tar.bz2

Under ~/rpmbuild/RPMS/<arch> you will find the created rpm file.


Gentoo:
There is an ebuild available. Go to your local portage tree and create the directory games-strategy/dunelegacy. Put the ebuild there and run

ebuild dunelegacy-?.ebuild digest
emerge dunelegacy


Mac OS X:
First you need the SDL2 and SDL2-mixer framework. Download them as dmgs from the official website, open the dmgs and copy SDL2.framework and SDL2_mixer.framework to /Library/Frameworks/.
Then open the XCode-Project from IDE/xCode/Dune Legacy.xcodeproj and build Dune Legacy. The resulting bundle will be put under IDE/xCode/build/Release.
Now go to the folder MacOSX and extract Dune Legacy.dmg.zip and then mount Dune Legacy.dmg. Put the compiled Dune Legacy bundle into the mounted dmg and unmount it afterwards.
Zip the dmg again to save a lot of download bandwidth.


Windows:
Use Code::Blocks to build the exe which will be placed in the data directory. The following DLLs are needed to run dunelegacy.exe:
libogg-0.dll
libvorbis-0.dll
libvorbisfile-3.dll
SDL2.dll
SDL2_mixer.dll
smpeg.dll

Copy them in the data directory. To create a installer you need NSIS. Compile dunelegacy.nsi with the NSIS compiler to create the installer.


Cross-compiling Windows Version on Linux:
To compile the Windows version on Linux you need to setup the mingw cross-compiler. On Debian/Ubuntu install the packages g++-mingw-w64 and nsis.
You need SDL2 and SDL2-mixer development files for Windows (These are not the same as the development files for Linux):
https://libsdl.org/release/SDL2-devel-2.0.5-mingw.tar.gz
https://www.libsdl.org/projects/SDL_mixer/release/SDL2_mixer-devel-2.0.1-mingw.tar.gz

Put a copy of the headers under /usr/i686-w64-mingw32/include and /usr/x86_64-w64-mingw32/include ; the lib files under /usr/i686-w64-mingw32/lib and /usr/x86_64-w64-mingw32/lib.

To cross-compile and create a Windows installer for Dune Legacy run the following command:

./buildcrosswin32.sh


Running unit tests
------------------

To run the unit tests from the tests directory simply run the following script

./runUnitTests.sh


Running cppcheck
----------------

cppcheck is a static analysis. The following command will run it on the source and write all errors/warnings to cppcheck.log:

cppcheck -j 5 --enable=all -D_REENTRANT -DHAS_SOCKLEN_T -I include . 2> cppcheck.log


