# GNU Autotools

**GNU Autotools**，又称 GNU 构建系统，是一套编程工具，主要包括 Autoconf、Automake 和 Libtool，其作用是让源代码包能够移植到众多类 Unix 系统，并自动完成构建配置。用 Autotools 维护的软件包会附带一个生成的 `configure` 脚本，因此终端用户只需执行经典的三步序列 `./configure`、`make` 和 `make install` 即可完成构建，无需安装任何维护者工具。<sup>[1](https://hpc.nih.gov/development/autotools.html)</sup><sup> • </sup><sup>[2](https://www.debian.org/doc/manuals/maint-guide/first.en.html)</sup>

| 关键事实 | 详情 |
|---|---|
| 组件 | Autoconf（生成 `configure` 脚本）、Automake（生成 `Makefile.in` 文件）和 Libtool（可移植的静态库与共享库）；Debian 的指南还将 Gettext 计入这套工具之中<sup>[2](https://www.debian.org/doc/manuals/maint-guide/first.en.html)</sup><sup> • </sup><sup>[3](https://www.sourceware.org/autobook/autobook/autobook_1.html)</sup> |
| 用户工作流程 | `./configure` 探测系统，由 `Makefile.in` 生成 `Makefile`，由 `config.h.in` 生成 `config.h`；随后执行 `make` 和 `make install`<sup>[4](https://developer.fedoraproject.org/tech/languages/c/autotools.html)</sup> |
| 维护者输入 | `configure.ac`（Autoconf 宏）以及每个目录一个 `Makefile.am`；`autoreconf --install` 生成 `configure`、`config.h.in` 和各 `Makefile.in` 文件<sup>[4](https://developer.fedoraproject.org/tech/languages/c/autotools.html)</sup> |
| 起源 | 1991 年 6 月作为一个 shell 脚本写成，用于猜测 GNU fileutils 的配置；Autoconf 1.0 于 1992 年 7 月发布<sup>[5](https://www.math.utah.edu/docs/info/autoconf_14.html)</sup> |
| 当前版本 | Autoconf 2.73（稳定版，2026 年 3 月 20 日）和 Automake 1.17（稳定版，2024 年）<sup>[6](https://www.mail-archive.com/autoconf%40gnu.org/msg25059.html)</sup><sup> • </sup><sup>[7](https://lists.gnu.org/archive/html/autotools-announce/2024-07/msg00000.html)</sup> |
| 实测开销 | 在一台 Nexus 4 手机上配置 GLib，Autotools 耗时 220 秒，而 Meson 约需 20 秒；无操作重建耗时 14 秒，而后者仅需 0.25 秒<sup>[8](https://mesonbuild.com/ARM-performance-test.html)</sup> |
| 发行版中的角色 | Fedora 的政策将 Autotools 生成的软件包视为可在宿主机未安装 Autotools 的情况下构建，因此打包构建过程中不应运行 `autoconf` 及其同类工具<sup>[9](https://fedoraproject.org/wiki/PackagingDrafts/AutoConf)</sup> |

## 各组件及其职责

**Autoconf** 根据以 Autoconf 宏写成的输入文件 `configure.ac` 生成 `configure` 脚本，这些宏由 GNU M4 处理。生成的脚本会测试系统是否具备软件包所需的各种特性，例如可用的头文件、库函数和编译器特征，正常情况下无需用户手动干预，也无需传入系统类型参数。它会创建一个名为 `config.status` 的文件，由该文件实际将 `Makefile.in` 等模板文件实例化为最终的 `Makefile`。<sup>[10](https://www.gnu.org/software/autoconf/manual/autoconf-2.70/autoconf.html)</sup><sup> • </sup><sup>[11](https://www.gnu.org/software/autoconf/manual/autoconf-2.60/autoconf.html)</sup> 在底层，Autotools 使用一个名为 `autom4te` 的辅助脚本，而该脚本本身又会调用 GNU M4。<sup>[12](https://www.gnu.org/software/automake/faq/autotools-faq.html)</sup>

**Automake** 根据 `Makefile.am` 模板生成 `Makefile.in` 文件，产出的 makefile 符合 GNU 编码标准。它依赖 Autoconf，并对 `configure.ac` 的内容施加限制。在 `Makefile.am` 中，像 `bin_PROGRAMS = hello` 这样的一行告诉 Automake：该程序将安装到 `bindir` 中；与之配套的 `hello_SOURCES` 变量列出源文件，这些源文件同时会被加入由 `make dist` 构建的发行 tarball。<sup>[13](https://www.gnu.org/s/automake/manual/automake.pdf)</sup><sup> • </sup><sup>[14](https://www.gnu.org/software/automake/manual/html_node/amhello_0027s-Makefile_002eam-Setup-Explained.html)</sup>

Libtool 为编译器和链接器提供命令行接口，使得在任何平台上都能轻松、可移植地生成静态库和共享库。Automake 手册阐述了它存在的根本原因：可移植地构建共享库是一件相对复杂的事情，因此 GNU Libtool 应运而生，以平台无关的方式完成这项工作。<sup>[3](https://www.sourceware.org/autobook/autobook/autobook_1.html)</sup><sup> • </sup><sup>[15](https://www.gnu.org/software/automake/manual/html_node/A-Shared-Library.html)</sup> 当前稳定版本为 libtool 2.5.4。<sup>[16](https://www.gnu.org/software/libtool/)</sup>

这套工具还包含若干辅助程序：`autoreconf`、`autoconf`、`autoheader` 和 `autoscan` 来自 Autoconf 包，`aclocal` 和 `automake` 来自 Automake，`libtoolize` 来自 Libtool。它们共同构成了 GNU 构建系统。<sup>[12](https://www.gnu.org/software/automake/faq/autotools-faq.html)</sup>

## 构建如何运作

维护者编写 `configure.ac` 和 `Makefile.am` 文件，然后运行 `autoreconf --install`，该命令会生成 `configure` 脚本、`config.h.in`，以及每个目录下的一个 `Makefile.in`。这些生成的文件会被加入分发的软件包中。终端用户运行 `./configure`，它会探测系统，在每个目录中生成一个 `Makefile`，并生成 `config.h`；随后 `make` 编译并链接程序。<sup>[4](https://developer.fedoraproject.org/tech/languages/c/autotools.html)</sup>

**生成的文件随 tarball 一起分发。** 用 Autoconf 和 Automake 制作的软件包会附带 `configure` 和 `Makefile.in` 等生成文件，这样终端用户就不必安装重建它们所需的维护者工具。生成的 `Makefile` 中包含一些规则，当 `configure.ac` 发生变化时会重新运行 `autoconf`，从而避免 `configure` 在开发过程中变得过时。<sup>[17](https://www.gnu.org/software/automake/manual/html_node/Version-Control.html)</sup> 正因如此，Fedora 的打包规则将生成文件视为可构建的产物，并不鼓励在打包构建中运行 `autoreconf`，因为在宿主机上重新生成时，若已安装的 Autotools 版本不同，可能产生不可预知的结果。<sup>[9](https://fedoraproject.org/wiki/PackagingDrafts/AutoConf)</sup>

**交叉编译。** `configure` 脚本依据形如 `cpu-vendor-os` 的规范系统类型做出判断，该类型由 `config.guess` 脚本借助 `uname` 或预处理器符号推断得出。交叉编译模式通过 `--host` 显式进入；当 `--host` 与 `--build` 不一致时，`configure` 会跳过那些需要在构建机上运行编译后代码的测试。<sup>[18](https://www.gnu.org/software/autoconf/manual/autoconf-2.64/autoconf.pdf)</sup><sup> • </sup><sup>[19](https://www.gnu.org/software/autoconf/manual/autoconf-2.62/html_node/Hosts-and-Cross_002dCompilation.html)</sup>

## 历史

Autoconf 手册的历史章节记载：1991 年 6 月，作者当时正为[自由软件基金会](https://www.edgepedia.org/zh/free-software-foundation)维护许多 GNU 工具，随着这些工具被移植到越来越多的平台，用户不得不在 makefile 中选择大约 20 个 `-D` 选项。作者编写了一个 shell 脚本，用于猜测 fileutils 软件包的正确设置，该脚本随 fileutils 2.0 一同发布，次月被手工改写以适应其他 GNU 软件包，并在 1991 年秋的 alpha 测试中演变为一个由 m4 宏构建 `configure` 脚本的生成器。Autoconf 1.0 于 1992 年 7 月发布，许多 GNU 软件包随之改用该工具。<sup>[5](https://www.math.utah.edu/docs/info/autoconf_14.html)</sup> 一份构建系统对照表将 Autotools 的起始年份标为 1991 年，CMake 为 2000 年，Meson 为 2013 年，Bazel 为 2015 年。<sup>[20](https://github.com/yellow-footed-honeyguide/autotools-cmake-meson-bazel-comparison)</sup>

开发仍在继续。Autoconf 2.72 于 2023 年 12 月 22 日发布；2026 年 3 月 20 日宣布的 Autoconf 2.73 是一个缺陷修复版本，其最重要的变更是改进了对 2024 年修订版 C 标准（C23）以及默认采用该标准的编译器的支持；它还改进了对 GNU [Gettext](https://www.edgepedia.org/zh/gettext) 及其他第三方扩展的支持。<sup>[21](https://mirrors.kernel.org/gnu/autoconf/)</sup><sup> • </sup><sup>[6](https://www.mail-archive.com/autoconf%40gnu.org/msg25059.html)</sup> GNU Automake 1.17 于 2024 年宣布为稳定版本，当前的 Automake 手册记载的版本为 1.18.1。<sup>[7](https://lists.gnu.org/archive/html/autotools-announce/2024-07/msg00000.html)</sup><sup> • </sup><sup>[13](https://www.gnu.org/s/automake/manual/automake.pdf)</sup> 此前，Automake 1.12.2 和 1.11.6 修复了一个安全问题 CVE-2012-3386，该问题存在于所有使用 Automake 的软件包的 `make distcheck` 规则中。<sup>[22](https://www.gnu.org/software/automake/)</sup>

## 性能与批评

实测比较显示，配置开销是 Autotools 的主要弱点。在 Meson 项目于 Nexus 4 手机上进行的测试中，配置 GLib 时 Autotools 耗时 220 秒（包括 `autogen` 和 `configure` 两个阶段），而 Meson 约需 20 秒；在空构建（即系统仅确认无需重建任何内容）中，Autotools 耗时 14 秒，而 Meson 的 Ninja 后端仅需四分之一秒。该测试中 Meson 的配置并不完全对等，省略了 Gettext 国际化等步骤，但覆盖了约 90% 的配置工作。<sup>[8](https://mesonbuild.com/ARM-performance-test.html)</sup> 在另一项编译 1,000 个生成的 C 文件的基准测试中，Autotools 的配置时间是所有受测系统中最慢的，比第二慢的系统还慢一个数量级以上，而构建时间则较为接近。<sup>[23](https://mesonbuild.com/Simple-comparison.html)</sup>

Meson 项目的比较认可 Autotools 对传统 Unix 平台的出色支持以及大量现成模块，同时列出其缺点：速度慢、复杂、难以正确使用、不可靠、调试痛苦，对非 Unix 平台（尤其是 Windows）支持不佳。<sup>[24](https://github.com/mesonbuild/meson/blob/master/docs/markdown/Comparisons.md)</sup> 一份 2025 年的 C/C++ 构建系统生成器比较给 Meson 打了 83/100 分、CMake 打了 82/100 分，位列前两名，并指出 GNU Autotools 的优势在于可移植性。<sup>[25](https://www.faun.dev/toolbox/compare-c-cpp-build-system-generators/)</sup>

## 在发行版中的使用

Autotools 仍然深深嵌入 Linux 发行版的打包体系。Debian 的维护者指南将 Autotools 定义为由 Autoconf、Automake、Libtool 和 gettext 组成的 GNU 构建系统，并指引打包者通过 `dh-autoreconf` 机制实现自动化。<sup>[2](https://www.debian.org/doc/manuals/maint-guide/first.en.html)</sup> Spack 包管理器提供了一个专用的 `AutotoolsPackage` 构建系统类，并指出许多人都习惯了经典的 configure、make、make install 步骤。<sup>[26](https://fossies.org/linux/spack/lib/spack/docs/build_systems/autotoolspackage.rst)</sup> 延斯·克鲁格（Jens Krueger）是一位在 NIST 举行的 NOBUGS2002 会议上做报告的科学家，他在 2002 年的一篇会议论文中主张采用 Autotools，以便科学软件用户在使用不同编译器、链接器和库的机器之间迁移代码时，不必手工编辑 makefile。<sup>[27](https://arxiv.org/abs/cond-mat/0210430)</sup>

## References

1. [NIH HPC: Autotools](https://hpc.nih.gov/development/autotools.html)
2. [Debian New Maintainers' Guide, Chapter 2: First steps](https://www.debian.org/doc/manuals/maint-guide/first.en.html)
3. [Autoconf, Automake, and Libtool: 1. Introduction (sourceware.org)](https://www.sourceware.org/autobook/autobook/autobook_1.html)
4. [Fedora Developer Portal: Autotools](https://developer.fedoraproject.org/tech/languages/c/autotools.html)
5. [Autoconf manual: History of Autoconf](https://www.math.utah.edu/docs/info/autoconf_14.html)
6. [autoconf-2.73 released [stable], autoconf mailing list archive](https://www.mail-archive.com/autoconf%40gnu.org/msg25059.html)
7. [automake-1.17 released [stable], autotools-announce](https://lists.gnu.org/archive/html/autotools-announce/2024-07/msg00000.html)
8. [Meson: Arm performance test](https://mesonbuild.com/ARM-performance-test.html)
9. [Fedora Project Wiki: PackagingDrafts/AutoConf](https://fedoraproject.org/wiki/PackagingDrafts/AutoConf)
10. [Autoconf 2.70 manual](https://www.gnu.org/software/autoconf/manual/autoconf-2.70/autoconf.html)
11. [Autoconf 2.60 manual](https://www.gnu.org/software/autoconf/manual/autoconf-2.60/autoconf.html)
12. [Autotools FAQ (gnu.org)](https://www.gnu.org/software/automake/faq/autotools-faq.html)
13. [GNU Automake manual (version 1.18.1, PDF)](https://www.gnu.org/s/automake/manual/automake.pdf)
14. [Automake manual: amhello's Makefile.am Setup Explained](https://www.gnu.org/software/automake/manual/html_node/amhello_0027s-Makefile_002eam-Setup-Explained.html)
15. [Automake manual: A Shared Library](https://www.gnu.org/software/automake/manual/html_node/A-Shared-Library.html)
16. [GNU Libtool project page](https://www.gnu.org/software/libtool/)
17. [Automake manual: Version Control](https://www.gnu.org/software/automake/manual/html_node/Version-Control.html)
18. [Autoconf 2.64 manual, Chapter 14: Manual Configuration](https://www.gnu.org/software/autoconf/manual/autoconf-2.64/autoconf.pdf)
19. [Autoconf 2.62 manual: Hosts and Cross-Compilation](https://www.gnu.org/software/autoconf/manual/autoconf-2.62/html_node/Hosts-and-Cross_002dCompilation.html)
20. [autotools-cmake-meson-bazel-comparison (GitHub)](https://github.com/yellow-footed-honeyguide/autotools-cmake-meson-bazel-comparison)
21. [GNU autoconf download archive (kernel.org mirror)](https://mirrors.kernel.org/gnu/autoconf/)
22. [GNU Automake project page](https://www.gnu.org/software/automake/)
23. [Meson: A simple comparison](https://mesonbuild.com/Simple-comparison.html)
24. [Meson documentation: Comparisons](https://github.com/mesonbuild/meson/blob/master/docs/markdown/Comparisons.md)
25. [Best C/C++ Build System Generators: ranked and compared (faun.dev)](https://www.faun.dev/toolbox/compare-c-cpp-build-system-generators/)
26. [Spack documentation: AutotoolsPackage](https://fossies.org/linux/spack/lib/spack/docs/build_systems/autotoolspackage.rst)
27. [Jens Krueger (2002). Autotools for writing portable software. arXiv:cond-mat/0210430](https://arxiv.org/abs/cond-mat/0210430)

---
*Initially written Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 软件与编程 › Development tools and collaboration infrastructure › Build, deployment, and development tooling › Build systems and build tools

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/gnu-autotools

English original: https://www.edgepedia.org/gnu-autotools
