x
Loading
 Loading
Hello, Guest | Login | Register

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.

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

 /* features.h — features used by logger(1l) from the local system */ /* HAS_SYSLOG — does the system have a syslog implementation? */ #define HAS_SYSLOG 0 /* * HAS_SNPRINTF — does the system have a working snprintf() function? * If not, we’ll use our local version. snprintf()…

Please log in to view this content.

Not Yet a Member?

Register with LinuxMagazine.com and get free access to the entire archive, including:

  • Hands-on Content
  • White Papers
  • Community Features
  • And more.
Already a Member?
Log in!
Username

Password

Remember me

Forgotten your password?
Forgotten your username?
Read More
  1. Helpful Tools for Software Developers
  2. The Github Hall of Fame
  3. Book'em, Github.
  4. This Week on Github: Stupid Ruby Tricks
  5. A Veritable Scatter Shot!
Follow Linux Magazine
Rackspace