Building Static Wget

I recently came across a need for wget, but I did not want to have to keep a bunch of dependencies installed. Wget is not hard to build, but there are a couple of dependencies needed during the build. It’s possible to build them all statically, so the resulting wget executable has no runtime dependencies on having those other libraries installed. You’ll need the source for:

  • libgmp (tested with 6.3.0)
  • libnettle (tested with 3.9.1)
  • libtasn1 (tested with 4.19.0)
  • gnutls (tested with 3.7.10)
  • wget (tested with 1.24.5)

You will also need as prerequisites:

  • A working toolchain
  • GNU Make
  • A pkg-config implementation (I use pkgconf because it was way easier to install)
mkdir dep-prefix
deppfx=$PWD/dep-prefix

# libgmp
mkdir libgmp-6.3.0-build
cd libgmp-6.3.0-build
../gmp-6.3.0/configure --prefix=$deppfx --enable-static --disable-shared
make -j10
make -j10 install
cd ..

# libnettle
mkdir libnettle-3.9.1-build
cd libnettle-3.9.1-build
PKG_CONFIG_PATH=$deppfx/lib/pkgconfig CFLAGS="$(pkg-config --cflags gmp)" LDFLAGS="$(pkg-config --libs-only-L gmp)" ../nettle-3.9.1/configure --prefix=$deppfx --enable-static --disable-shared
make -j10
make -j10 install
cd ..

# libtasn1
mkdir libtasn1-4.19.0-build
cd libtasn1-4.19.0-build
PKG_CONFIG_PATH=$deppfx/lib/pkgconfig ../libtasn1-4.19.0/configure --prefix=$deppfx --enable-static --disable-shared
make -j10
make -j10 install
cd ..

# gnutls
mkdir gnutls-3.7.10-build
cd gnutls-3.7.10-build
PKG_CONFIG_PATH=$deppfx/lib/pkgconfig CFLAGS="$(pkg-config --cflags gmp)" LDFLAGS="$(pkg-config --libs-only-L gmp)" ../gnutls-3.7.10/configure --prefix=$deppfx --enable-static --disable-shared --with-included-unistring --without-p11-kit
make -j10
make -j10 install
cd ..

# wget
mkdir wget-1.24.5-build
cd wget-1.24.5-build
PKG_CONFIG_PATH=$deppfx/lib/pkgconfig PKG_CONFIG='pkg-config --static' ../wget-1.24.5/configure --prefix=$HOME/.local/wget-1.24.5
make -j10
make -j10 install
cd ..

Notes:

  • libnettle doesn’t seem to use pkg-config to look for libgmp, you have to help it along yourself.
  • You can’t use the libtasn1 included in gnutls – it is missing a fix required for static linking to work (missing fix).
  • gnutls needs patch for OSStatus (commit link).
  • wget doesn’t pass --static to pkg-config, so gnutls_protocol_set_direct is not detected leading to undefined references to gnutls_protocol_set_priority later (mailing list link).

Comments are closed.