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.
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
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.
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
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.
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.


