Reputation: 102346
Autoconf allows multiple config files in AC_CONFIG_HEADERS
. From the Autoconf manual:
— Macro: AC_CONFIG_HEADERS (header ..., [cmds], [init-cmds])
This macro is one of the instantiating macros; see Configuration Actions. Make AC_OUTPUT create the file(s) in the blank-or-newline-separated list header containing C preprocessor #define statements, and replace ‘@DEFS@’ in generated files with -DHAVE_CONFIG_H instead of the value of DEFS. The usual name for header is config.h.
...
We use two config headers. The first one is called config_asm.h
, and includes defines for ISA availability, like SSE2, SSSE3, SSE4.1, AES, CLMUL, SHA, etc. The second one is called config_cxx.h
, and includes defines for C++ features, like atomics, alignof, alignas, synchronization, etc. Users include a top level config.h
which includes the subordinate config files, like config_asm.h
and config_cxx.h
.
I need to switch between the config files depending on the test being run. The manual does not discuss how to use multiple config files, and it does not provide an example of using multiple config files.
How do I switch between the config files when using Autoconf?
Here is what I have so far. I believe I need to change to something like AC_CONFIG_HEADERS([config_asm.h config_cxx.h])
. But it is not clear to me how to tell Autoconf to write results to a particular config file.
AC_INIT([Crypto++], [8.3], [http://cryptopp.com/bugs], [cryptopp], [http://cryptopp.com/])
AM_INIT_AUTOMAKE
AC_PROG_CXX
AC_LANG([C++])
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_HEADERS([config_asm.h])
AC_CONFIG_FILES([Makefile] [libray.pc])
AC_CONFIG_SRCDIR([configure.ac])
When I tell Autoconf there is a second config file it results in an error. I suspect I am missing something simple, but I'm not sure what it is since the manual does not discuss it.
AC_CONFIG_HEADERS([config_asm.h config_cxx.h])
results in:
autoreconf -f -i
...
configure.ac:105: installing './compile'
configure.ac:95: installing './missing'
configure.ac:101: error: required file 'config_cxx.h.in' not found
Makefile.am: installing './depcomp'
Upvotes: 4
Views: 930
Reputation: 181008
It takes a little reading between the lines to understand everything the Autoconf docs are telling you, and it takes a broad understanding of Autoconf to recognize where else the docs have something relevant to say. In particular,
Make
AC_OUTPUT
create the file(s) in the blank-or-newline-separated listheader
depends on you to understand that what AC_OUTPUT
does to generate headers is very much like what it does to generate files specified via AC_CONFIG_FILES
: it generates them from templates. In the case of headers, it expects a different form of template, and fills it based on a different set of symbol definitions (those from AC_DEFINE
, as opposed to those from AC_SUBST
), but it's still just template processing. There's an additional clue about this a bit later in the AC_CONFIG_HEADERS
description, where it says
Usually the input file is named
header.in
; however, you can override the input file name [...]
Importantly, neither the generated configure
nor its generated config.status
writes or modifies the templates. The basic answer, then, is that you control which header or headers each symbol is defined in by controlling the templates.
And that's the trick, of course. In a typical, one-config-header project, it is normal to (re)generate the config header template at need by running autoheader
, typically under the control of autoreconf
. And you can still do that, but autoheader
always emits all its output to the first header defined in an AC_CONFIG_HEADERS
call. (It doesn't even create empty templates for any other headers, which is why you got the error about config_cxx.h.in
not being found.)
If you cannot use just one header then you have to maintain all header templates but one (semi-)manually. Since autoreconf
will cause the first to be updated, I'm going to suggest that if it's essential to have two headers that neither one contains all the definitions, then choose "none of the above" as the first header. Instead define another header that goes unused in practice, but is listed first. Build your templates for the two real config headers from pieces of the automatically managed one.
Ideally, you would automate the process of splitting up the main template into the two you actually want. If you can script that, then you can cause the script to run automatically when configure
does, in time to have the appropriate effect, by launching the script via AC_CONFIG_COMMANDS_PRE
. That might look something like this:
AC_CONFIG_COMMANDS_PRE([pushd "$srcdir" && { ./generate_header_templates; popd; }])
You will still need at least empty versions of each wanted template file to be present when you run autoreconf
, though.
On the plus side, this also means that you don't have to choose just one header for each symbol. If there are any that you would like to have in both headers then you just have to write both templates appropriately.
Upvotes: 5