C – Build nested Autotools packages without installing

Build nested Autotools packages without installing… here is a solution to the problem.

Build nested Autotools packages without installing

What I want is to build my autotools package and a nested autotools package. It is a static library, and usually this package installs lib in your $prefix/lib folder if you type make & make install

Subpackage file:

configure.ac

AC_INIT([testlib],[1.0],[[email protected]])
AM_INIT_AUTOMAKE([foreign -Wall -Werror])
AC_PROG_CC()
AC_PROG_RANLIB()
AC_CHECK_HEADERS()
AC_LANG([C])
AC_CONFIG_FILES([Makefile src/Makefile])
AC_OUTPUT

Makefile.am

SUBDIRS = src

src/Makefile.am

lib_LIBRARIES = libtestlib.a
libtestlib_a_SOURCES = testlib.c
include_HEADERS = testlib.h

But I want to use it as a nested package in my autotools package and just need it to be linked at build time.

So how do I implement that my package is built and installed, but the subpackage/nested package only builds without modifying the configure.ac or Makefile.am in the child package?

Solution

So how do I achieve that my package is build & installed but the sub-
/ nested package is only build without modifying the configure.ac or
the Makefile.am from the sub-package?

Your best bet may be to use AC_CONFIG_SUBDIRS in the top-level configure.ac to link the configuration of child packages to the top-level package, but avoid using SUBDIRS in the top-level Makefile.am to trigger make recursively into child packages. Instead of the latter, add manual rules to the top-level Makefile.am to build the required libraries by recursively make.

In the top-level package, it looks like this :

configure.ac

# ...
AC_CONFIG_SUBDIRS([testlib-1.0])
# ...

Makefile.am

# ... testlib-1.0 *not* present in SUBDIRS ...

testlib-1.0/src/libtestlib.a:
    $(MAKE) -C testlib-1.0

Then, be sure to express appropriate dependencies on teSTLib-1.0/src/libteSTLib.a when needed, and use appropriate linking options at the top level.

Related Problems and Solutions