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?
Simple answer
You should assume that
$srcdiris a read-only, so you must not write anything there. So, your generated source-code will end up in$(builddir).By default, autotool-generated Makefiles will only look for source-files in
$srcdir, so you have to tell it to check$builddiras well. Adding the following to yourMakefile.amshould help:After that you might end up with a
no rule to make target ...error, which you should be able to fix by updating your source-generating rule as in:A better solution
You might notice that in your current setup, the release tarball (as created by
make dist) will contain thewhatever.cppfile as part of your sources, since you added this file to themyprogram_SOURCES. If you don't want this (e.g. because it might mean that the build-process will really take the pregenerated file rather than generating it again), you might want to use something like the following. It uses a wrapper source-file (whatever_includer.cpp) that simply includes the generated file, and it uses-I$(builddir)to then find the generated file.Makefile.am:
whatever_includer.cpp: