automake: Conditional Libtool Libraries
1
1 8.3.3 Building Libtool Libraries Conditionally
1 ----------------------------------------------
1
1 Like conditional programs (⇒Conditional Programs), there are two
1 main ways to build conditional libraries: using Automake conditionals or
1 using Autoconf ‘AC_SUBST’itutions.
1
1 The important implementation detail you have to be aware of is that
1 the place where a library will be installed matters to libtool: it needs
1 to be indicated _at link-time_ using the ‘-rpath’ option.
1
1 For libraries whose destination directory is known when Automake
1 runs, Automake will automatically supply the appropriate ‘-rpath’ option
1 to libtool. This is the case for libraries listed explicitly in some
1 installable ‘_LTLIBRARIES’ variables such as ‘lib_LTLIBRARIES’.
1
1 However, for libraries determined at configure time (and thus
1 mentioned in ‘EXTRA_LTLIBRARIES’), Automake does not know the final
1 installation directory. For such libraries you must add the ‘-rpath’
1 option to the appropriate ‘_LDFLAGS’ variable by hand.
1
1 The examples below illustrate the differences between these two
1 methods.
1
1 Here is an example where ‘WANTEDLIBS’ is an ‘AC_SUBST’ed variable set
1 at ‘./configure’-time to either ‘libfoo.la’, ‘libbar.la’, both, or none.
1 Although ‘$(WANTEDLIBS)’ appears in the ‘lib_LTLIBRARIES’, Automake
1 cannot guess it relates to ‘libfoo.la’ or ‘libbar.la’ at the time it
1 creates the link rule for these two libraries. Therefore the ‘-rpath’
1 argument must be explicitly supplied.
1
1 EXTRA_LTLIBRARIES = libfoo.la libbar.la
1 lib_LTLIBRARIES = $(WANTEDLIBS)
1 libfoo_la_SOURCES = foo.c ...
1 libfoo_la_LDFLAGS = -rpath '$(libdir)'
1 libbar_la_SOURCES = bar.c ...
1 libbar_la_LDFLAGS = -rpath '$(libdir)'
1
1 Here is how the same ‘Makefile.am’ would look using Automake
1 conditionals named ‘WANT_LIBFOO’ and ‘WANT_LIBBAR’. Now Automake is
1 able to compute the ‘-rpath’ setting itself, because it’s clear that
1 both libraries will end up in ‘$(libdir)’ if they are installed.
1
1 lib_LTLIBRARIES =
1 if WANT_LIBFOO
1 lib_LTLIBRARIES += libfoo.la
1 endif
1 if WANT_LIBBAR
1 lib_LTLIBRARIES += libbar.la
1 endif
1 libfoo_la_SOURCES = foo.c ...
1 libbar_la_SOURCES = bar.c ...
1