Next: , Previous: , Up: Building a Shared Library   [Contents][Index]


8.3.3 Building Libtool Libraries Conditionally

Like conditional programs (see Conditional compilation of programs), there are two main ways to build conditional libraries: using Automake conditionals or using Autoconf AC_SUBSTitutions.

The important implementation detail you have to be aware of is that the place where a library will be installed matters to libtool: it needs to be indicated at link-time using the -rpath option.

For libraries whose destination directory is known when Automake runs, Automake will automatically supply the appropriate ‘-rpath’ option to libtool. This is the case for libraries listed explicitly in some installable _LTLIBRARIES variables such as lib_LTLIBRARIES.

However, for libraries determined at configure time (and thus mentioned in EXTRA_LTLIBRARIES), Automake does not know the final installation directory. For such libraries you must add the ‘-rpath’ option to the appropriate ‘_LDFLAGS’ variable by hand.

The examples below illustrate the differences between these two methods.

Here is an example where $(WANTEDLIBS) is an AC_SUBSTed variable set at ./configure-time to either libfoo.la, libbar.la, both, or none. Although $(WANTEDLIBS) appears in the lib_LTLIBRARIES, Automake cannot guess it relates to libfoo.la or libbar.la by the time it creates the link rule for these two libraries. Therefore the -rpath argument must be explicitly supplied.

EXTRA_LTLIBRARIES = libfoo.la libbar.la
lib_LTLIBRARIES = $(WANTEDLIBS)
libfoo_la_SOURCES = foo.c …
libfoo_la_LDFLAGS = -rpath '$(libdir)'
libbar_la_SOURCES = bar.c …
libbar_la_LDFLAGS = -rpath '$(libdir)'

Here is how the same Makefile.am would look using Automake conditionals named WANT_LIBFOO and WANT_LIBBAR. Now Automake is able to compute the -rpath setting itself, because it’s clear that both libraries will end up in $(libdir) if they are installed.

lib_LTLIBRARIES =
if WANT_LIBFOO
lib_LTLIBRARIES += libfoo.la
endif
if WANT_LIBBAR
lib_LTLIBRARIES += libbar.la
endif
libfoo_la_SOURCES = foo.c …
libbar_la_SOURCES = bar.c …

Next: Libtool Libraries with Conditional Sources, Previous: Building Libtool Libraries, Up: Building a Shared Library   [Contents][Index]