Autoconf

自動化設定指令稿建構程式

GNU Autoconf是一個在Bourne shell下製作供編譯、安裝和打包軟體的組態指令碼英語Configure_script (computing)的工具[2]。Autoconf並不受程式語言限制,常用於CC++ErlangObjective-C。組態指令碼控制了一個軟體套件在特定系統上的安裝。在進行一系列測試後,組態指令碼從模板中生成makefile標頭檔進而調整軟體套件,使之適應某一種系統。Autoconf與AutomakeLibtool等軟體組成了GNU構建系統[3]。Autoconf由戴維·麥肯思英語David Mackenzie於1991年夏天編寫用於支持他在自由軟體基金會的編程工作[4]。此後,Autoconf包含了多人編寫的改進代碼並成為了使用最廣泛的自由編譯組態軟體。[5][6]

Autoconf
開發者GNU
目前版本
  • 2.72 (2023年12月22日;穩定版本)[1]
編輯維基數據鏈結
原始碼庫 編輯維基數據鏈結
作業系統跨平台
類型編程工具
授權條款GPL
網站http://www.gnu.org/software/autoconf/
autoconf和automake的工作流程圖。請注意"configure.ac"在Autoconf早期版本中名為"configure.in"

使用概要 編輯

軟體開發者通過使用GNU m4語言在configure.ac中寫出限定組態指令碼行為的列表。Autoconf將configure.ac中的命令轉化為對應特定平台的組態指令碼。Autoconf本身並不具備編譯能力,它僅僅用於產生通常附帶在軟體套件中的組態指令碼。

configure.ac格式 編輯

The GNU Autoconf手冊建議configure.ac file使用如下格式:

Autoconf requirements
The AC_PREREQ(version)macro can be used to ensure that a recent enough version of the autoconf program is available to process the configure.ac file
AC_INIT(package, version, bug-report-address
This macro is required in every configure.ac file. It specifies the name and version of the software package for which to generate a configure script and the email address of the developer.
information on the package
checks for programs
checks for libraries
checks for header files
checks for types
checks for structures
checks for compiler characteristics
checks for library functions
checks for system services
AC_CONFIG_FILES([file...])
AC_OUTPUT

工作原理 編輯

autoconf類似於perl使用的metaconfig包。先前X window系統所使用的imake系統與autoconf是密切相關,但有不同的理念。

autoconf通過檢查特性而不是軟體版本來確保可移植性。例如Sun OS 4的原生C編譯器不支援ISO C,但是使用者或管理員可以自行安裝支援ISO C的編譯器。基於軟體特性的檢查方法可以發現僅檢查軟體版本的方法檢測不到的支援ISO C的編譯器。因此組態指令碼可以在未知的或者較新的系統中得到合理的結果,同樣允許管理員按照他們的系統來組態指令碼。

批評 編輯

autoconf是一個古老和成熟的產品,如果使用得當,可以使用一個非常簡單的介面進行複雜的交叉編譯。但是有一些批評指出autoconf使用了過時的技術,因而遺留了很多限制。autoconf無法為XcodeVisual Studio製作專案檔案,其指令碼通常大且複雜,因此增加了Debug的難度。Autoconf所使用的M4對於一些開發者來說是陌生的,因此他們需要專門學習[7]。一些開發者並不遵循組態指令碼的一些習慣約定[8]

因此一些自由軟體開發者開始使用其他軟體代替autoconf,KDE於KDE 4起開始使用CMake[9]Scribus同樣開始使用CMake[9]

參見 編輯

註腳 編輯

  1. ^ autoconf-2.72 released [stable]. 2023年12月22日 [2023年12月25日]. 
  2. ^ Autoconf - GNU Project - Free Software Foundation (FSF). GNU Project. [2010-12-16]. (原始內容存檔於2010-12-23). 
  3. ^ The GNU Build System - Autoconf. GNU Project. [2010-12-16]. (原始內容存檔於2010-12-25). 
  4. ^ David Mackenzie. Genesis - Autoconf. GNU Project. [2010-12-16]. (原始內容存檔於2010-12-25). 
  5. ^ David Mackenzie. Leviticus - Autoconf. GNU Project. [2010-12-16]. (原始內容存檔於2010-12-25). 
  6. ^ David Mackenzie. Numbers - Autoconf. GNU Project. [2010-12-16]. (原始內容存檔於2010-12-25). 
  7. ^ McCall, Andrew. Stop the autoconf insanity! Why we need a new build system. 2003-06-21 [2010-12-14]. (原始內容存檔於2010-12-27). 
  8. ^ GNU Coding Standards. [2010-12-14]. (原始內容存檔於2010-12-23). 
  9. ^ 9.0 9.1 Neundorf, Alexander. Why the KDE project switched to CMake -- and how. 2006-06-21 [2010-12-14]. (原始內容存檔於2011-05-07). 

外部連結 編輯

教程 編輯