X-Git-Url: https://www.tinc-vpn.org/git/browse?a=blobdiff_plain;f=examples%2Fcross-compiling-windows-binary.mdwn;h=5574306542839b9839c16a38f1dda72e9776632a;hb=7d39151045f32dcbdafd3a1b219964326d26a506;hp=3a2eb56a95dd4d27e040db73b82d3eb267d8b37e;hpb=39b01fe8c771163f2f426bc2dca01c4c607d9c70;p=wiki diff --git a/examples/cross-compiling-windows-binary.mdwn b/examples/cross-compiling-windows-binary.mdwn index 3a2eb56..5574306 100644 --- a/examples/cross-compiling-windows-binary.mdwn +++ b/examples/cross-compiling-windows-binary.mdwn @@ -8,6 +8,9 @@ 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. +The result is a 32-bit executable. If you want to create a 64-bit executable, +have a look at the [[64-bit cross-compilation example|examples/cross-compiling-64-bit-windows-binary]]. + ### Overview The idea is simple: @@ -21,8 +24,8 @@ The idea is simple: 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 + sudo apt-get install mingw32 wine git-core + sudo apt-get build-dep tinc Other Linux distributions may also have MinGW packages, use their respective package management tools to install them. Debian installs the cross-compiler @@ -37,10 +40,10 @@ We will create a directory called `mingw/` in the home directory. We use apt-get to get the required libraries necessary for tinc, and use `git` to get the latest development version of tinc. -> mkdir $HOME/mingw -> cd $HOME/mingw -> apt-get source openssl liblzo2-dev zlib1g-dev -> git clone git://tinc-vpn.org/tinc + mkdir $HOME/mingw + cd $HOME/mingw + apt-get source openssl liblzo2-dev zlib1g-dev + git clone git://tinc-vpn.org/tinc ### Making cross-compilation easy @@ -48,20 +51,21 @@ To make cross-compiling easy, we create 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=i586-mingw32msvc-cpp -> export RANLIB=i586-mingw32msvc-ranlib -> export PATH="/usr/i586-mingw32msvc/bin:$PATH" -> exec "$@" -> EOF + mkdir $HOME/bin + cat >$HOME/bin/mingw << EOF + #!/bin/sh + export CC=i586-mingw32msvc-gcc + export CXX=i586-mingw32msvc-g++ + export CPP=i586-mingw32msvc-cpp + export RANLIB=i586-mingw32msvc-ranlib + export PATH="/usr/i586-mingw32msvc/bin:$PATH" + exec "$@" + EOF + chmod u+x $HOME/bin/mingw If `$HOME/bin` is not already part of your `$PATH`, you need to add it: -> export PATH="$HOME/bin:$PATH" + export PATH="$HOME/bin:$PATH" We use this script to call `./configure` and `make` with the right environment variables, but only when the `./configure` script doesn't support cross-compilation itself. @@ -75,35 +79,45 @@ time it is needed. Cross-compiling LZO is easy: -> cd $HOME/mingw/lzo2-2.03 -> ./configure --host=i586-mingw32msvc -> make -> DESTDIR=$HOME/mingw make install + cd $HOME/mingw/lzo2-2.03 + ./configure --host=i586-mingw32msvc + make + DESTDIR=$HOME/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 + 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 +e_os2.h in OpenSSL 0.9.8 that breaks compilation with recent versions of GCC. +If you have this version of OpenSSL, then first download this [[openssl-cross-compilation.diff]] to your home directory, then patch -OpenSSL, and then compile as usual. Do not use the `-j` option when compiling -OpenSSL, it will break. +OpenSSL: + + cd $HOME/mingw/openssl-0.9.8k + patch < $HOME/openssl-cross-compilation.diff + +With OpenSSL 1.0.0, this problem is no longer present. However, `apt-get source` will have applied +Debian-specific patches that break cross-compiling a Windows binary. You need to undo those patches first: + + cd $HOME/mingw/openssl-0.9.8k + quilt pop -a + +Now you can compile OpenSSL. +Do not use the `-j` option when compiling OpenSSL, it will break. -> 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 + mingw ./Configure --openssldir=$HOME/mingw/usr/local mingw + mingw make + mingw make install ### Compiling tinc @@ -112,10 +126,10 @@ 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 -> ./configure --host=i586-mingw32msvc --with-openssl=$HOME/mingw/usr/local -> make + cd $HOME/mingw/tinc + autoreconf -fsi + ./configure --host=i586-mingw32msvc --with-openssl=$HOME/mingw/usr/local + make ### Testing tinc @@ -123,5 +137,5 @@ 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 + $HOME/mingw/tinc/src/tincd.exe --help