Lighttpd with static modules
For the Nexus OS I need a version of lighttpd that is statically linked. Even when you build lighty as a static library, it by defaults expects to load its modules (access, dirlisting, staticfile, cgi, ...) at runtime. The following trick makes lightly include modules in the statically linked binary. It has been tested against version 1.4.25.
CFLAGS
Compile with the debug flag -DLIGHTTPD_STATIC set. I noticed that my gcc (4.4.1) also
complained about syntax, so I had to force gcc to interpret as the C99 standard:
make CFLAGS=-DLIGHTTPD_STATIC -std=c99
src/Makefile.in changes
In src/Makefile.in (from which configure generates src/Makefile), add the modules you want to include (say, mod_access and mod_staticfile) to all lists of input to target lighttpd. 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)
As you see, I add the targets in total 5 times to the Makefile. That's probably
4 times unnecessarily, but it works. Add a comment if you have created
a shorter patch.
src/plugin.c changes
This file contains a line #include "plugin-static.h", but no such header is
generated. AFAIK this is a stale entry and no longer used. However, you can make lighty
aware of the statically linked modules by commenting out this line and adding these
immediately below it:
PLUGIN_INIT(mod_access) PLUGIN_INIT(mod_staticfile)
Feedback
As always, leave a comment if you know an easier solution. If you want to see the
full patch, download the Nexus sources from the link at the top of this post. Note
that it includes additional modifications to handle the fact that Nexus is only
partially Posix complete.
Thank you it's very helpful.
ReplyDeleteAnd I found ordering of plugins is important.
http://redmine.lighttpd.net/issues/1893