I'm doing VPATH builds with automake. I'm now also using generated source, with SWIG. I've got rules in Makefile.am like:
dist_noinst_DATA = whatever.swig
whatever.cpp: whatever.swig
swig -c++ -php $^
Then the file gets used later:
myprogram_SOURCES = ... whatever.cpp
It works fine when $builddir == $srcdir. But when doing VPATH builds (e.g. mkdir build; cd build; ../configure; make), I get error messages about missing whatever.cpp.
Should generated source files go to $builddir or $srcdir? (I reckon probably $builddir.)
How should dependencies and rules be specified to put generated files in the right place?
Usually, you want to keep
$srcdirreadonly, so that if for instance the source is distributed unpacked on a CDROM, you can still run/.../configurefrom some other part of the file-system.However if you are using SWIG to generate source code for a wrapper library, you probably want to distribute that SWIG-generated code as well so that your users do not need to install SWIG to compile your code. Then you have indeed a choice: you can decide that the SWIG-generated code should end in
$builddir(it's OK:make distwill collect it there and include it in the tarball), or you could decide to output SWIG-generated code in$srcdirsince it is really a source from the point of view of the distributed package. An advantage of keeping it in$srcdiris that whenmake distcheckattempts to build your package from a read-only source directory, it will fail on any attempt to call SWIG to regenerate the wrapper source. If you have your wrapper source in$builddir, you might not notice you have some broken rule that cause SWIG to be run on the user's host; by generating in$srcdiryou ensure that SWIG is not needed by your users.So my preference is to output SWIG wrapper sources in
$srcdir. My setup for Python wrappers looks as follows:Note that I use
$(srcdir)for all targets, because of limitations of theVPATHfeature on various flavors ofmake. My setup to deal with the multiple files output by SWIG could be improved, but as these rules are not run by users and it has never caused me any problem, I do not bother.