The GNU Build System

2. The GNU Build System

Autoconf solves an important problem
—reliable discovery of system-specifc build and runtime information
—but this is only one piece of the puzzle for the development of portable software.

Autoconf 解决了一个重要的问题
— 可靠地发现系统特定的构建和运行时信息
— 但这只是开发可移植软件的难题之一

To this end, the GNU project has developed a suite of integrated utilities to finish the job Autoconf started:
the GNU build system, whose most important components are Autoconf, Automake, and Libtool.

为此,GNU项目开发了一套集成的实用程序来完成Autoconf开始的工作:
GNU构建系统,其最重要的组件是Autoconf,Automake 和 Libtool。

In this chapter, we introduce you to those tools, point you to sources of more information,
and try to convince you to use the entire GNU build system for your software.

在本章中,我们向你介绍这些工具,指出更多信息来源,并尝试说服你将整个GNU构建系统用于你的软件。

2.1 Automake

The ubiquity of make means that a makefile is almost the only viable way to distribute automatic build rules for software, but one quickly runs into its numerous limitations.

make的普遍存在意味着makefile几乎是分发软件自动构建规则的唯一可行方法,但是很快就遇到了许多限制。

Its lack of support for automatic dependency tracking, recursive builds in subdirectories, reliable timestamps (e.g., for network file systems), and so on, mean that developers must painfully (and often incorrectly) reinvent the wheel for each project.

makefile 不支持自动依赖关系跟踪,子目录中的递归构建,可靠的时间戳(例如,对于网络文件系统)等等,
这意味着开发人员必须痛苦地(并且通常错误的)为每个项目重复这些工作。

Portability is nontrivial, thanks to the quirks of make on many systems.

可移植程序如此繁琐,主要是由于许多系统都有各自的实现方式

On top of all this is the manual labor required to implement the many standard targets that users have come to expect (make install, make distclean, make uninstall, etc.).

在此基础上实现用户所期望的许多标准目标程序只能靠体力劳动(安装,制造,清理,卸载等)。

Since you are, of course, using Autoconf, you also have to insert repetitive code in your ‘Makefile.in’ to recognize @CC@,@CFLAGS@, and other substitutions provided by configure. Into this mess steps Automake.

当然由于你使用 Autoconf, 你还必须在"Makefile.in"中插入重复代码,以识别 @CC@,@CFLAGS@ 以及 configure 提供的其他代替标记。


Automake allows you to specify your build needs in a ‘Makefile.am’ file with a vastly simpler and more powerful syntax than that of a plain makefile, and then generates a portable ‘Makefile.in’ for use with Autoconf.

Automake 允许你在'Makefile.am'文件中指定您的构建需求,其语法比普通makefile简单得多,功能更强大,然后生成便于使用的'Makefile.in'

For example, the ‘Makefile.am’ to build and install a simple “Hello world” program might look like:

例如,'Makefile.am'构建和安装一个简单的 “Hello world” 程序类似下面这样:

bin_PROGRAMS = hello
hello_SOURCES = hello.c

The resulting ‘Makefile.in’ (~400 lines) automatically supports all the standard targets, the substitutions provided by Autoconf, automatic dependency tracking, VPATH building, and so on.

所生成的'Makefile.in'(〜400行)自动支持所有标准目标,Autoconf 提供的替换,自动依赖关系跟踪,VPATH构建等等。

make builds the hello program,and make install installs it in'/usr/local/bin'(or whatever prefix was given to configure,if not/usr/local).

用 make 构建 hello 程序,并用make install安装到'/usr/local/bin'(或任何配置的前缀)。

The benefits of Automake increase for larger packages (especially ones with subdirectories),
but even for small programs the added convenience and portability can be substantial.

对于较大的软件包(特别是具有子目录的软件包),Automake更具优势,但即使对于小程序,增加的便利性和可移植性也是非常实用的。

And that’s not all…

而且这并不是全部…

2.2 Gnulib

GNU software has a well-deserved reputation for running on many different types of systems.

GNU软件在许多不同类型的系统上运行时都具有当之无愧的声誉。

While our primary goal is to write software for the GNU system, many users and developers have been introduced to us through the systems that they were already using.

虽然我们的主要目标是为GNU系统编写软件,但许多用户和开发人员通过他们已在使用的系统介绍给我们。


Gnulib is a central location for common GNU code, intended to be shared among free software packages.

Gnulib 是公共 GNU 代码的中央单元,旨在 在免费软件包之间共享。

Its components are typically shared at the source level, rather than being a library that gets built, installed, and linked against.

它的组件通常在源级别共享,而不是被构建,安装和链接的库。

The idea is to copy files from Gnulib into your own source tree.

这个想法是将文件从Gnulib复制到您自己的源代码树中。

There is no distribution tarball; developers should just grab source modules from the repository.

没有发布 tar 包;开发人员应该从仓库中获取源模块。

The source files are available online, under various licenses, mostly GNU GPL or GNU LGPL.

源文件的各种许可证可以在网上获取,主要是GNU GPLGNU LGPL


Gnulib modules typically contain C source code along with Autoconf macros used to configure the source code.

Gnulib 模块通常包含C源代码以及用于配置源代码的 Autoconf 宏。

For example, the Gnulib stdbool module implements a'stdbool.h'header that nearly conforms to C99, even on old-fashioned hosts that lack'stdbool.h'.

比如,Gnulib 实现了一个与C99 “stdbool.h” 头几乎一致的 stdbool 模块,即使在缺少”stdbool.h”的老式主机上也是如此。

This module contains a source file for the replacement header, along with an Autoconf macro that arranges to use the replacement header on old-fashioned systems.

该模块包含替换 “stdbool.h” 头文件的源文件,以及在老式系统上安排使用替换该头文件的 Autoconf 宏

2.3 Libtool

Often, one wants to build not only programs, but libraries, so that other programs can benefit from the fruits of your labor.

通常,人们不仅要构建程序,而且还要构建库,以便其他程序可以从你的劳动成果中受益。

Ideally, one would like to produce shared (dynamically linked) libraries, which can be used by multiple programs without duplication on disk or in memory and can be updated independently of the linked programs.

理想情况下,生成共享(动态链接)库,可以由多个程序使用,而不会在磁盘或内存中产生副本,并且可以独立于链接的程序进行更新。

Producing shared libraries portably, however, is the stuff of nightmares—each system has its own incompatible tools, compiler flags, and magic incantations.

然而,生成共享库就是一场恶梦—每个系统都有自己的不兼容的工具,编译器标志和魔法咒语

Fortunately, GNU provides a solution: Libtool.

万幸的是,GNU 提供了一个解决方案:Libtool.

Libtool handles all the requirements of building shared libraries for you,
and at this time seems to be the only way to do so with any portability.

Libtool为你处理了构建共享库的所有需求,这似乎是目前唯一的方式来实现所有的可移植性。

It also handles many other headaches, such as: the interaction of Make rules with the variable suffixes of shared libraries,
linking reliably with shared libraries before they are installed by the superuser, and supplying a consistent versioning system
(so that different versions of a library can be installed or upgraded without breaking binary compatibility).

它还处理了许多其他头痛的问题,例如:Make规则与共享库变量后缀的交互
在共享库被超级用户安装之前可靠地链接,并提供一个一致的版本控制系统
(以便可以在不破坏二进制兼容性的情况下安装或升级不同版本的库)

Although Libtool, like Autoconf, can be used without Automake, it is most simply utilized in conjunction with Automake—there, Libtool is used automatically whenever shared libraries are needed, and you need not know its syntax.

虽然 Libtool,与 Autoconf 一样,可以在没有 Automake 的情况下使用, 但是它与Automake结合使用是最简单地—
每当需要共享库时,都会自动使用Libtool,并且您不需要知道其语法。

2.4 Pointers

Developers who are used to the simplicity of make for small projects on a single system might be daunted at the prospect of learning to use Automake and Autoconf.

习惯于在单个系统上为小型项目做简单化的开发人员可能会在学习使用AutomakeAutoconf的前景中感到失望。

As your software is distributed to more and more users,
however, you otherwise quickly find yourself putting lots of effort into reinventing the services that the GNU build tools provide, and making the same mistakes that they once made and overcame.
(Besides, since you’re already learning Autoconf, Automake is a piece of cake.)

因为随着你的软件分发给越来越多的用户,你很快就会发现自己花了很多精力来重构GNU构建工具提供的服务,
并且你犯了与他们曾经做过和克服过的同样的错误。
(除此之外, 由于你已经学会了 Autoconf, 学习Automake就是小菜一碟了)


There are a number of places that you can go to for more information on the GNU build tools.

有许多地方可以为GNU构建工具提供更多信息

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值