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?
You should assume that $srcdir
is 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 $builddir
as well. Adding the following to your Makefile.am
should help:
VPATH = $(srcdir) $(builddir)
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:
$(builddir)/whatever.cpp: whatever.swig
# ...
You might notice that in your current setup, the release tarball (as created by make dist
) will contain the whatever.cpp
file as part of your sources, since you added this file to the myprogram_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:
dist_noinst_DATA = whatever.swig
whatever.cpp: whatever.swig
swig -c++ -php $^
whatever_includer.cpp: whatever.cpp
myprogram_SOURCES = ... whatever_includer.cpp
myprogram_CPPFLAGS = ... -I$(builddir)
clean-local::
rm -f $(builddir)/whatever.cpp
whatever_includer.cpp:
#include "whatever.cpp"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With