Never ever install autoheader's config.h
.
The last thing the users of your library need is interference from the macros leaking out of your config.h
. Your library may have HAVE_FOOBAR
, but my software might be compiled in a way that foobar is disabled, so that HAVE_FOOBAR
will break my compilation.
The AX_PREFIX_CONFIG macro from the archive is a workaround, where everything gets prefixed.
A better approach is to create a template file (e.g. blargconfig.h.in
) with lines like:
typedef @BLARG_TYPE@ blarg_int_t;
@BLARG_RANDOM_INCLUDE@
And then AC_SUBST()
those variables in configure.ac
:
AC_SUBST(BLARG_TYPE, ["unsigned short"])
AC_SUBST(BLARG_RANDOM_INCLUDE, ["#include <somerandomheader.h>"])
Then list it as an output file:
AC_CONFIG_FILES([Makefile
src/Makefile
...
include/blargconfig.h])
The .h
file should be listed with nodist_include_HEADERS
; the .h.in
file will be automatically distributed because it's listed in AC_CONFIG_FILES
.
Destination for such files is commonly $libdir/packagename/include
. See GLib for example, although they generate glibconfig.h
without a template (by writing the whole creation code inline in configure.ac
, as the autobook suggests). I find this approach less maintainable than using AC_SUBST
, but it's more flexible.
Of course, to help the compiler find the platform-dependent header you'll probably also want to write a pkgconfig script, like GLib does.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…