Monday, December 26, 2011

Compiling MLDonkey for Windows

MLDonkey is a nifty program that helps you share files with other people. MLDonkey works on Linux, but the Windows version I downloaded didn't work on my computer running Windows XP. So I compiled MLDonkey using Cygwin's mingw64-i686-gcc-* compiler toolchain. Here I show how I did it. Part of the information below is taken from the MLDonkey Windows guide.
  1. Install MinGW-w64.
  2. Compile pthread.
  3. Compile zlib and bzip2
    Download the zlib source (zlib-1.2.7.tar.gz) and unpack it.
    tar xzvf zlib-1.2.7.tar.gz
    cd zlib-1.2.7
    Compile and install zlib.
    make -f win32/Makefile.gcc
    cp -iv zlib1.dll /mingw/bin
    cp -iv zconf.h zlib.h /mingw/include
    cp -iv libz.a /mingw/lib
    cp -iv libz.dll.a /mingw/lib
    Now download bzip2 source from bzip2.org and unpack it.
    tar xzvf bzip2-1.0.6.tar.gz
    cd bzip2-1.0.6
    Change line 78 of bzlib.h to read:
    #if defined(_WIN32) && !defined(__MINGW32__)
    Compile and install bzip2.
    make
    cp bzlib.h /mingw/include/
    cp libbz2.a /mingw/lib
  4. libiconv
    Download and compile libiconv:
    tar xzvf libiconv-1.14.tar.gz
    cd libiconv-1.14
    ./configure --build=i686-w64-mingw32 --prefix=/mingw --enable-static --disable-nls
    make
    make install
  5. Optionally, compile the GD library.

  6. wget
    Build wget as shown in this post. If you don't want to compile wget yourself, get the executable (wget.exe) somewhere, and put it in the same folder as mlnet.exe later.
  7. regex and libmagic

    Compile regex as shown in this post. Then, compile libmagic as shown in this post.

  8. OCaml
    You need flexdll (flexdll-0.27.zip) to build OCaml. Extract it to /mingw/bin. Then, download the latest OCaml source (3.12.1). Patch ocaml with this Unicode patch.
    tar xzvf ocaml-3.12.1.tar.gz
    cd ocaml-3.12.1
    patch -p1 -l < ../ocaml-3.12.1-unicode.patch

    In the config subfolder, copy Makefile.mingw to Makefile.

    cp config/m-nt.h config/m.h 
    cp config/s-nt.h config/s.h 
    cp config/Makefile.mingw config/Makefile 
    Begin compiling OCaml.
    make -f Makefile.nt world
    make -f Makefile.nt opt
    make -f Makefile.nt opt.opt
    make -f Makefile.nt install
    Set up OCaml environment variables:
    export CAMLLIB=C:/mingw/lib
    export OCAMLLIB=C:/mingw/lib
    export CAMLP4LIB=C:/mingw/lib/camlp4
  9. Build MLDonkey
    Get the MLDonkey source, then unpack and configure it.
    tar xjvf mldonkey-3.1.0.tar.bz2
    cd mldonkey-3.1.0
    ./configure --build=i686-w64-mingw32 --prefix=/mingw --disable-fasttrack CPPFLAGS='-DPTW32_STATIC_LIB -D_REGEX_RE_COMP' LIBS='-lregex -lshlwapi -lz'
    mldonkey configure MinGW output

    Start compilation.

    export OCAML_SRC=~/ocaml-3.12.1
    cp -iv /mingw/lib/stublibs/dllunix.dll .
    make depend

    Open Makefile. On the mlnet.static line, replace -static with "-link -Wl,--subsystem,windows".

    make mlnet.static GD_LIBS='-lpng -ljpeg'
    strip mlnet.static 
    mv mlnet.static mlnet.exe
    If the final linking stage fails, here is the command I used to produce mlnet.exe:
    g++ -g0 -O3 -o mlnet.exe -Wl,--subsystem,windows -L/lib/gcc/i686-w64-mingw32/4.5.3 -L/mingw/lib /tmp/camlstartup00193d.s build/flexdll_mingw.o /mingw/lib/std_exit.o src/daemon/common/commonMain.o build/driver.a build/core.a build/client.a build/common.a build/magic.a build/bitstring.a build/cdk.a build/extlib.a /mingw/lib/nums.a /mingw/lib/str.a /mingw/lib/unix.a /mingw/lib/bigarray.a /mingw/lib/stdlib.a src/utils/cdk/gdstubs.o src/networks/direct_connect/che3_c.o src/utils/lib/CryptoPP.o src/utils/lib/CryptoPP_stubs.o src/utils/net/upnp_stubs.o src/daemon/common/commonHasher_c.o src/utils/lib/magiclib_stub.o src/utils/bitstring/bitstring_c.o src/utils/cdk/zlibstubs.o src/utils/cdk/heap_c.o src/config/mingw/os_stubs_c.o src/utils/lib/fst_hash.o src/utils/lib/md4_comp.o src/utils/lib/md4_c.o src/utils/lib/charsetstubs.o src/utils/lib/md5_c.o src/utils/lib/sha1_c.o src/utils/lib/tiger.o src/utils/lib/stubs_c.o -lnums -lcamlstr -lunix -lbigarray -lgdi32 -luser32 -ladvapi32 -limm32 -lshell32 -lole32 resfile.o -lpthread -lmagic -lgd -ljpeg -lfreetype -lpng -lz -lbz2 -lws2_32 -lshlwapi /mingw/lib/libasmrun.a /mingw/lib/libcharset.dll.a /mingw/lib/libiconv.dll.a
    Optonally, compress the executable with upx.
    upx --best --strip-relocs=0 mlnet.exe
  10. Here's my mldonkey builds.

About This Blog

KBlog logo This blog seeks to provide useful information to people, based on the author's knowledge and experience. Thanks for visiting the blog and posting your comments.

© Contents by KBlog

© Blogger template by Emporium Digital 2008

Follow by Email

Total Pageviews