I have two progrects using autoconf. Project A uses project B through AC_CONFIG_SUBDIRS()
project A configure.ac:
AC_CONFIG_SUBDIRS([projectb])
project B configure.ac:
AC_DEFINE([NEWDEFINE])
I would like to export the NEWDEFINE from project B to project A.
a.c:
#ifndef NEWDEFINE
#error NEWDEFINE not defined
#endif
$ autoreconf
$ ./configure
$ make
a.c:2:2: error: #error PTHREAD not defined
2 | #error NEWDEFINE not defined
| ^~~~~
I want to view the NEWDEFINE in a.c of project A.
I would like to export the NEWDEFINE from project B to project A.
AC_CONFIG_SUBDIRS
is for configuring a bundled standalone project. The configuration of such a project is its own. If you're looking for an external macro of such a project, as built, then you will find it in one of the project's public headers, which the project A sources that need it should #include
. Possibly a generated header.
If the macro you want is not accessible that way then to a first approximation, it is not available at all. That is, project A's build should not be made dependent on internal build details of project B or any other separate project. Alternatives include:
Do without.
Use your knowledge of project B's configuration script and the options it will be called with to predict the definition it will produce.
Hack your copy of project B to expose the definition to you in an existing or new public header, or, better, to allow project A to control what the definition will be.
If project B uses AC_CONFIG_HEADERS
, so that the macro definition will be written in a config.h
for that project (which is an internal header), then get it from there in any of a number of ways. The absolute worst of those would be to #include
project B's config.h
directly into your regular sources -- do not do this.
If you really need internal build configuration of project B inside project A, then perhaps that's a sign that they shouldn't really be separate projects. You could merge them together under control of a single configuration script, which would of course have all the relevant information.
Any way around, you cannot get data generated by project B's configure
into project A's configure
when the former is run by the latter under control of AC_CONFIG_SUBDIRS
. The structure and timing do not work for that.