如何使用 autotools 构建 Python C 扩展模块
大多数可用于构建 Python 扩展模块的文档 使用 distutils,但我想通过使用适当的方法来实现这一点 python autoconf & 改为 automake 宏。
我想知道是否有一个开源项目可以做到这一点 正是这个。 我发现的大多数最终都依赖于 setup.py 文件。 使用这种方法是有效的,但不幸的是最终重建了整个 每当我对模块源文件进行修改时,都会显示源树。
Most of the documentation available for building Python extension modules
uses distutils, but I would like to achieve this by using the appropriate
python autoconf & automake macros instead.
I'd like to know if there is an open source project out there that does
exactly this. Most of the ones I've found end up relying on a setup.py file.
Using that approach works, but unfortunately ends up rebuilding the entire
source tree any time I make a modification to the module source files.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设您有一个项目,其目录名为
src
,那么让我们按照以下步骤使用 autotools 构建和打包 python 扩展:创建 Makefile.am 文件
首先,您需要创建一个 Makefile .am 在项目的根目录中,基本上(但不限于)列出也应该处理的子目录。 你最终会得到这样的结果:
第二个,在
src
目录中,将保存实际编译 python 扩展的指令。 它看起来像这样:编写configure.ac
该文件必须在项目的根目录中创建,并且必须列出项目需要构建的所有库、程序或任何类型的工具,例如编译器、链接器、 像我这样
的懒人通常不会从头开始创建它,我更喜欢使用 autoscan 工具,它会查找您正在使用的东西并生成配置。扫描文件,该文件可用作真实
configure.ac
的基础。要通知
automake
您将需要 Python 的东西,您可以将其添加到您的configure.ac
中:总结
基本上,
automake
有一个内置的 -在知道如何处理 python 内容的扩展中,您只需将其添加到您的configure.ac
文件中,然后在您的Makefile.am
中利用此功能。PyGtk 绝对是一个很棒的例子,但它相当大,所以也许你会想检查另一个项目,比如 Guake
Supposing that you have a project with a directory called
src
, so let's follow the follow steps to get a python extension built and packaged using autotools:Create the Makefile.am files
First, you need to create one Makefile.am in the root of your project, basically (but not exclusively) listing the subdirectories that should also be processed. You will end up with something like this:
The second one, inside the
src
directory will hold the instructions to actually compile your python extension. It will look like this:Write the configure.ac
This file must be created in the root directory of the project and must list all libraries, programs or any kind of tool that your project needs to be built, such as a compiler, linker, libraries, etc.
Lazy people, like me, usually don't create it from scratch, I prefer to use the
autoscan
tool, that looks for things that you are using and generate aconfigure.scan
file that can be used as the basis for your realconfigure.ac
.To inform
automake
that you will need python stuff, you can add this to yourconfigure.ac
:Wrap up
Basically,
automake
has a built-in extension that knows how to deal with python stuff, you just need to add it to yourconfigure.ac
file and then take the advantage of this feature in yourMakefile.am
.PyGtk is definitely an awesome example, but it's pretty big, so maybe you will want to check another project, like Guake
所有 PyGTK 扩展都使用自动工具,因此如果 PyGTK 方面不能为您解决所有问题,那么可能值得查看 PyGTK 源代码. 另外,这是我写的一个更简单的。
All PyGTK extensions use autotools, so if the PyGTK aspects don't kill the whole thing for you, it might be worth having a look at the PyGTK source code. Additionally, here is one I wrote which is more simple.