3
votes

I have a sub-package setup in my autotools repository, in which several related projects are glued together using a master configure.ac and Makefile.am.

Aside from the compilation ordering, easily done via AC_CONFIG_SUBDIRS() macro, there is the need to export headers and library locations required between these excessively coupled sub-projects.

--- configure.ac
 |- Makefile.am
 |- subproj1 --- configure.ac
 |            |- Makefile.am
 |            |- src
 |            \- include
 [...]
 |
 \- subprojN --- configure.ac // requires -I${top_srcdir}/subprojX/include and
              |- Makefile.am  // -L${top_srcdir}/subprojX/src
              |- src
              \- include

Regrouping these packages as one is not an option, unfortunately. I tried exporting variables using AC_SUBST() and/or make's export command, for no avail.

The only way I could get these flags available into every sub-project Makefile was passing CPPFLAGS and LDFLAGS into the root configure invocation (via command-line). However, I'd hope if there is a way to keep these values inside autotools stuff, instead of having to create a separate script for them.

PS: similar to automake and project dependencies

2
Related question on outer forum.milton

2 Answers

2
votes

The autotools are not really designed to be a package management system, so this is an awkward usage, but it is possible to reference relative paths outside of the build tree in the sub-projects. In other words, in subprojN/Makefile.am, you can add:

AM_CPPFLAGS = -I$(srcdir)/../subprojX/include
AM_LDFLAGS = -L$(srcdir)/../subprojX/lib

In this scenario, if subprojN/configure is trying to find libsubprojX, it will fail unless you instead add ../subprojX/{include,lib} to CPPFLAGS and LDFLAGS for configure, which can be done in configure.ac:

CPPFLAGS="$CPPFLAGS -I${srcdir}/../subprojX/include
LDFLAGS="$LDFLAGS -L${srcdir}/../subprojX/lib"

If the configure scripts of the subprojects are not checking for the libraries in the coupled subprojects, it would probably be cleaner to specify LDADD in Makefile.am to get the necessary libraries linked.

-1
votes

CPPFLAGS and LDFLAGS should almost never be passed directly on the command line (personal opinion) but should be set in a config.site. Simply make the assignments in ${prefix}/share/config.site or in $CONFIG_SITE (ie, in the file $HOME/config.site and set CONFIG_SITE=$HOME/config.site in the environment in which you run configure) and that script will be sourced by all of your configure invocations. I'm not sure exactly what you mean by "keep these values inside autotool stuff", but it strikes me that using a config.site satisfies that. LDFLAGS and CPPFLAGS are the correct mechanism to tell your configure script the non-standard location of libraries, so any solution that does not use those would be outside the normal scope of the autotools. (Of course, the best solution is to install the libraries in a standard location so your toolchain can find them with no extra effort on your part. Perhaps you are using gcc and can set LIBRARY_PATH and CPATH.)