HowTo: Using -lite with a GIT-based application

Years ago while looking for a fast init replacement for work, I found Finit. Originally written by Claudio Matsuoka to act as a drop-in replacement for the Asus EeePC fastinit, “gaps filled with frog DNA …“

Until I found Finit I had always been in awe of those venturing into the realm of PID 1. However, learning from the simplicity of Claudio’s code I realized that although PID 1 at times is indistinguishable from magic, it is really not that hard to master. My version of Finit is available on GitHub.

The code is open sourced under the very liberal MIT/X11 license, and much of its frog DNA has proven very useful to me over the years. This blog post is about how that frog DNA can help you fill gaps in your projects …

Recently I broke out the most generic pieces from Finit into a separate library, which I call libite (because it looks awesome linking to it: -lite :) I complemented it with a few pieces of my own and some from the OpenBSD project, most notably their famous string API: strlcpy(3) and strlcat(3). Also included is the very useful *BSD linked list API sys/queue.h, which is a much more up to date version than GLIBC carries. For example, the new _SAFE macros are missing, which you want to use while traversing lists to delete/free nodes.

To make use of -lite and its APIs you can either build it as a separate library and install lite.h and libite.so.1 to your system, or add libite as a GIT submodule to your project and use only the parts you need from the archive:

git submodule add https://github.com/troglobit/libite.git

You then need to add #include "libite/lite.h" to the source and adapt your Makefile slightly to call the libite/Makefile before linking your application to the libite.a archive:

all: $(EXEC) libite/libite.a

libite/libite.a: Makefile
        @$(MAKE) -C libite

$(EXEC): $(OBJS) libite/libite.a
        @gcc -o $@ $^

For an example of how this can look, see the uftpd project, which uses both -lite and -luev. The latter is my small event library, libuEv. For help using -lite with the GNU configure and build system, see inadyn.

Libite builds in “silent mode” by default, use make V=1 (like the kernel) to get a more verbose output, usable for autobuilders etc.