0

I have a set of different projects that all share a common set of C++ libraries. Currently these common libs are copied into each code base but this is turning into a major problem for me. We use subversion for version control so I am planning on changing the common libraries into a set of svn externals.

Once I do that though I need a way to either make a parent/child Makefile.am or some way to automatically merge the Makefile.ams together. Is this possible? I know about the SUBDIR functionality, however I am trying to avoid recursive make.

chotchki
  • 4,258
  • 5
  • 34
  • 55
  • any specific reason why you must avoid recursive make? – umläute Sep 27 '12 at 17:53
  • As per this paper http://aegis.sourceforge.net/auug97.pdf . Recursive make also slows down our builds since they can't run in parallel anymore. – chotchki Sep 27 '12 at 18:39
  • However if I have to use a single recursion, I'll do it if that's what it takes. – chotchki Sep 27 '12 at 18:50
  • Why cut-n-paste the code for the library into each project? Make the library a dependency and install it separately, then use it. – William Pursell Sep 27 '12 at 23:20
  • That's what I'm trying to do via the svn externals. By using externals I can avoid the cut and paste and still allow each sub project to decide when its version of the libraries should change – chotchki Sep 28 '12 at 13:01
  • Including the source of a dependency in a project is simply the wrong approach. Modularity is good. Integration is bad. Do not use a version control system as a dependency tracking tool; it is inadequate for the job. – William Pursell Oct 01 '12 at 13:33

1 Answers1

2

I'm going to assume you use static libraries here, because it makes things simpler.

Your common library would look have its own configure.ac and Makefile.am, and probably define the library under noinst_LIBRARIES.

Your project that uses the library would have your common library imported via svn external, something like this:

foo/
foo/configure.ac
foo/Makefile.am
foo/...
foo/libcommon/
foo/libcommon/configure.ac
foo/libcommon/Makefile.am
foo/libcommon/...

In foo's configure.ac, add a call to AC_CONFIG_SUBDIRS([libcommon]). In foo's Makefile.am, add SUBDIRS = libcommon. Both foo and libcommon could be non-recursive except for this one level. In foo's Makefile.am, you'd add something like LDADD = libcommon/libcommon.a. You may also need to add something like AM_CPPFLAGS = -I$(srcdir)/libcommon/include.

Then, when you configure foo, it'll configure libcommon and build it. The fact that the library is declared noinst means it'll only be statically linked into things but never installed in the filesystem.

Jack Kelly
  • 18,264
  • 2
  • 56
  • 81