'how to compile lighttpd modules statically

I have currently complied lighttpd from source

./configure --prefix=/home/lighttpd \
--without-pcre \
--without-zlib \
--without-bzip2

I also tried -enable-static --disable-shared option, but modules still loading from lib directory

I want to compile all lighttpd module in single binary instead of loading from lib directory, how to do that ?



Solution 1:[1]

Compile it with flag -DLIGHTTPD_STATIC. If gcc will warn you about syntax, force interpret gcc as the C99 standard:

make CFLAGS=-DLIGHTTPD_STATIC -std=c99

Also you must change src/Makefile.in which is generated by configure to add the modules you want to include. Specifically, add to am__liblightcomp_la_SOURCE_DIST, am__lighttpd_SOURCES_DIST and common_src:

mod_access.c mod_staticfile.c

And also add the objects. To am__objects_1 and am__objects_2

mod_access.$(OBJEXT) mod_staticfile.$(OBJEXT)

if src/plugin-static.h file is not available, change src/plugin.c file, find line #include "plugin-static.h", coment it and add this below:

PLUGIN_INIT(mod_access)
PLUGIN_INIT(mod_staticfile)

Solution 2:[2]

The documentation of lighttpd explains that using build_static will only cause it to be statically linked with its own modules (mod_*.so files). It will still dynamically link external dependencies (those in /lib*/*).

If you were not mixing these up, regarding your experience of:

I also tried -enable-static --disable-shared option, but modules still loading from lib directory

And all you wanted was for these modules to be statically included in the lighttpd binary, then the other answers should be correct and valid.

However, if you want to have a single binary, so that there are no externally dynamic dependencies. Then you need to use both scons and replace build_static=1 with build_fullstatic=1. The Makefile setup doesn't have this option.


build_static=1

scons -j 4 build_static=1 build_dynamic=0

Using ldd to show which dynamic libraries it needs:

ldd sconsbuild/static/build/lighttpd
    linux-vdso.so.1 (0x00007fff0478f000)
    libpcre2-8.so.0 => /lib/x86_64-linux-gnu/libpcre2-8.so.0 (0x00007f760191e000)
    libcrypt.so.1 => /lib/x86_64-linux-gnu/libcrypt.so.1 (0x00007f76018e4000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f76016bc000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f7601a5a000)

PS: if you built a shared version, the mod_*.so files would still not show up here, as those are lazily loaded from within the execution of lighttpd, based on your config file.


build_fullstatic=1

scons -j 4 build_fullstatic=1 build_dynamic=0
ldd sconsbuild/fullstatic/build/lighttpd
    not a dynamic executable

Which is what I assume you wanted to see.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sun Dro
Solution 2