code generation - Automake, generated source files and VPATH builds -
i'm doing vpath builds automake. i'm using generated source, swig. i've got rules in makefile.am
like:
dist_noinst_data = whatever.swig whatever.cpp: whatever.swig swig -c++ -php $^
then file gets used later:
myprogram_sources = ... whatever.cpp
it works fine when $builddir == $srcdir
. when doing vpath builds (e.g. mkdir build; cd build; ../configure; make
), error messages missing whatever.cpp
.
should generated source files go $builddir
or $srcdir
? (i reckon $builddir
.)
how should dependencies , rules specified put generated files in right place?
simple answer
you should assume $srcdir
read-only, must not write there. so, generated source-code end in $(builddir)
.
by default, autotool-generated makefiles source-files in $srcdir
, have tell check $builddir
well. adding following makefile.am
should help:
vpath = $(srcdir) $(builddir)
after might end no rule make target ...
error, should able fix updating source-generating rule in:
$(builddir)/whatever.cpp: whatever.swig # ...
a better solution
you might notice in current setup, release tarball (as created make dist
) contain whatever.cpp
file part of sources, since added file myprogram_sources
. if don't want (e.g. because might mean build-process take pregenerated file rather generating again), might want use following. uses wrapper source-file (whatever_includer.cpp
) includes generated file, , uses -i$(builddir)
find 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"
Comments
Post a Comment