autoconf
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how to prefix definitions in config.h


From: Russ Allbery
Subject: Re: how to prefix definitions in config.h
Date: Tue, 19 Feb 2002 10:59:07 -0800
User-agent: Gnus/5.090005 (Oort Gnus v0.05) XEmacs/21.4 (Common Lisp, sparc-sun-solaris2.6)

Guido Draheim <address@hidden> writes:

> I'm doing the same thing, and in fact, all libraries should put their
> headers with a subdir prefix, sadly not all of them do it, and
> automake's support for such a style is limited. Anyway, two ways.

> a) I'm using package/_config.h - this even hint the reader that this
>    file is not a normal header (it is generated!) and it does not
>    get confused for the standard config.h file.
> b) look at the argument of AC_CONFIG_HEADER - you can specify a
>    different output-file, so that you don't need to have the two
>    same-named.

The name isn't the problem.

Suppose that you have two installable libraries that use autoconf, and in
both of those libraries you need to probe for a few system features, like
the proper types, and change the headers and prototypes based on that.
Now suppose you want to write a program that uses both of those libraries.
If you include both header files, then the separate package config.h files
will potentially conflict with each other and result in a bunch of
redefinition errors.

One thing that you can do is recognize that generally your interface only
depends on a much restricted subset of the things that you probe for
actual compilation, and therefore you only need to install a stripped down
version of config.h.  For INN, I use the following awk script to generate
that stripped-down version with only the symbols that the header files
need to use, and just add new symbols to it as I need them for the API:

#! /bin/sh

##  $Id: mksystem,v 1.1 2001/02/24 07:59:06 rra Exp $
##
##  Create include/inn/system.h from include/config.h.
##
##  include/config.h is generated by autoconf and contains all of the test
##  results for a platform.  Most of these are only used when building INN,
##  but some of them are needed for various definitions in the header files
##  for INN's libraries.  We want to be able to install those header files
##  and their prerequisites, but we don't want to define the normal symbols
##  defined by autoconf since they're too likely to conflict with other
##  packages.
##
##  This script takes the path to include/config.h as its only argument and
##  generates a file suitable for being included as <inn/system.h>.  It
##  contains only the autoconf results needed for INN's API, and the symbols
##  that might conflict with autoconf results in other packages have INN_
##  prepended.

cat <<EOF
/* Automatically generated by mksystem from config.h; do not edit. */

/* This header contains information obtained by INN at configure time that
   is needed by INN headers.  Autoconf results that may conflict with the
   autoconf results of another package have INN_ prepended to the
   preprocessor symbols. */

#ifndef INN_SYSTEM_H
#define INN_SYSTEM_H 1

EOF

awk -f - $1 <<'---END-OF-AWK-SCRIPT---'

/^#define HAVE_INTTYPES_H/      { print save $1 " INN_" $2 " " $3 "\n" }
/^#define HAVE_STDBOOL_H/       { print save $1 " INN_" $2 " " $3 "\n" }
/^#define HAVE_SYS_BITTYPES_H/  { print save $1 " INN_" $2 " " $3 "\n" }

{ save = $0 "\n" }

---END-OF-AWK-SCRIPT---

cat <<EOF
#endif /* INN_SYSTEM_H */
EOF

-- 
Russ Allbery (address@hidden)             <http://www.eyrie.org/~eagle/>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]