自动制作,生成的源文件和VPATH构建 [英] Automake, generated source files and VPATH builds

查看:90
本文介绍了自动制作,生成的源文件和VPATH构建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用automake进行VPATH构建.我现在也将生成的源与SWIG一起使用.我在Makefile.am中有规则,例如:

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 $^

然后该文件稍后使用:

myprogram_SOURCES = ... whatever.cpp

$builddir == $srcdir时工作正常.但是在进行VPATH构建(例如mkdir build; cd build; ../configure; make)时,我收到有关缺少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.

生成的源文件应该转到$builddir还是$srcdir? (我认为可能是$builddir.)

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?

推荐答案

简单答案

您应该假定$srcdir是只读的,因此您绝不能在其中写任何东西. 因此,您生成的源代码将以$(builddir)结尾.

Simple answer

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).

默认情况下,自动工具生成的Makefile仅在$srcdir中查找源文件,因此您必须告诉它也检查$builddir.将以下内容添加到您的Makefile.am应该会有所帮助:

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)

之后,您可能会遇到no rule to make target ...错误,您应该可以通过更新源生成规则来解决该错误,如下所示:

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
        # ...

更好的解决方案

您可能会注意到,在当前设置中,发行版tarball(由make dist创建)将包含whatever.cpp文件作为源的一部分,因为您已将该文件添加到了myprogram_SOURCES中. 如果您不希望这样做(例如,因为这可能意味着构建过程将真正使用预生成的文件,而不是再次生成该文件),则可能需要使用类似以下内容的文件. 它使用包装器源文件(whatever_includer.cpp),该文件仅包含生成的文件,然后使用-I$(builddir)查找生成的文件.

A better solution

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:

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:

whatever_includer.cpp:

#include "whatever.cpp"

这篇关于自动制作,生成的源文件和VPATH构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆