* Dizzy wrote on Wed, Jan 31, 2007 at 12:44:39PM CET: > I would like to somehow describe a Makefile.am file as: > > libsocket_a_SOURCES=Socket.cpp Socket.hpp > > libconnection_a_SOURCES=Connection.cpp Connection.hpp > libconnection_a_LIBADD=libsocket.a > > And then, if I have a sbin_PROGRAMS like > sbin_PROGRAMS=prog1 > > prog1_SOURCES=... > prog1_LDADD=libconnection.a > > automake should generate a makefile that has targets for libsocket.a and > libconnection.a ONLY as needed.
Learn about EXTRA_noinst_LIBRARIES and other EXTRA_* thingies. > But this is very complex (and redundant as one has to specify dependencies in > 2 places one with LIBADD/LDADD and the other with those variables to trigger > the dependency targets), imagine that there are hundreds of small noinst > libraries each with it's own dependency, thus one would need to make hundreds > of conditionals like that. Instead of pushing all information through automake conditionals (which I think is often the more readable solution), you can also just use autoconf substitutions (i.e., set the value of some variable in configure and AC_SUBST it); but then, you must have specified all possibly built things in EXTRA_* variables, so automake emits rules for them. For example: # Makefile.am: # All of the libraries: EXTRA_noinst_LIBRARIES = libfoo.a libbar.a libbaz.a libfoo_a_SOURCES = ... # Only the ones we'll actually need: noinst_LIBRARIES = $(myneededlibs) # configure.ac: myneededlibs=libfoo.a if $whatever; then myneededlibs="$myneededlibs libbar.a" fi AC_SUBST([myneededlibs]) That way you can keep the number of substituted values down, which probably also helps keep your logic simpler. Alternatively, you could make just two libraries instead of many, and compute the list of _SOURCES for them; again, remember to list all possible sources in EXTRA_*_SOURCES. There's more than one way to do it. Hope that helps. Cheers, Ralf