gcc/gdb/make/autotool 文件/教學

 
* 0. autoconf | automake | autoheader 架構圖

GNU build 系統架構圖
-------------------------------------------------------------------------
your source files --> [autoscan*] --> [configure.scan] --> configure.in

configure.in --. .------> autoconf* -----> configure
+---+
[aclocal.m4] --+ `---.
[acsite.m4] ---' |
+--> [autoheader*] -> [config.h.in]
[acconfig.h] ----. |
+------'
[config.h.top] --+
[config.h.bot] --'

Makefile.in -------------------------------> Makefile.in


configure系統所使用的檔案架構
------------------------------------------------------------------------
.-------------> config.cache
configure* ------------+-------------> config.log
|
[config.h.in] -. v .-> [config.h] -.
+--> config.status* -+ +--> make*
Makefile.in ----' `-> Makefile ----'

* 1. autoscan 產生 configure.scan, 將 configure.scan 改名為 configure.in
configure.in 基本架構如下:

AC_INIT(file)
checks for programs
checks for libraries
checks for headers
checks for ........
AC_OUTPUT(file1 file2 ...)

configure.in Macro 之說明
----------------------------------------------------------------------------
AC_INIT(FILE)

這個巨集用來檢查原始碼所在的路徑,autoscan會自動產生,我們不必
修改它。

AM_INIT_AUTOMAKE(PACKAGE,VERSION)i

使用 Automake 所必備的巨集,PACKAGE是我們所要產生軟體套件的名
稱,VERSION 是版本編號。

AC_CONFIG_AUX_DIR(dir)

configure 系統時所使用的所有檔案( install-sh,config.sub,config.guess )
若不想放在 configure 所在的目錄下, 可以利用此巨集指定在子目錄中

AC_CONFIG_HEADER(header.h)

autoheader 會根據 AC_CHECK_HEADERS、AC_DEFINE 等巨集,產生 header.h.in
, configure 參考此檔產生 header.h, 套件中的 header files只要含入
header.h,即可解決編譯時大量的 '-D' 選項 。

AC_PROG_CC

檢查系統可用的 C 編譯器,如果原始程式是用 C 寫的就需要這個巨集。
其他程式檢查巨集請查看 autoconf/acprograms

AC_PROG_INSTALL

檢察系統內是否有 BSD 相容 install 工具程式, 否則以 automake 的
install-sh 替代。

AC_SUBST(VARIABLE)

configure 程式會將 AC_OUTPUT 巨集所列出檔案中與指定變數名稱相同
的位置,取代為該變數的值。

AC_CHECK_HEADERS( header.h)

檢查系統中是否存在 header.h

AC_DEFINE(variable, define , comment)

定義 C preprocessor variable, 可省略後兩項參數, 但預先必須在
acconfig.h 中定義。

ex: #undef USE_DNS

AC_DEFINE_UNQUOTED(variable, 可展開的 definem, comment )

類似 AC_DEFINE , 其中的 define 若包含變數, 則會以內容展開變數

ex:

AC_CONFIG_HEADER( conf.h )
AC_CHECK_HEADERS( unistd.h )
AC_DEFINE(USE_DNS, 1 , 使用DNS)
AC_DEFINEi_UNQUOTED(EDITOR, "$EDITOR", editor 的路徑)

則 autoheader 產生 conf.h.in 內含:
------------------------------------------------------------
/* Define as 1 if you have unistd.h */
#define HAVE_UNISTD_H 0

/* 使用DNS */
#undef USE_DNS

/* editor 的路徑 */
#undef EDITOR

若 configure 時, 若有 unistd.h、及指定 EDITOR=/usr/bin/vi 則
產生之 conf.h 如下
-----------------------------------------------------------
/* Define as 1 if you have unistd.h */
#define HAVE_UNISTD_H 1

/* 使用DNS */
#define USE_DNS 1

/* editor 的路徑 */
#define EDITOR /usr/bin/vi

AC_CHECK_PROG(variable,program,value-if-found,value-if-found,path1:path2)

依指定路徑 path1:path2 尋找指定的 program, 若找到將 variable指定
為 value-if-found, 若沒有找到 variable 指定為 value-if-not-found,
設定 variable 使用檔案的絕對檔案名稱。

AC_PATH_PROG(variable, program, value-if-not-found, path1:path2)

依指定路徑 path1:path2 尋找指定的 program, 若找到將 variable指定
為其完整路徑, 若沒有找到 variable 指定為 value-if-not-found。

AC_CANONICAL_HOST

檢查系統類型, 並將其值存入 $host 變數

AC_CHECK_FUNCS(funcs, action-if-found, action-if-not-found)

找尋是否有指定的 function 存在, 若存在執行 active-if-found 之 shell
command, 反之則執行 active-if-not-found。可被檢查函式請參考
autoconf/acfunctions

AC_ARG_ENABLE( feature,help-string,action-if-given,action-if-not-given)

如果執行 configure 給定 --enable-feature 或 --disable-feature, 則
會啟動相關的 action , enable 會執行 action-if-given, disable 會執行
action-if-not-given。通常與 AC_DEFINE 搭配, 定義是否編譯某一項功能。

AC_OUTPUT(FILE)

設定 configure 所要產生的檔案,如果是 Makefile 的話,configure
便會把它檢查出來的結果 Makefile.in 檔然後產生合適的 Makefile。

ex:
configure.in 片段 Makefile.in 片段
--------------------------------------------------------------
FOO="hello" CFLAGS = -D@FOO@
AC_SUBST(FOO)

則執行 configure 後會產生 Makefile 包含以下片段: CFLAGS = -Dhello

* 2. 編輯 Makefilea.am , automake 根據 configure.in 中的巨集,將 Makefile.am
轉變成 Makefile.in, 執行 automake --add-missing --copy 即可。

--add-missing 將包裝好 configure 所需之檔案補齊( 預設為 link 的方式 )
--copy 所需的檔案以 copy 的方式補齊

automake 支援、認可的 configure.in 巨集
----------------------------------------------------------------------
AC_INIT_AUTOMAKE(package, version)

定義 PACKAGE、VERSION 兩變數

AM_CONFIG_HEADER( header.h )

讓 automake 產生可自動再生成 header.h 的規則,使用此巨集必須先定義
stamp-h.in, 用於標記 header.h 產生的時間。

AC_CANONICAL_HOST
AC_CHECK_TOOL

automake 會確認 config.guess 及 config.sub 的存在。config.guess 用於
猜測系統類型、config.sub用於提供檢查工具。

Makefile.am 選項說明
----------------------------------------------------------------------------
AUTOMAKE_OPTIONS

設定 automake 的選項。Automake 主要是幫助開發 GNU 軟體的人員維
護軟體套件,所以在執行 automake 時,會檢查目錄下是否存在標準
GNU 軟體套件中應具備的文件檔案,例如 'NEWS'、'AUTHOR'、'ChangeLog'
等文件檔。設成 foreign 時,automake 會改用一般軟體套件的標準來檢查。

SUBDIRS

automake 會產生能夠遞迴進入指定目錄的 Makefile 規則。

bin_PROGRAMS

定義我們所要產生的執行檔檔名。如果要產生多個執行檔,每個檔名用
空白字元隔開。

hello_SOURCES

定義 'hello' 這個執行檔所需要的原始檔。如果 'hello' 這個程式是
由多個原始檔所產生,必須把它所用到的原始檔都列出來,以空白字元
隔開。假設 'hello' 這個程式需要 'hello.c'、'main.c'、'hello.h'
三個檔案的話,則定義
hello_SOURCES= hello.c main.c hello.h
如果我們定義多個執行檔,則對每個執行檔都要定義相對的 filename_SOURCES。

pkgdata_DATA

將 pkgdata_DATA 所指定的檔案安裝到 pkgdatadir 指定的目錄,*_DATA 對應
*dir,如 localstate_DATA 安裝至 localstatedir。

EXTRA_DIST

在 make dist 時將指定的檔案一起打包。

* 3. 建構 GNU build 系統

aclocal -> autoheader -> autoconf -> automake

* 4. Reference

- http://www.amath.washington.edu/~lf/tutorials/autoconf/
- http://ftp.csie.chu.edu.tw/freeware/intel/10/automake-1.9-sol10-intel-local.gz
- http://china.sina.com.tw/tech/s/2004-10-19/1115443045.shtml
arrow
arrow
    全站熱搜

    Bluelove1968 發表在 痞客邦 留言(3) 人氣()