## Instructions for building Tor with MinGW (http://www.mingw.org/)
##

Stage One:  Download and Install MinGW.
---------------------------------------

Download mingw:
http://prdownloads.sf.net/mingw/MinGW-5.0.3.exe?download

Download msys:
http://prdownloads.sf.net/mingw/MSYS-1.0.10.exe?download

Download the mingw developer tool kit:
http://prdownloads.sf.net/mingw/msysDTK-1.0.1.exe?download

Download the mingw win32api:
http://prdownloads.sf.net/mingw/w32api-3.6.tar.gz?download

Install mingw, msys and mingw-dtk.

Stage Two:  Download, extract, compile openssl
----------------------------------------------

Download openssl:
http://www.openssl.org/source/openssl-0.9.8c.tar.gz

Extract openssl:
cp openssl-0.9.8c.tar.gz tor-mingw/
cd tor-mingw/
tar zxf openssl-0.9.8c.tar.gz

Make openssl.dll:
cd tor-mingw/openssl-0.9.8c/
cd crypto/
find ./ -name "*.h" -exec cp {} ../include/openssl/ \;
find ./ -type f -name "*.c" -exec cp {} ../test/ \;
cd ../ssl/
find ./ -name "*.h" -exec cp {} ../include/openssl/ \;
cd ..
cp *.h include/openssl/
cp ssl/ssltest.c test/
Edit Makefile and remove the "test" and "tests" sections.
rm -rf ./test
./Configure mingw
make

Note: this fails in test due to: 
make[1]: *** No rule to make target `sha256t.o', needed by `sha256t.exe'.  Stop.
--need to research this - phobos

Alternatively:
Download the pre-compiled openssl for win32.
Install and proceed.


Stage Three:  Download, extract, compile zlib
---------------------------------------------

Download zlib source:
http://www.zlib.net/zlib-1.2.3.tar.gz

Extract zlib:
cp zlib-1.2.3.tar.gz tor-mingw/
cd tor-mingw/
tar zxf zlib-1.2.3.tar.gz

Make zlib1.dll:
cd tor-mingw/zlib-1.2.3/
make -f win32/Makefile.gcc

Done.


Stage Four: Download, extract, and patch libevent-1.1b.
------------------------------------------------------

Download libevent-1.1b:
http://www.monkey.org/~provos/libevent/

Start up MSYS:
Start -> Programs -> MinGW -> MSYS -> msys

Create a directory to work within, for example, /c/tor-mingw.

Copy libevent and tor tarballs into this working dir:
cp /path/to/libevent-1.1b.tar.gz /c/tor-mingw/
cp /patch/to/tor-alpha.tar.gz /c/tor-mingw/
cd /c/tor-mingw/

Extract libevent: tar zxf libevent-1.1b.tar.gz
Extract tor: tar zxf tor-alpha.tar.gz

Copy the libevent-1.1b diff into libevent-1.1b:
patch -p0 < ../tor-alpha/Win32Build/mingw/libevent-1.1b-mingw.diff

Run "aclocal && autoheader && automake && autoconf".
There may be WARNING messages.  There will be no output if all runs successfuly.

Run "./configure"
Run "make"
Run "make install"

Stage Five:  Build Tor
----------------------

Extract the latest tor from svn in tor-mingw dir:
tar zxf latest-tor-alpha.tar.gz

cd tor-alpha
./autogen.sh
./configure 
make

You now have a tor.exe in src/or/.  This is Tor.
