Autotools¶
Autotools
构建助手是对 autotools 命令行调用的封装。它会将诸如 ./configure
或 make
这样的调用抽象成 Python 方法调用。
用法
from conan import ConanFile
from conan.tools.gnu import Autotools
class App(ConanFile):
settings = "os", "arch", "compiler", "build_type"
def build(self):
autotools = Autotools(self)
autotools.configure()
autotools.make()
它会读取由 AutotoolsToolchain 生成的 conanbuild.conf
文件,以了解调用 configure 和 make 脚本所需的参数。
configure_args:用于调用
configure
脚本的参数。make_args:用于调用
make
脚本的参数。
参考¶
- class Autotools(conanfile, namespace=None)¶
- 参数:
conanfile – 当前的配方对象。始终使用
self
。namespace – 当你在同一个配方中有多个 toolchain 调用时,此参数可以避免冲突。通过设置此参数,用于将信息传递给 toolchain 的 conanbuild.conf 文件将被命名为:<namespace>_conanbuild.conf。默认值为
None
,表示生成的文件名为 conanbuild.conf。在 AutotoolsToolchain 的构造函数中也必须使用相同的命名空间值,以便它能够从正确的文件中读取信息。
- configure(build_script_folder=None, args=None)¶
调用 configure 脚本。
- 参数:
args – 用于
configure
调用的参数列表。build_script_folder – configure 脚本所在的子文件夹。如果未指定,则使用 conanfile.source_folder。
- make(target=None, args=None, makefile=None)¶
调用 make 程序。
- 参数:
target – (可选,默认为
None
):选择要构建的目标。这允许为某些 AutoTools 项目构建例如文档、共享库或安装。args – (可选,默认为
None
):用于make
调用的参数列表。makefile – (可选,默认为
None
):允许指定一个自定义的 makefile 来代替默认的 “Makefile”。
- install(args=None, target=None, makefile=None)¶
这只是
self.make(target="install")
或self.make(target="install-strip")
的一个“别名”。- 参数:
args – (可选,默认为
None
):用于make
调用的参数列表。默认情况下,如果传递的值为None
,则会向调用中添加一个参数DESTDIR=unix_path(self.package_folder)
。有关 tools.microsoft.unix_path() 函数 的更多信息。target – (可选,默认为
None
):选择要安装的目标。makefile – (可选,默认为
None
):允许指定一个自定义的 makefile 来代替默认的 “Makefile”。
- autoreconf(build_script_folder=None, args=None)¶
调用
autoreconf
。- 参数:
args – (可选,默认为
None
):用于autoreconf
调用的参数列表。build_script_folder – configure 脚本所在的子文件夹。如果未指定,则使用 conanfile.source_folder。
conf¶
Autotools
构建助手受这些 [conf]
变量的影响。
tools.gnu:make_program
允许定义正在使用的make
可执行文件。对于 MinGW 构建,这将默认为mingw32-make
,对于任何其他构建,则默认为make
。tools.build:install_strip
(Conan 2.20.0 起) 将在Autotools.install()
方法中定义make install-strip
目标(如果设置为True
),否则将使用make install
目标。