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構建工具提供更多信息

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章