Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

4.8.1 Configuration Header Templates

Your distribution should contain a template file that looks as you want the final header file to look, including comments, with #undef statements which are used as hooks. For example, suppose your configure.ac makes these calls:

     AC_CONFIG_HEADERS([conf.h])
     AC_CHECK_HEADERS([unistd.h])

Then you could have code like the following in conf.h.in. On systems that have unistd.h, configure defines ‘HAVE_UNISTD_H’ to 1. On other systems, the whole line is commented out (in case the system predefines that symbol).

     /* Define as 1 if you have unistd.h.  */
     #undef HAVE_UNISTD_H

Pay attention that ‘#undef’ is in the first column, and there is nothing after ‘HAVE_UNISTD_H’, not even white space. You can then decode the configuration header using the preprocessor directives:

     #include <conf.h>
     
     #if HAVE_UNISTD_H
     # include <unistd.h>
     #else
     /* We are in trouble.  */
     #endif

The use of old form templates, with ‘#define’ instead of ‘#undef’ is strongly discouraged. Similarly with old templates with comments on the same line as the ‘#undef’. Anyway, putting comments in preprocessor macros has never been a good idea.

Since it is a tedious task to keep a template header up to date, you may use autoheader to generate it, see autoheader Invocation.


 
 
  Published under the terms of the GNU General Public License Design by Interspire