Node: Conditional Libtool Sources, Next: , Previous: Conditional Libtool Libraries, Up: A Shared Library



Libtool Libraries with Conditional Sources

Conditional compilation of sources in a library can be achieved in the same way as conditional compilation of sources in a program (see Conditional Sources). The only difference is that _LIBADD should be used instead of _LDADD and that it should mention libtool objects (.lo files).

So, to mimic the hello example from Conditional Sources, we could build a libhello.la library using either hello-linux.c or hello-generic.c with the following Makefile.am.

     lib_LTLIBRARIES = libhello.la
     libhello_la_SOURCES = hello-common.c
     EXTRA_libhello_la_SOURCES = hello-linux.c hello-generic.c
     libhello_la_LIBADD = $(HELLO_SYSTEM)
     libhello_la_DEPENDENCIES = $(HELLO_SYSTEM)
     

And make sure $(HELLO_SYSTEM) is set to either hello-linux.lo or hello-generic.lo in ./configure.

Or we could simply use an Automake conditional as follows.

     lib_LTLIBRARIES = libhello.la
     libhello_la_SOURCES = hello-common.c
     if LINUX
     libhello_la_SOURCES += hello-linux.c
     else
     libhello_la_SOURCES += hello-generic.c
     endif