Tips to obtain a very small static elinks binary suitable for mini distributions
Remove config.cache (previous CC may be cached):
$ rm config.cache
Use dietlibc (http://www.fefe.de/dietlibc/) or similar stuff (uClibc, …):
$ export CC='diet -Os gcc'
Use compilers flags to optimize for size:
$ export CFLAGS='-s -fno-inline -nostdinc -fomit-frame-pointer'
Note that if you don't use dietlibc, you definitively want to add -Os
or
-O2
to CFLAGS
; GCC 2.95 does not know -Os
, and some say -O2
gives
smaller executables even for GCC 3.x.
If you use these CFLAGS
on Cygwin and you get unresolved symbols (htons
and
suite in particular), try removing -fno-inline
parameter.
Disable some compile-time options:
$ ./configure --disable-ipv6 --disable-backtrace --disable-nls \ --enable-fastmem --without-zlib --without-bzlib --disable-xbel \ --without-lua --without-gnutls --without-openssl --without-x \ --enable-small --without-spidermonkey --without-gpm
You can disable bookmarks, globhist and more, too, if you want to.
malloc()
debugging and use alloca()
wherever possible.
Dependencies over external libs must be removed using the related configure options:
Option | Description |
---|---|
--without-zlib | removes libz dependency (compression) |
--without-bzlib | removes libbz2 dependency (compression) |
--disable-xbel | removes expat dependency (XBEL bookmarks support) |
--without-lua | removes liblua dependency (Lua scripting) |
--without-gnutls | removes libtls dependency (SSL support) |
--without-openssl | removes libssl dependency (SSL support) |
--without-x | removes libx11 dependency (restoring terminal title) |
--without-spidermonkey | removes libjs dependency (JavaScript) |
--without-gpm | removes libgpm dependency (mouse/console) |
It seems GCC 2.95.x do not generate as small binaries as GCC 3.2.x with same flags.
You can use an executable compressor like UPX http://upx.sourceforge.net/.
Here are some results using gcc 2.95.3, dietlibc-0.23, and previous flags:
me$ ls -l src/elinks -rwxr-xr-x 1 zas users 495100 Oct 20 15:53 src/elinks me$ upx --best src/elinks me$ ls -l src/elinks -rwxr-xr-x 1 zas users 217946 Oct 20 15:53 src/elinks
Whow ! Around 200kb :)
--enable-small
configure option effects: