There are only a few packages that need to be installed as root to get started:
-> sudo apt-get install gcc-mingw32 mingw64 git-core wget
-> sudo apt-get build-dep tinc
+ sudo apt-get install gcc-mingw32 mingw64 git-core wget
+ sudo apt-get build-dep tinc
Other Linux distributions may also have 64-bit MinGW packages, use their respective
package management tools to install them. Debian installs the cross-compiler
is missing in the amd64-mingw32msvc include directory, a workaround is to
create a symlink to the otherwise identical 32-bit version of that header file:
-> ln -s ../../i586-mingw32msvc/include/getopt.h /usr/amd64-mingw32msvc/include/getopt.h
+ ln -s ../../i586-mingw32msvc/include/getopt.h /usr/amd64-mingw32msvc/include/getopt.h
### Setting up the build directory and getting the sources
apt-get and wget to get the required libraries necessary for tinc, and use
`git` to get the latest development version of tinc.
-> mkdir $HOME/mingw64
-> cd $HOME/mingw64
-> apt-get source liblzo2-dev zlib1g-dev
-> wget http://www.openssl.org/source/openssl-1.0.0.tar.gz
-> tar xzf openssl-1.0.0.tar.gz
-> git clone git://tinc-vpn.org/tinc
+ mkdir $HOME/mingw64
+ cd $HOME/mingw64
+ apt-get source liblzo2-dev zlib1g-dev
+ wget http://www.openssl.org/source/openssl-1.0.0.tar.gz
+ tar xzf openssl-1.0.0.tar.gz
+ git clone git://tinc-vpn.org/tinc
### Making cross-compilation easy
up the necessary environment variables so configure scripts and Makefiles will
use the 64-bit MinGW version of GCC and binutils:
-> mkdir $HOME/bin
-> cat >$HOME/bin/mingw64 << EOF
-> #!/bin/sh
-> export CC=amd64-mingw32msvc-gcc
-> export CXX=amd64-mingw32msvc-g++
-> export CPP=amd64-mingw32msvc-cpp
-> export RANLIB=amd64-mingw32msvc-ranlib
-> export PATH="/usr/amd64-mingw32msvc/bin:$PATH"
-> exec "$@"
-> EOF
+ mkdir $HOME/bin
+ cat >$HOME/bin/mingw64 << EOF
+ #!/bin/sh
+ export CC=amd64-mingw32msvc-gcc
+ export CXX=amd64-mingw32msvc-g++
+ export CPP=amd64-mingw32msvc-cpp
+ export RANLIB=amd64-mingw32msvc-ranlib
+ export PATH="/usr/amd64-mingw32msvc/bin:$PATH"
+ exec "$@"
+ EOF
+ chmod u+x $HOME/bin/mingw64
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.
Cross-compiling LZO is easy:
-> cd $HOME/mingw64/lzo2-2.03
-> ./configure --host=amd64-mingw32msvc
-> make
-> DESTDIR=$HOME/mingw64 make install
+ cd $HOME/mingw64/lzo2-2.03
+ ./configure --host=amd64-mingw32msvc
+ make
+ DESTDIR=$HOME/mingw64 make install
If it fails with a message about not passing the "ACC" test,
create a symlink for the missing getopt.h file as mentioned above.
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/mingw64/zlib-1.2.3.3.dfsg
-> mingw64 ./configure
-> mingw64 make libz.a
-> DESTDIR=$HOME/mingw64 mingw64 make install
+ cd $HOME/mingw64/zlib-1.2.3.3.dfsg
+ mingw64 ./configure
+ mingw64 make libz.a
+ DESTDIR=$HOME/mingw64 mingw64 make install
### Compiling OpenSSL
Although older versions will not compile, OpenSSL 1.0.0 is easy.
+However, `apt-get source` will have applied
+Debian-specific patches that break cross-compiling a Windows binary.
+You need to undo those patches first.
Do not use the `-j` option when compiling OpenSSL, it will break.
-> cd $HOME/mingw64/openssl-1.0.0
-> mingw64 ./Configure --openssldir=$HOME/mingw64/usr/local mingw64
-> mingw64 make
-> mingw64 make install
+ cd $HOME/mingw64/openssl-1.0.0
+ quilt pop -a
+ mingw64 ./Configure --openssldir=$HOME/mingw64/usr/local mingw64
+ mingw64 make
+ mingw64 make install
### Compiling tinc
`autoreconf` first. If you want to cross-compile tinc from a released tarball,
this is not necessary.
-> cd $HOME/mingw64/tinc
-> autoreconf -fsi
-> ./configure --host=amd64-mingw32msvc --with-openssl=$HOME/mingw64/usr/local
-> make
+ cd $HOME/mingw64/tinc
+ autoreconf -fsi
+ ./configure --host=amd64-mingw32msvc --with-openssl=$HOME/mingw64/usr/local
+ make