Tuesday, December 27, 2011

To build wget.exe with MinGW

wget is a useful command-line tool for downloading files from the Internet. wget can fetch files through FTP and HTTP, but can't handle P2P protocols, such as bittorrent and ed2k. However, one of the strengths of wget is its ability to traverse a Web site. I used to mirror Web sites using wget so that I could read the downloaded HTML documents off-line. That's the main reason I am building wget on Windows.

This post illustrates how to build wget statically using MinGW GCC compiler. To build wget for the Windows platform, first install MinGW or set up MinGW-w64. There are many libraries to prepare: zlib, pcre/regex, openssl.

  1. Zlib is a compression library. To compile zlib, grab the zlib source, unpack it and type the following commands:

    make -f win32/Makefile.gcc
    cp -iv zconf.h zlib.h /mingw/include
    cp -iv libz.a /mingw/lib
  2. This step involves compiling regex and is optional. However, I got errors building wget with its included regex. You can compile regex as shown in this post or compile PCRE. I recommend building PCRE.

  3. Compile OpenSSL as follows. OpenSSL allows wget to download using the https:// protocol. Alternately, you could compile gnutls instead, but I'm not covering gnutls in this post simply because it takes more steps. If you are using 64-bit MinGW-w64, then use the word "mingw64" instead of "mingw" at the end of configure line.

    ./Configure -DHAVE_STRUCT_TIMESPEC -L/mingw/lib -lz -lws2_32 --prefix=/mingw zlib mingw
    make
    make test
    make install
  4. Now build wget. The source is available here. If you are using MinGW-w64, append --build=i686-w64-mingw32 or --build=x86_64-w64-mingw32 to the configure line depending on whether you use 32-bit or 64-bit MinGW-w64 build.

    ./configure --prefix=/mingw --enable-threads=win32 --disable-nls --with-ssl=openssl --without-included-regex LIBS='-lpcreposix -lpcre'

    If you are linking GNU regex 0.12 instead of PCRE, append LIBS='-lregex' to the configure line instead. If you are going to link wget with static PCRE, remove /mingw/lib/libpcre.dll.a and use CPPFLAGS='-DPCRE_STATIC'.

    make CPPFLAGS='-DWINDOWS -DPCRE_STATIC -DIN6_ARE_ADDR_EQUAL=IN6_ADDR_EQUAL'
    make install

    With MinGW-w64, IN6_ARE_ADDR_EQUAL is not defined, so I have to define an alias for it with an equivalent macro.

  5. Optionally, make the executable file smaller. UPX is an executable compressor and can be downloaded from here.

    strip /mingw/bin/wget.exe
    upx --best --strip-relocs=0 /mingw/bin/wget.exe

Testing wget

You'll find wget.exe at /mingw/bin. To test wget, just run it with the URL of the file you wish to download. For example, to use wget to download the MEPIS Linux:

wget http://distro.ibiblio.org/mepis/released/SimplyMEPIS-1.5G_11.9.70_64.iso

You can get my wget build at the Downloads page.

Also Read:

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