C.3. Building Modules from Several Source Files

The Apache build system is easiest to use when each C API module fits into a single source file. However, if the design of your module requires it to be spread out among a series of source files, Apache can accommodate this, albeit with a little more preparation on your part.

If you are building within the Apache source tree, the easiest way to structure the module is to place all the source files in their own subdirectory of src/modules/. The build scheme will be to create a library file named "libyour_module.a" first, and then to link this with httpd.

In addition to the source code files, the subdirectory will contain a file named Makefile.tmpl containing instructions for building the module, and, optionally, a file named "libyour_module.module" containing configuration hints for the module. You will also create a dummy file named Makefile.libdir which has no other purpose than to tell the configuration system that you have provided your own build targets in Makefile.tmpl and to suppress the automatic target generation that the configuration process usually performs.

As a concrete illustration, we will take the mod_compress example from the previous section and split it up into two source code files. compress.c will contain the module definition and the handler code, while compress_util.c will contain various utilities for compressing and decompressing files. The module will be compiled into a library archive named libcompress.a ...

Get Writing Apache Modules with Perl and C now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.