Difference between revisions of "Cross compiling for Windows using MinGW"

From OdaWiki
 
m (colon and capitalization consistency)
 
Line 1: Line 1:
 
This document is written for Debian and Ubuntu users. The process should be similar for other distributions, but installing the prerequisites will most likely be different.
 
This document is written for Debian and Ubuntu users. The process should be similar for other distributions, but installing the prerequisites will most likely be different.
  
===Step 1: Installing and Configuring the Prerequisites===
+
===Step 1: Installing and configuring the prerequisites===
 
In order to build Windows binaries, you'll need MinGW, SDL, and SDL_mixer. This tutorial also assumes you're building the latest revision, so you'll need Subversion.
 
In order to build Windows binaries, you'll need MinGW, SDL, and SDL_mixer. This tutorial also assumes you're building the latest revision, so you'll need Subversion.
  
Line 12: Line 12:
 
<pre>sudo ln -s /usr/bin/i586-mingw32msvc-g++ /usr/bin/mingw32-g++</pre>
 
<pre>sudo ln -s /usr/bin/i586-mingw32msvc-g++ /usr/bin/mingw32-g++</pre>
  
Download SDL and SDL_mixer"
+
Download SDL and SDL_mixer:
  
 
<pre>wget http://www.libsdl.org/release/SDL-devel-1.2.13-mingw32.tar.gz
 
<pre>wget http://www.libsdl.org/release/SDL-devel-1.2.13-mingw32.tar.gz
Line 46: Line 46:
  
 
===Step 2: Downloading the source===
 
===Step 2: Downloading the source===
Use Subversion to check out a copy of the source
+
Use Subversion to check out a copy of the source:
  
 
<pre>svn co http://odamex.net/svn/root/trunk odamex-win32</pre>
 
<pre>svn co http://odamex.net/svn/root/trunk odamex-win32</pre>
  
Change to the source directory
+
Change to the source directory:
  
 
<pre>cd odamex-win32</pre>
 
<pre>cd odamex-win32</pre>

Latest revision as of 04:44, 7 May 2008

This document is written for Debian and Ubuntu users. The process should be similar for other distributions, but installing the prerequisites will most likely be different.

Step 1: Installing and configuring the prerequisites

In order to build Windows binaries, you'll need MinGW, SDL, and SDL_mixer. This tutorial also assumes you're building the latest revision, so you'll need Subversion.

Subversion and MinGW are in the repositories, so to install them, type:

sudo apt-get install mingw32 subversion

Odamex expects the g++ compiler to be named mingw32-g++, create a link:

sudo ln -s /usr/bin/i586-mingw32msvc-g++ /usr/bin/mingw32-g++

Download SDL and SDL_mixer:

wget http://www.libsdl.org/release/SDL-devel-1.2.13-mingw32.tar.gz
wget http://www.libsdl.org/release/SDL-1.2.13-win32.zip
wget http://www.libsdl.org/projects/SDL_mixer/release/SDL_mixer-devel-1.2.8-VC8.zip

Extract the archives:

tar zxvf SDL-devel-1.2.13-mingw32.tar.gz
unzip SDL-1.2.13-win32.zip SDL.dll -d SDL-1.2.13/lib/
unzip SDL_mixer-devel-1.2.8-VC8.zip

The sdl-config utility needs to be modified to contain the correct prefix:

mv SDL-1.2.13/bin/sdl-config SDL-1.2.13/bin/sdl-config.bak
cat SDL-1.2.13/bin/sdl-config.bak | \
    sed 's/\/Users\/hercules\/tmp\/SDL-1.2.13/\/usr\/i586-mingw32msvc/' \
    > SDL-1.2.13/bin/sdl-config
chmod +x SDL-1.2.13/bin/sdl-config

Move the files where they belong:

sudo mv SDL-1.2.13/bin/sdl-config /usr/i586-mingw32msvc/bin/
sudo mv SDL-1.2.13/include/SDL/* /usr/i586-mingw32msvc/include/
sudo mv SDL-1.2.13/lib/* /usr/i586-mingw32msvc/lib/
sudo mv SDL_mixer-1.2.8/include/* /usr/i586-mingw32msvc/include/
sudo mv SDL_mixer-1.2.8/lib/* /usr/i586-mingw32msvc/lib/

You don't need the archives or what's left of their contents anymore. Delete them:

rm -rf SDL-1.2.13 SDL_mixer-1.2.8 SDL-devel-1.2.13-mingw32.tar.gz \
    SDL-1.2.13-win32.zip SDL_mixer-devel-1.2.8-VC8.zip

Step 2: Downloading the source

Use Subversion to check out a copy of the source:

svn co http://odamex.net/svn/root/trunk odamex-win32

Change to the source directory:

cd odamex-win32

Step 3: Compiling

Add the MinGW bin directory to your PATH so that the correct sdl-config is used:

PATH="/usr/i586-mingw32msvc/bin:$PATH"

And compile:

make -f Makefile.win

Step 4: Installing

The exe files are in the bin directory. A few more files are still needed to run in Windows. Copy them there:

cp /usr/i586-mingw32msvc/lib/SDL.dll /usr/i586-mingw32msvc/lib/SDL_mixer.dll \
    README odamex.wad odasrv.cfg bin/

You're all done! Copy the bin directory to a Windows machine and enjoy.