Building Spring Cross Compiled: Difference between revisions

From Spring
Jump to navigationJump to search
Abma (talk | contribs)
Jk (talk | contribs)
 
(24 intermediate revisions by 3 users not shown)
Line 17: Line 17:


===Gentoo===
===Gentoo===
<code><pre>
emerge crossdev
EXTRA_ECONF="--with-dwarf2 --disable-sjlj-exceptions" crossdev -t i686-mingw32
</pre></code>
Additional instructions can be found [http://en.gentoo-wiki.com/wiki/Crossdev here] or [http://psas.pdx.edu/GentooCrossCompilerHowto/ here].


Instructions for getting a cross-compiler can be found [http://en.gentoo-wiki.com/wiki/Crossdev here] or [http://psas.pdx.edu/GentooCrossCompilerHowto/ here].
===Ubuntu 10.04===


Use the repository specified [https://launchpad.net/~tobydox/+archive/mingw mingw ppa], and then install the required packages:
<code>
  sudo add-apt-repository ppa:tobydox/mingw
  sudo apt-get update
  sudo apt-get install mingw32-x-binutils mingw32-x-gcc mingw32-x-runtime mingw-x-w32api
</code>


===Ubuntu===


Use the repository specified [https://launchpad.net/~tobydox/+archive/mingw mingw ppa], and then install the required packages:
===Ubuntu 11.10===


<code>
see the section [https://github.com/spring/spring/blob/develop/buildbot/README.markdown Recompile MinGW package with dwarf2 exceptions instead of sjlj exceptions].
sudo add-apt-repository ppa:tobydox/mingw <br>
sudo apt-get update <br>
sudo apt-get install mingw-x-binutils mingw-x-gcc mingw-x-runtime mingw-x-w32api</code>


===Other distros===
===Other distros===
Line 35: Line 43:


<code>
<code>
--with-dwarf2 --enable-shared --disable-sjlj-exceptions --enable-version-specific-runtime-libs
--with-dwarf2 --disable-sjlj-exceptions --enable-shared --enable-version-specific-runtime-libs
</code>
</code>


Line 43: Line 51:


Alternatively, use this line to compile all the deps (which will then be used instead of mingwlibs):
Alternatively, use this line to compile all the deps (which will then be used instead of mingwlibs):
 
<code><pre>make zlib boost devil ogg vorbis openal freetype sdl glew gcc</pre></code>
<code>make zlib boost devil ogg vorbis openal freetype sdl glew gcc</code>


== Getting Spring's windows dependencies ==
== Getting Spring's windows dependencies ==
Line 52: Line 59:
=== official MinGW - dwarf2 (default) ===
=== official MinGW - dwarf2 (default) ===
You can get it here ('''Download Source''' button, or use ''git''):
You can get it here ('''Download Source''' button, or use ''git''):
* [http://github.com/spring/mingwlibs/tree/boost_1.42.0_mingw_4.4.2 '''mingwlibs''' for MinGW GCC 4.4 or newer]
* [http://github.com/spring/mingwlibs '''mingwlibs''']
* [http://github.com/spring/mingwlibs '''mingwlibs''' for MinGW GCC 4.3 or older]


=== TDM MinGW - sjlj (alternative) ===
=== TDM MinGW - sjlj (alternative) ===
Line 72: Line 78:


== Create your cmake toolchain ==
== Create your cmake toolchain ==
 
Create the toolchain file:
* Create the toolchain file:
<code><pre>pico "~/spring-xcompile/win32/win32.cmake"</pre></code>
 
>> pico "~/spring-xcompile/win32/win32.cmake"
 
=== Example toolchain file ===
=== Example toolchain file ===
An example should be self-explanatory:
An example should be self-explanatory:
<pre>
<code><pre>
# the name of the target operating system
# the name of the target operating system
SET(CMAKE_SYSTEM_NAME Windows)
SET(CMAKE_SYSTEM_NAME Windows)
Line 95: Line 98:
# the path that make install will use to put the final binaries
# the path that make install will use to put the final binaries
SET(CMAKE_INSTALL_PREFIX ~/spring-xcompile/win32/final)
SET(CMAKE_INSTALL_PREFIX ~/spring-xcompile/win32/final)
</pre>
</pre></code>


Pass this with "-DCMAKE_TOOLCHAIN_FILE=~/spring-xcompile/win32/win32.cmake" to cmake or select it in the gui to make a cross-compilation (see below).
Pass this with <code>-DCMAKE_TOOLCHAIN_FILE=~/spring-xcompile/win32/win32.cmake</code> to cmake or select it in the gui to make a cross-compilation (see below).


=== Some Options Explained ===
=== Some Options Explained ===
* '''MINGWLIBS''': absolute path to the directory where [[Building_Spring_Cross_Compiled#Getting_Spring.27s_windows_dependencies |'''mingwlibs''']] are located
* '''MINGWLIBS''': absolute path to the directory where [[Building_Spring_Cross_Compiled#Getting_Spring.27s_windows_dependencies |'''mingwlibs''']] are located
* '''CMAKE_BUILD_TYPE''': ''RELEASE'' for users, ''DEBUG2'' for debugging, ''RELWITHDEBINFO'' for package devs (or ''DEBUG2'')
* '''CMAKE_INSTALL_PREFIX''': installation prefix (defaults to ''/usr/local'') defines the base directory for installing
* '''CMAKE_INSTALL_PREFIX''': installation prefix (defaults to ''/usr/local'') defines the base directory for installing
* '''DATADIR''', '''LIBDIR''', '''BINDIR''': where to install data, libraries or binaries (relative paths are based on ''CMAKE_INSTALL_PREFIX'', absolute paths are absolute (''DESTDIR'' is still respected))
* '''DATADIR''', '''LIBDIR''', '''BINDIR''': where to install data, libraries or binaries (relative paths are based on ''CMAKE_INSTALL_PREFIX'', absolute paths are absolute (''DESTDIR'' is still respected))
Line 115: Line 117:
=== The GUI method ===
=== The GUI method ===
CMake offers a nice Qt4 gui to ease the following steps (to use the gui explained here, cmake must be at least version 2.6.1). Doing so should be straightforward:
CMake offers a nice Qt4 gui to ease the following steps (to use the gui explained here, cmake must be at least version 2.6.1). Doing so should be straightforward:
* run <code>cmake-gui</code>
* select source directory
* select source directory
* select (and/or create) build directory where temporary files are stored
* select (and/or create) build directory where temporary files are stored
Line 129: Line 132:


* cd to build directory
* cd to build directory
     <code><pre>cd ~user/spring-xcompile/win32/build</pre></code>
     <code><pre>cd ~user/spring-xcompile/win32/build</pre></code>
* <code>cmake <path to source tree> <options></code> where:
* <code>cmake <path to source tree> <options></code> where:
** <code><path to source tree></code> is the path to the spring source directory
** <code><path to source tree></code> is the path to the spring source directory
Line 137: Line 138:


* IMPORTANT: depending on your settings you may need to run this command twice. It can't hurt so I recommend doing it anyway.
* IMPORTANT: depending on your settings you may need to run this command twice. It can't hurt so I recommend doing it anyway.
<code><pre>cmake "~user/spring-xcompile/spring" "-DCMAKE_TOOLCHAIN_FILE=~user/spring-xcompile/win32/win32.cmake"</pre></code>
<code><pre>cmake "~user/spring-xcompile/spring" "-DCMAKE_TOOLCHAIN_FILE=~user/spring-xcompile/win32/win32.cmake"</pre></code>
* run <code>make</code> and <code>make install</code>
* run <code>make</code> and <code>make install</code>
     <code><pre>make spring && make install-spring DESTDIR=~user/spring-xcompile/win32/final</pre></code>
     <code><pre>make spring && make install-spring DESTDIR=~user/spring-xcompile/win32/final</pre></code>


Line 147: Line 145:


== Package Maintainers Note: ==
== Package Maintainers Note: ==
** doing "make install DESTDIR=/some/path" will install spring in the specified place, putting files in subdirectories like configured. This may be helpfull when making packages so spring don'T get installed on your system for real (see also CMake FAQ [[http://www.vtk.org/Wiki/CMake_FAQ#Does_CMake.27s_.22make_install.22_support_DESTDIR.3F]]).
* doing <code>make install DESTDIR=/some/path</code> will install spring in the specified place, putting files in subdirectories like configured. This may be helpful when making packages so Spring don't get installed on your system for real (see also CMake FAQ [[http://www.vtk.org/Wiki/CMake_FAQ#Does_CMake.27s_.22make_install.22_support_DESTDIR.3F]]).
** You need to update the mime database (update-mime-database) and the kde database (kbuildsycoca) after installing to make the system aware of the newly installed mime types and desktop shortcuts.
* You need to update the mime database (<code>update-mime-database</code>) and the kde database (<code>kbuildsycoca</code>) after installing to make the system aware of the newly installed mime types and desktop shortcuts.


==Buildbot==
For setting up a buildbot slave, see: {{sourcelink|file=buildbot/README.markdown}}


= SCons cross compiling =
configure:
<pre>
MINGDIR=/usr/i586-mingw32msvc \
MINGWLIBS=${MINGWLIBS_DIR} \
CC=i586-mingw32msvc-gcc \
CXX=i586-mingw32msvc-g++ \
scons configure platform=windows debug=1 \
mingwlibsdir=${MINGWLIBS_DIR} \
builddir="${BUILD_DIR}" \
prefix="${INSTALL_DIR}" \
datadir="." \
bindir="." \
libdir="."
</pre>
make install:
<pre>
MINGDIR=/usr/i586-mingw32msvc \
CC=i586-mingw32msvc-gcc \
CXX=i586-mingw32msvc-g++ \
scons install \
builddir="${BUILD_DIR}"
</pre>
[[Category:Linux]]
[[Category:Linux]]

Latest revision as of 01:12, 19 July 2015

Development < Building Spring < Building Spring Cross Compiled

Cross-compiling allows you to build for other platforms than the machine you are building on. You can, for example, compile Windows 32-bit binaries on a Linux 64-bit machine.

Obtaining the Source

Tarballs

(For playing online official games on lobby.springrts.com - the spring lobby server)

Using Git is the recommended way to get the sources of the engine. In spite of, you can use the official tarballs to compile Spring without git.

Note: Do NOT use the zip-files from github, they are missing important data to compile Spring.

See Building spring for build instructions.

Git

Spring project page at github

Master repo URI: git://github.com/spring/spring.git
Backup repo: git://git.code.sf.net/p/springrts/code

Branches of interest:

  • master - latest stable, enforced for official games on lobby.springrts.com
  • maintenance - fixes for the latest stable
  • develop - major developments (most active, larger developments)

Assuming the GIT command line client is installed, you can clone (get locally) the repository with the commands below.

Latest Stable (master branch, useless for development purposes, lives as maintenance moving forward)

git clone --recursive git://github.com/spring/spring.git -b master

To later update it (get the changes other people did) with:

git pull --rebase

Maintenance (maintenance branch)

git clone --recursive git://github.com/spring/spring.git -b maintenance

Bleeding-edge (develop branch)

git clone --recursive git://github.com/spring/spring.git -b develop

Working with git

Please note that patches to the code must be done for either develop or maintenance. Such patches can be then sent to one of the developers with repository access. If you are new to git and github, you may want to have a look at this guide to get you started.

Note: you can switch branches this way:<syntaxhighlight lang="bash">

  1. (optional) backup your current code changes

git stash

  1. switch branch

git checkout $MY_OTHER_BRANCH

  1. sometimes needed
  2. note, it deletes all your unstashed changes and all non-pushed commits on the new branch,
  3. but it doesn't delete untracked files.
  4. git reset --hard
  1. update/sync with remote repo

git pull --rebase

  1. (optional) if you want to apply the code changes backed-up in the first step
  2. git stash pop # reapplies your changes and DELETES the backup
  3. or
  4. git stash apply --index 0 # reapplies your changes and keep the backup (see `git stash list`)

</syntaxhighlight>

Submodules

To obtain the submodules you should clone the repository with --recursive as mentioned above. If you haven't done this, you can execute the following code <syntaxhighlight lang="bash"> git submodule sync git submodule update --init

</syntaxhighlight>

To update the submodules, you have to execute the same commands again or pull normally.

CMake cross compiling

Setting up the cross compiler

The compiler is called MinGW, which is a port of GCC to windows. The version are going to need is MinGW GCC 4.4.0 (which is MinGW 2.7) or later. Most Linux distributions come with MinGW-GCC 4.1.2 only in their standard repos (Summer 2009), so you have to do extra work to get 4.4.0+.


Gentoo

emerge crossdev
EXTRA_ECONF="--with-dwarf2 --disable-sjlj-exceptions" crossdev -t i686-mingw32

Additional instructions can be found here or here.

Ubuntu 10.04

Use the repository specified mingw ppa, and then install the required packages:

  sudo add-apt-repository ppa:tobydox/mingw
  sudo apt-get update
  sudo apt-get install mingw32-x-binutils mingw32-x-gcc mingw32-x-runtime mingw-x-w32api


Ubuntu 11.10

see the section Recompile MinGW package with dwarf2 exceptions instead of sjlj exceptions.

Other distros

You have to find a way yourself, or use these instructions to get the sources and compile it yourself. When doing so, make sure to use these build flags for gcc:

--with-dwarf2 --disable-sjlj-exceptions --enable-shared --enable-version-specific-runtime-libs

you can add them under src/gcc-core.mk.

Note: This method will most likely not work anymore, as the checksum of the build files is checked by the makefile.

Alternatively, use this line to compile all the deps (which will then be used instead of mingwlibs):

make zlib boost devil ogg vorbis openal freetype sdl glew gcc

Getting Spring's windows dependencies

These are called mingwlibs. How to get them is described below.

official MinGW - dwarf2 (default)

You can get it here (Download Source button, or use git):

TDM MinGW - sjlj (alternative)

http://github.com/spring/spring/downloads

Setting up your directories

Here is my recommended layout

~/spring-xcompile/   (or wherever you want to put it all)
___ spring/   (the spring source)
___ win32/    (your target platform)
_______ build/ (the build files for your target will go here)
_______ final/ (the compiled binaries and libs will be installed here)
_______ libs/  (mingwlibs, the target libraries you just downloaded)
_______ win32.cmake (see below)

Create your cmake toolchain

Create the toolchain file:

pico "~/spring-xcompile/win32/win32.cmake"

Example toolchain file

An example should be self-explanatory:

# the name of the target operating system
SET(CMAKE_SYSTEM_NAME Windows)

# which compilers to use for C and C++
SET(CMAKE_C_COMPILER i686-mingw32-gcc)
SET(CMAKE_CXX_COMPILER i686-mingw32-g++)

# here is the target environment located
SET(CMAKE_FIND_ROOT_PATH /usr/i686-mingw32)

# the spring mingw32 dependencies
SET(MINGWLIBS ~/spring-xcompile/win32/libs)

# the path that make install will use to put the final binaries
SET(CMAKE_INSTALL_PREFIX ~/spring-xcompile/win32/final)

Pass this with -DCMAKE_TOOLCHAIN_FILE=~/spring-xcompile/win32/win32.cmake to cmake or select it in the gui to make a cross-compilation (see below).

Some Options Explained

  • MINGWLIBS: absolute path to the directory where mingwlibs are located
  • CMAKE_INSTALL_PREFIX: installation prefix (defaults to /usr/local) defines the base directory for installing
  • DATADIR, LIBDIR, BINDIR: where to install data, libraries or binaries (relative paths are based on CMAKE_INSTALL_PREFIX, absolute paths are absolute (DESTDIR is still respected))
  • APPLICATIONS_DIR, MIME_DIR, PIXMAPS_DIR: where to install freedesktop-files (icons, mime-types and application-description)

Further reference

Run CMake

The GUI method

CMake offers a nice Qt4 gui to ease the following steps (to use the gui explained here, cmake must be at least version 2.6.1). Doing so should be straightforward:

  • run cmake-gui
  • select source directory
  • select (and/or create) build directory where temporary files are stored
  • hit configure button
  • choose your build type:
    • Unix makefile if you are using linux and want to compile linux executables
    • mingw makefiles if you are working on windows
    • Unix makefile with cross compiler setup to cross-compile mingw32 executables, you have to select the toolchain file you want to use (see below)
  • configure variables to your need (move the mouse over the options and read the tooltip for further informations on them and or see Section "Options")
  • push generate button
  • open commandline and do "make" and "make install"

The commandline method

  • cd to build directory
cd ~user/spring-xcompile/win32/build
  • cmake <path to source tree> <options> where:
    • <path to source tree> is the path to the spring source directory
    • <options> are defined like -D<option name>=<value>
  • IMPORTANT: depending on your settings you may need to run this command twice. It can't hurt so I recommend doing it anyway.
cmake "~user/spring-xcompile/spring" "-DCMAKE_TOOLCHAIN_FILE=~user/spring-xcompile/win32/win32.cmake"
  • run make and make install
make spring && make install-spring DESTDIR=~user/spring-xcompile/win32/final

to show other build targets type: make help

Package Maintainers Note:

  • doing make install DESTDIR=/some/path will install spring in the specified place, putting files in subdirectories like configured. This may be helpful when making packages so Spring don't get installed on your system for real (see also CMake FAQ [[1]]).
  • You need to update the mime database (update-mime-database) and the kde database (kbuildsycoca) after installing to make the system aware of the newly installed mime types and desktop shortcuts.

Buildbot

For setting up a buildbot slave, see: buildbot/README.markdown