Reputation: 2150
What I want is to build my autotools package together with a nested autotools package. It's a static library and usually this package install the lib in your $prefix/lib
folder, if you type make && make install
Sub-Package-Files:
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 need it only for linking while build time.
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?
Upvotes: 3
Views: 1693
Reputation: 180048
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 is probably to use AC_CONFIG_SUBDIRS
in the top-level configure.ac
to link configuration of the subpackage with the top-level package, but to avoid using SUBDIRS
in the top-level Makefile.am
to trigger make
recursing into the subpackage. Instead of the latter, add a manual rule to the top-level Makefile.am
for building the wanted library via a recursive make
.
In the top-level package, that would look something 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
Be sure, then, to express a proper dependency on testlib-1.0/src/libtestlib.a
where needed, and to use appropriate link options at the top level.
Upvotes: 2
Reputation: 11
I'm not sure if this is too hackish, but giving the SUBDIRS variable a target-specific value seems to work and looks relatively elegant:
SUBDIRS = src
install installdirs: SUBDIRS =
or, more generally
SUBDIRS := foo bar libgazonk
install installdirs: SUBDIRS := $(filter-out libgazonk, $(SUBDIRS))
(Simple expansion necessary to avoid infinite recursion.)
Upvotes: 1
Reputation: 57854
Use AC_CONFIG_SUBDIRS([testlib])
. For code samples, read more about it in the documentation.
EDIT
If you wanted to build convenience libraries without touching the subpackage (for instance, if you stored it as a Git submodule in your main Git repository) then you could:
configure.ac
into your package's configure.ac
configure.ac
include AC_OUTPUT([subpackage/Makefile])
subpackage
out of SUBDIRS
in Makefile.am
have your package's Makefile.am
build the relevant parts of subpackage the way you want them, e.g.
noinst_LIBRARIES = subpackage/libsubpackage.a
subpackage_libsubpackage_a_SOURCES = subpackage/source.c etc.
This may not be what you want, as it involves duplicating a lot of subpackage's build system, but it does allow you to drop the subpackage into your package unchanged.
Upvotes: 1