Compiling on Windows using MinGW

From OpenTTD
Revision as of 19:41, 21 November 2011 by Parody (Talk | contribs)

Jump to: navigation, search


Contents

Introduction

This page contains guidelines for compiling OpenTTD for Win32 with MinGW.

List of packages

This tutorial has been tested with the following versions of the required packages:

Installing MinGW and MSYS

  1. Download and run mingw-get-inst (the download link can be found in the previous section).
  2. Select "Use pre-packaged repository catalogues".
  3. Review and accept the License agreement.
  4. Please note that MinGW should be installed to a directory path that doesn't contain any spaces. This method has been tested with a directory path of C:\MinGW.
  5. Select C++ Compiler and MSYS Basic System as optional components.
  6. Wait until every package has been downloaded and installation is finished.

Setting up MSYS

Go to your msys folder (by default it is found at C:\MinGW\msys\1.0), open etc\fstab with a text editor (for example Notepad) and add the following line at the end of the file:

C:\MinGW\   /usr/local

On Windows 7 and Vista if you have UAC enabled, to let MSYS fully work you'll need additional steps. Go to your msys folder (C:\MinGW\msys\1.0), open msys.bat with a text editor (for example Notepad) and add the following line after @echo off:

cd "C:\MinGW\msys\1.0"

And if disk C: (or where you have msys installed) is not disk where your Windows is installed add one more line

C:

After saving the file, right click on msys.bat and choose "Run as Administrator". After that programs requiring admin rights, such as install and patch will work. (You will need right-click and run as administrator every time you run msys).

Testing MinGW/MSYS installation

  • Open the MinGW shell (MSYS).
  • Run the following commands:
    make -v
    gcc -v
  • They should output something. Check if something goes wrong.

Compilation and installation of the required packages

For additional information about the libraries, check part 7.1) of OpenTTD Readme. To compile and install these packages, first you need to install the following commands:

IN MSYS:

mingw-get install msys-wget
mingw-get install msys-unzip
mingw-get install msys-patch


If you get following error: configure: error: cannot run C compiled programs. , one of the reasons could be your anti-virus, that silently deletes a.exe binary files. Try to temporarily disable anti-virus software and compile again.

Installing Subversion

In MSYS:

wget http://sourceforge.net/projects/win32svn/files/1.7.1/svn-win32-1.7.1.zip/download
unzip svn-win32-1.7.1.zip
cd svn-win32-1.7.1
mv bin/* /usr/local/bin/
cd ..

Compiling zlib

In MSYS:

wget http://zlib.net/zlib-1.2.5.tar.gz
tar xvfz zlib-1.2.5.tar.gz
cd zlib-1.2.5
make -f win32/Makefile.gcc BINARY_PATH=/usr/local/bin INCLUDE_PATH=/usr/local/include LIBRARY_PATH=/usr/local/lib install
cd ..

Compiling libpng

In MSYS:

wget http://sourceforge.net/projects/libpng/files/libpng15/1.5.6/libpng-1.5.6.tar.xz/download
tar xvfJ libpng-1.5.6.tar.xz
cd libpng-1.5.6
mv INSTALL INSTALL.txt
./configure
make install
cd ..

Compiling liblzo2

In MSYS:

wget http://www.oberhumer.com/opensource/lzo/download/lzo-2.06.tar.gz
tar xvfz lzo-2.06.tar.gz
cd lzo-2.06
./configure --enable-static
make install
cd ..

Compiling libfreetype

In MSYS:

wget http://sourceforge.net/projects/freetype/files/freetype2/2.4.6/freetype-2.4.6.tar.gz/download
tar xvfz freetype-2.4.6.tar.gz
cd freetype-2.4.6
./configure --enable-static
make install
cd ..

Compiling xz

Liblzma (which is a part of xz) is required for compiling OpenTTD since r21044. It also needs pkg-config and its dependencies. In MSYS:

wget http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/gettext-runtime_0.18.1.1-2_win32.zip
unzip gettext-runtime_0.18.1.1-2_win32.zip -d /mingw
wget http://ftp.gnome.org/pub/gnome/binaries/win32/glib/2.26/glib_2.26.0-2_win32.zip
unzip glib_2.26.0-2_win32.zip -d /mingw
wget http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/pkg-config_0.23-3_win32.zip
unzip pkg-config_0.23-3_win32.zip -d /mingw
wget http://tukaani.org/xz/xz-5.0.3.tar.gz
tar xvfz xz-5.0.3.tar.gz
cd xz-5.0.3
./configure --enable-static --disable-threads
make install
cd ..

Compiling libicu

libicu is an optional library used for handling of right-to-left scripts (e.g. Arabic and Persian) and the natural sorting of lists. It can take a long time to compile, so you can safely omit this step if you don't require libicu.


Notice.png

Note
The application of the second patch is an optional step. It will reduce the size of compiled OpenTTD, at the cost of losing sorting data for most languages.

Content.png

Warning
Compiling with libicu will greatly increase the size of the resulting OpenTTD executable.

openttd.exe size with libicu: approx. 25 MB
openttd.exe size with libicu (reduced icudata size): approx. 10 MB
openttd.exe size without libicu: approx. 8 MB


In MSYS:

wget http://download.icu-project.org/files/icu4c/4.6/icu4c-4_6-src.zip
unzip icu4c-4_6-src.zip
cd icu
wget http://devs.openttd.org/~terkhen/libicu/libicu_4_6_mingw32.diff
patch -p1 -i libicu_4_6_mingw32.diff
wget http://devs.openttd.org/~terkhen/libicu/libicu_reduce_icudata_size.diff
patch -p1 -i libicu_reduce_icudata_size.diff
cd source
./configure --enable-static --disable-shared --disable-strict --disable-threads
make install
cd ../..

Getting the source code

Check the development FAQ for different methods for obtaining the source. If you download it without using MSYS (for example downloading the source code from the website) don't forget to place it in your home folder (by default it is C:\MinGW\msys\1.0\home\<user_name>).

Compiling OpenTTD

  1. Start MSYS.
  2. Run:
    cd ~/<path_to_source>
    ./configure
    make
    (note that ~ means your home folder)
  3. The compiling is complete when the openttd.exe file is made. It will be copied to the ./bin subfolder.
  4. To test your compilation you can run (from the same folder in which you compiled OpenTTD):
    ./bin/openttd
    Don't forget to install a base graphics set before this step if you don't have one (the simplest solution is to install OpenGFX)
  5. If you want to generate a installation bundle you can use:
    make bundle
    After this command is done you will find a complete OpenTTD ready for distribution in the ~/<path_to_source>/bundle folder.
Personal tools