Finding and Defining Features
In September, we discussed the significant advantages of re-implementing desired, but less common functions: if you use a feature of your local operating system, but discover it doesn’t exist on other platforms, write your own implementation, and make that code a part of your distribution.
Sunday, December 15th, 2002
In September, we discussed the significant advantages of re-implementing desired, but less common functions: if you use a feature of your local operating system, but discover it doesn’t exist on other platforms, write your own implementation, and make that code a part of your distribution.
In that column we also discussed the benefit of testing for features in your code: feature test macros make code easier to port, and far easier to read.
This month, we’ll discuss four ways to generate feature definitions on any Unix-like platform. The four techniques are: by hand, derived from OS definitions, using metaconfig, and using autoconf.
Feature Test Macros Made By Hand
One of the most common mechanisms for configuring software is downright old-fashioned: setting features by hand. This technique requires you to edit the project’s or package’s configuration file (usually a .h file), and comb through it line by line, changing #ifdefs as needed. Listing One shows feature.h, an include file that configures logger.
Listing One: A simple include file that declares what system features are available |