config.h.in not being used as a template

人盡茶涼 提交于 2019-12-13 04:05:53

问题


I'm trying to supply a config.h.in to Autotools. The topic is covered in the Autoconf manual at 4.8.1 Configuration Header Templates. config.h.in looks like so:

/// \file config.h
/// \brief Library configuration file

#ifndef CRYPTOPP_CONFIG_H
#define CRYPTOPP_CONFIG_H

// define this if running on a big-endian CPU
#undef CRYPTOPP_BIG_ENDIAN

// define this if running on a little-endian CPU
#undef CRYPTOPP_LITTLE_ENDIAN

#endif  // CRYPTOPP_CONFIG_H

Our configure.ac includes the following for testing:

AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_FILES([Makefile] [libcryptopp.pc])
AC_CONFIG_SRCDIR([configure.ac])

AC_PROG_LIBTOOL
LT_INIT

AC_PROG_CXX
AC_LANG([C++])
AC_PROG_GREP

After autoreconf and configure runs, there is a config.h. The problem is, it does not follow the template config.h.in. It looks like a new config.h produced by the tools.

When I examine config.log I only see one mention of config.h. I can't find additional information about what is going on:

config.status:1172: creating Makefile
config.status:1172: creating libcryptopp.pc
config.status:1172: creating config.h
config.status:1401: executing depfiles commands
config.status:1401: executing libtool commands

What is the problem and how do I fix it?


回答1:


After autoreconf and configure runs, there is a config.h. The problem is, it does not follow the template config.h.in. It looks like a new config.h produced by the tools.

Take a look at your config.h.in at that point. I think you'll be surprised.

The issue is that among the programs that autoreconf runs for you is autoheader, which builds a config.h.in based on what it finds in configure.ac (or configure.in). Your subsequent configure then uses the new template, but nothing in particular about that is recorded in the configuration logs because the template already exists at that point.

That behavior is usually a welcome convenience, but if you want to supply your own, custom config.h template then you must avoid it being replaced when autoreconf is run (or when autoheader is run directly). One way to do that is to avoid running those programs at all. You may run other autotools programs, and if you decide to avoid autoreconf then it might be worth your while to script that.

On the other hand, Autoconf comes with a few built-in macros to modulate autoheader's behavior. In particular, AH_TOP and AH_BOTTOM may be useful to you for adding custom content to the automatically generated content.

On the third hand, if you want to provide your own template, written strictly by hand, and to avoid autoheader mucking with it, then it is useful to know that autoheader works with only the first header template named in your configure.ac, and you can name more than one. Thus, you might add a dummy configuration header that your sources do not reference, so that autoheader can play with that without messing anything up:

AC_CONFIG_HEADERS([config_dummy.h config.h])

The Autotools will create that dummy config header and a template for it, but if your sources never reference it then that has no effect on the build.



来源:https://stackoverflow.com/questions/48436715/config-h-in-not-being-used-as-a-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!