Introduction
Dan Bernstein has written a lot of software available on his website, most notably Qmail and djbdns / tinydns.
He frequently uses his own commands (ie a library to put together a string) in all of them, and includes those small files in every package.
Felix von Leitner has taken most of those files and packaged them into a library he calls libdjb. Instead of having to include and recompile all the alloc.c's and scan_seek.c's you can just reference this library.
Problems with current libdjb
Felix's library works fine, except that two files are missing: buffer_1s.c and seek_cur.c. They're needed in Dan's CDB program.
The entries in the header files are there for them, so I think they were just overlooked when making the library.
Table of what's missing:
| File | Library | Header File | Function
| | buffer_1s.c | buffer.a | buffer.h | buffer_1small |
| seek_cur.c | unix.a | seek.h | seek_cur |
How to patch libdjb
All that's needed are the two files buffer_1s.c and seek_cur.c and to change the Makefiles in the buffer/ and unix/ directories to reference them.
You can either grab those files by hand from above or get this libdjb-patches-0.5.2.tar.bz2 tarball.
The step to patch:
1) go into your libdjb source directory or do the following to get it:
wget http://www.fefe.de/djb/djb-0.5.2.tar.bz2
tar -xvjf djb-0.5.2.tar.bz2
cd djb
2) get my patches and untar them:
wget http://ladro.com/libdjb/libdjb-patches-0.5.2.tar.bz2
tar -xvjf libdjb-patches-0.5.2.tar.bz2
(note: this overwrites files)
3) continue on like normal with a make
How to install libdjb for use by other programs
Now that you have an updated libdjb you should install it ease use by other programs. I've created a simple perl script to do that for you available here that you should run in the djb directory.
What it does is copy the created archive (*.a) files into /usr/lib directory and renames them like "libdjbunix.a" and the various header files (ie unix/byte.h) into the /usr/include/djb/ directory.
The reason for the renaming from "buffer.a" to "libdjbbuffer.a" is so that you can put a "-ldjbbuffer" into your compile statement to include the library, the -l checks for "lib" in front and ".a" at the end.
Putting the "djb" in there is to avoid any name conflicts, for example there could be another "liballoc.a" out there.
cd /path/to/djb/
./installlibdjb.pl -h # to see the options, install program included with my tarball
Running installlibdjb.pl will put the header files into /usr/include/djb/ and the archives into /usr/lib renaming them like libdjbbuffer.a
How to patch CDB for use with libdjb
Now that we've patched and installed libdjb we should try and use it. I picked Dan's
CDB (Constant Database) package as I use it often. Like his other software, he includes all his small routines that are duplicated by libdjb.
To fully use libdjb in compiling CDB we're going to:
1) delete all the duplicate files (ie alloc.c) that's in the archives
2) replace the Makefile with one that doesn't build archives that are in libdjb
3) modify some of the .h and .c files to reflect the libdjb
You can do all of this by hand or download this cdb-0.75-patches.tar.bz2 tarball and do the following:
tar -xvzf cdb-0.75.tar.gz
wget http://ladro.com/libdjb/cdb/cdb-0.75-patches.tar.bz2
tar -xvjf cdb-0.75-patches.tar.bz2
cd cdb-0.75
./redocdb.pl
Now you'll have a fully patched CDB sources to do a make on.
To test it out, follow the instructions at the CDB install page and do the following:
./cdbmake-sv test.cdb test.tmp < /etc/services
./cdbget smtp/tcp < test.cdb && echo ''
You should see a 25.
Next steps
You should copy the cdb.a file to /usr/lib/libdjbcdb.a . I would put a link in there to go to libcdb.a as "cdb" is probably unique. Likewise copy the header files cdb.h and cdb_make.h to /usr/include/djb
As an aside, the files from the CDB tarball go down from 163kb to 111kb. Woo hoo! 50kb!