views:

172

answers:

2

I've got a Subversion project that uses Gnu Autotools (i.e., automake, autoconf, and libtool) to manage source code within a subfolder (called 'subpackage'). The subpackage references source files that are above the subpackage's root source directory, and are common to other subpackages. Unfortunately, when running 'make dist' to create the distribution tarball, the common source files do not get included in the distribution.

Is there a way to use autoconf/automake to move these common source files into a subdirectory of the subpackage before distributing the source, and to have the makefile adjust itself to correctly point to the relocated source files? Clearly, it would be possible to have the makefile move these source files over before compiling, but for working within the Subversion repository, this causes problems because these moved files are revision controlled, and its easy to accidentally edit the moved file instead of the original.

+1  A: 

You could have an empty directory in subpackage, called, say, "common", with a makefile that copies the external files in. Then you could use the dist-hook target to move the files directly into the version of the "common" directory that will get zipped up into the tarball. That way you don't have to worry about them lying around and being edited. You would also overwrite the Makefile.am, Makefile.in and Makefile in "common" as you copied.

Example in subpackage/common/Makefile.am (untested):

dist-hook:
    cp -p $(topsrcdir)/../common/Makefile* $(topsrcdir)/../common/*.[ch] $(distdir)

I'm not 100% sure this will work though. It might break the rest of your package, depending on where everything else expects to find those source files; it probably will break making dist if you unpack the tarball and try to make dist from there. You should know that this sort of trickery is frowned upon. But I hope I've given you enough ideas to play around with.

ptomato
Thank you for the suggestions! This is somewhat analogous to what we do today in a similar context, except that we copy over the files first and then build them (so that the Makefiles are correct for both subversion and the distribution). The problem is getting all the Makefiles (the makefile in the common directory and the makefile in the $(top_srcdir) to play nicely.
Matt Ball
+1  A: 

Instead of moving files around (which always sounds fishy to me), Why not use symbolic links? You could have your subpackage reference only local files, and a Makefile rule that says "if the local files is not here, create a symbolic link to the parent's file". During make dist, the symbolic link will be converted into a plain file automatically.

adl
I like this approach and will give it a shot! My only hesitation is whether it will work on a Windows system (possibly running Cygwin). On Windows systems, the symbolic links appear as .lnk files. This is probably okay in a pure Cygwin setup (since Cygwin Bash correctly interprets .lnk files as symbolic links), but I wonder if Microsoft Visual Studio would also handle them correctly.
Matt Ball