Compiling on Windows using MinGW

From OpenTTD
(Redirected from Compiling on MinGW)
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 (found at <MinGW installation folder>\msys\1.0, C:\MinGW\msys\1.0 in this example), 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 Vista and newer, you'll need additional steps to make MSYS fully work if User Account Control is enabled (it is by default). Go to your MSYS folder (C:\MinGW\msys\1.0 here), open msys.bat with a text editor (right-click -> Open With -> Notepad or equivalents) and add the following line after @echo off:

cd "C:\MinGW\msys\1.0"

And if your MSYS installation drive is not the disk Windows is installed on, add one more line:

C:
(MSYS drive)

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

Testing MinGW/MSYS installation

  • Open the MinGW shell (MSYS) by running msys.bat.
  • 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 and avoid the error 'wget: command not found', first you need to install the following commands: (To compile on Windows 7, the service "application experience" must be activated and running)

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.6/apache22/svn-win32-1.7.6.zip/download
unzip svn-win32-1.7.6.zip
cd svn-win32-1.7.6
mv bin/* /usr/local/bin/
cd ..

Compiling zlib

In MSYS:

wget http://zlib.net/zlib-1.2.8.tar.gz
tar xvfz zlib-1.2.8.tar.gz
cd zlib-1.2.8
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/older-releases/1.5.16/libpng-1.5.16.tar.xz/download
tar xvfJ libpng-1.5.16.tar.xz
cd libpng-1.5.16
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.10/freetype-2.4.10.tar.gz
tar zxvf freetype-2.4.10.tar.gz
cd freetype-2.4.10
./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 /usr/local
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 /usr/local
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 /usr/local
wget http://tukaani.org/xz/xz-5.0.4.tar.gz
tar xvfz xz-5.0.4.tar.gz
cd xz-5.0.4
./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

Open the MSYS shell and run

cd && svn checkout svn://svn.openttd.org/trunk

The OpenTTD source code is now in the trunk subdirectory of your MSYS home folder (<MinGW installation folder>\MSYS\1.0\home\<your Windows user name>).

Compiling OpenTTD

  1. Start MSYS.
  2. Run:
    cd ~/<path_to_source>
    ./configure
    make
    (note that ~ means your MSYS 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.

Patching the source code

Place the patch you want to apply into the directory the OpenTTD source code is located in (<MinGW installation folder>\MSYS\1.0\home\<your Windows user name>\trunk in this example). Then, in the MSYS shell:

cd ~/trunk
patch -p1/p0 < <patch name>

Use p0 for Subversion style patches, p1 for all others (it's probably a good idea to try p1 first). Explanation of the difference: FAQ development#How to apply a patch

Personal tools