--- /dev/null
+[[!meta title="cross-compiling a Windows binary under Linux using MinGW"]]
+
+## Howto: cross-compiling a Windows binary under Linux using MinGW
+
+This howto describes how to create a Windows binary of tinc. Although it is
+possible to compile tinc under Windows itself, cross-compiling it under Linux
+is much faster. It is also much easier to get all the dependencies in a modern
+distribution. Therefore, this howto deals with cross-compiling tinc with MinGW
+under Linux on a Debian distribution.
+
+### Overview
+
+The idea is simple:
+
+* Install MinGW and Wine.
+* Create a directory where we will perform all cross-compilations.
+* Get all the necessary sources.
+* Cross-compile everything.
+
+### Installing the prerequisites for cross-compilation
+
+There are only a few packages that need to be installed as root to get started:
+
+> sudo apt-get install mingw32 wine git-core
+> sudo apt-get build-dep tinc
+
+### Setting up the build directory and getting the sources
+
+We will create a directory called `mingw/` in the home directory.
+We use apt-get to get the required libraries necessary for tinc.
+
+> mkdir $HOME/mingw
+> cd $HOME/mingw
+> apt-get source openssl liblzo2-dev zlib1g-dev
+> git clone git://tinc-vpn.org/tinc
+
+### Creating the mingw script
+
+To make cross-compiling easy, we install a script called `mingw` that will set
+up the necessary environment variables so configure scripts and Makefiles will
+use the MinGW version of GCC and binutils:
+
+> mkdir $HOME/bin
+> cat >$HOME/bin/mingw << EOF
+> #!/bin/sh
+> export CC=i586-mingw32msvc-gcc
+> export CXX=i586-mingw32msvc-g++
+> export CPP=/usr/bin/i586-mingw32msvc-cpp
+> export RANLIB=i586-mingw32msvc-ranlib
+> export PATH="/usr/i586-mingw32msvc/bin:$PATH"
+> exec "$@"
+> EOF
+
+If `$HOME/bin` is not already part of your `$PATH`, you need to add it:
+
+> export PATH="$HOME/bin:$PATH"
+
+You can also run the export commands from the `mingw` script by hand instead of
+calling the mingw script for every `./configure` or `make` command, or execute
+`$HOME/bin/mingw $SHELL` to get a shell with the right environment variables
+set.
+
+### Compiling LZO
+
+Cross-compiling LZO is easy:
+
+> cd $HOME/lzo2-2.03
+> mingw ./configure --host=mingw32
+> mingw make
+> DESTDIR=$HOME/mingw mingw make install
+
+### Compiling Zlib
+
+Cross-compiling Zlib is also easy, but a plain `make` failed to compile the
+tests, so we only build the static library here:
+
+> cd $HOME/mingw/zlib-1.2.3.3.dfsg
+> mingw ./configure
+> mingw make libz.a
+> DESTDIR=$HOME/mingw mingw make install
+
+### Compiling OpenSSL
+
+OpenSSL is always a bit hard to compile, because they have their own
+`Configure` script that needs some tweaking. There is also a small bug in
+e_os2.h that breaks compilation with recent versions of GCC. First download this [[openssl-cross-compilation.diff]] to your home directory, then patch OpenSSL, and then compile as usual:
+
+> cd $HOME/mingw/openssl-0.9.8k
+> patch < $HOME/openssl-cross-compilation.diff
+> mingw ./Configure --openssldir=$HOME/mingw/usr/local mingw
+> mingw make
+> mingw make install
+
+### Compiling tinc
+
+Now that all the dependencies have been cross-compiled, we can cross-compile
+tinc. Since we use a clone of the git repository here, we need to run
+`autoreconf` first. If you want to cross-compile tinc from a released tarball,
+this is not necessary.
+
+> cd $HOME/mingw/tinc
+> autoreconf -fsi
+> mingw ./configure --host=mingw32 -with-openssl=$HOME/mingw/usr/local
+> mingw make
+
+### Testing tinc
+
+Since Wine was installed, you can execute the resulting binary even on Linux.
+You cannot do much however, since tinc requires a TAP-Win32 device, which is
+not available in Wine. Still, the following command should work:
+
+> $HOME/mingw/tinc/src/tincd.exe --help
+
--- /dev/null
+--- Configure.orig 2009-10-04 19:33:46.232068938 +0200
++++ Configure 2009-10-04 19:23:29.502125839 +0200
+@@ -1,4 +1,4 @@
+-#!/usr/local/bin/perl
++#!/usr/bin/perl
+ eval 'exec perl -S $0 ${1+"$@"}'
+ if $running_under_some_shell;
+ ##
+@@ -1059,7 +1059,7 @@
+
+ my $IsMK1MF=scalar grep /^$target$/,@MK1MF_Builds;
+
+-$IsMK1MF=1 if ($target eq "mingw" && $^O ne "cygwin" && !is_msys());
++#$IsMK1MF=1 if ($target eq "mingw" && $^O ne "cygwin" && !is_msys());
+
+ $no_shared = 0 if ($fipsdso && !$IsMK1MF);
+
+--- e_os2.h.orig 2009-10-04 19:33:58.297912010 +0200
++++ e_os2.h 2009-10-04 19:23:29.502125839 +0200
+@@ -262,7 +262,7 @@
+ */
+ #ifdef OPENSSL_EXPORT_VAR_AS_FUNCTION
+ # define OPENSSL_IMPLEMENT_GLOBAL(type,name) \
+- extern type _hide_##name; \
++ static type _hide_##name; \
+ type *_shadow_##name(void) { return &_hide_##name; } \
+ static type _hide_##name
+ # define OPENSSL_DECLARE_GLOBAL(type,name) type *_shadow_##name(void)