1.autoscan(autoconf):掃描源代碼以搜尋普通的可移植性問題,比如檢查編譯器,庫,頭文件等,生成文件configure.scan,它是configure.ac的一個雛形。
yoursourcefiles-->[autoscan*]-->[configure.scan]-->configure.ac
2.aclocal(automake):根據已經安裝的宏,用戶定義宏和acinclude.m4文件中的宏將configure.ac文件所需要的宏集中定義到文件aclocal.m4中。aclocal是一個perl腳本程序,它的定義是:“aclocal-createaclocal.m4byscanningconfigure.ac”
userinputfilesoptionalinputprocessoutputfiles ================================================= acinclude.m4-----. V .-------, configure.ac------------------------>|aclocal| {usermacrofiles}->||------>aclocal.m4 `-------' 3.autoheader(autoconf):根據configure.ac中的某些宏,比如cpp宏定義,運行m4,聲稱config.h.in userinputfilesoptionalinputprocessoutputfiles ================================================= aclocal.m4-------. | V .----------, configure.ac----------------------->|autoheader|---->autoconfig.h.in `----------'4.automake:automake將Makefile.am中定義的結構建立Makefile.in,然後configure腳本將生成的Makefile.in文件轉換為Makefile。如果在configure.ac中定義了一些特殊的宏,比如AC_PROG_LIBTOOL,它會調用libtoolize,否則它會自己產生config.guess和config.sub
userinputfilesoptionalinputprocessesoutputfiles =================================================== .--------, ||--->COPYING ||--->INSTALL ||------>install-sh ||------>missing |automake|------>mkinstalldirs configure.ac----------------------->|| Makefile.am----------------------->||------>Makefile.in ||------>stamp-h.in .---+|--->config.guess |||--->config.sub |`------+-' ||---->config.guess |libtoolize|---->config.sub ||-------->ltmain.sh ||-------->ltconfig `----------'5.autoconf:將configure.ac中的宏展開,生成configure腳本。這個過程可能要用到aclocal.m4中定義的宏。
userinputfilesoptionalinputprocessesoutputfiles =================================================== aclocal.m4,autoconfig.h.in-------. V .--------, configure.ac----------------------->|autoconf|------>configure
6../configure的過程
.------------->[config.cache]configure*--------------------------+------------->config.log|
[config.h.in]-.v.-->[autoconfig.h]
+------->config.status*-+Makefile.in---'`-->Makefile
7.make過程
[autoconfig.h]-.+-->make*--->程序Makefile---'
.---------,config.site--->||
config.cache--->|<strong><span>configure</span>
</strong>
|--->config.cache
|+-,
`-+-------'|
||---->config.status
config.h.in------->|config-|---->config.h
Makefile.in------->|.status|---->Makefile
||---->stamp-h
|+--,
.-+||
|`------+--'|
ltmain.sh------->|ltconfig|------->libtool
|||
`-+------'|
|config.guess|
|config.sub|`------------'
.--------,Makefile------>||config.h------>|make
|
{projectsources}---------------->||-------->{projecttargets}
.-++--,
|`--------'|
|libtool|
|missing|
|install-sh|
|mkinstalldirs|`-------------'
實例:
在/hello/目錄下創建一個hello.c文件,並編譯運行它:
#cd/hello/
(1)編寫源文件hello.c:
#include<stdio.h>
intmain(intargc,char**argv)
{
printf("Hello,GNU!n");
return0;
}
[litao@vm0000131hello]$ll
total4
-rw-rw-r--1litaolitao68Aug1212:02hello.c
一、autoscan
[litao@vm0000131hello]$autoscan
autom4te:configure.ac:nosuchfileordirectory
autoscan:/usr/bin/autom4tefailedwithexitstatus:1
[litao@vm0000131hello]$ll
total8
-rw-rw-r--1litaolitao0Aug1212:03autoscan.log
-rw-rw-r--1litaolitao457Aug1212:03configure.scan
-rw-rw-r--1litaolitao68Aug1212:02hello.c
已經生成了configure.scan,autoscan.log文件
將configure.scan修改為configure.in,最後修改的內容如下:
[litao@vm0000131hello]$mvconfigure.scanconfigure.in
[litao@vm0000131hello]$vimconfigure.in
#-*-Autoconf-*-
#Processthisfilewithautoconftoproduceaconfigurescript.
AC_PREREQ(2.59)
AC_INIT(FULL-PACKAGE-NAME,VERSION,BUG-REPORT-ADDRESS)
AC_CONFIG_SRCDIR([hello.c])
#AC_CONFIG_HEADER([config.h])
AM_INIT_AUTOMAKE(hello,1.0)
#Checksforprograms.
AC_PROG_CC
#Checksforlibraries.
#Checksforheaderfiles.
#Checksfortypedefs,structures,andcompilercharacteristics.
#Checksforlibraryfunctions.
AC_OUTPUT(Makefile)
二、acloacl
[litao@vm0000131hello]$aclocal
生成aclocal.m4和autom4te.cache(生成aclocal.m4的過程中涉及到configure.in)
[litao@vm0000131hello]$ll
total44
-rw-rw-r--1litaolitao31120Aug1212:08aclocal.m4
drwxr-xr-x2litaolitao4096Aug1212:08autom4te.cache
-rw-rw-r--1litaolitao0Aug1212:03autoscan.log
-rw-rw-r--1litaolitao496Aug1212:08configure.in
-rw-rw-r--1litaolitao68Aug1212:02hello.c
三、antoconf
[litao@vm0000131hello]$autoconf
生成configure(根據configure.in,和aclocal.m4)
[litao@vm0000131hello]$ll
total168
-rw-rw-r--1litaolitao31120Aug1212:08aclocal.m4
drwxr-xr-x2litaolitao4096Aug1212:11autom4te.cache
-rw-rw-r--1litaolitao0Aug1212:03autoscan.log
-rwxrwxr-x1litaolitao122297Aug1212:11configure
-rw-rw-r--1litaolitao496Aug1212:08configure.in
-rw-rw-r--1litaolitao68Aug1212:02hello.c
四、編寫Makefile.am:
AUTOMAKE_OPTIONS=foreign
bin_PROGRAMS=hello
hello_SOURCES=hello.c
五、automake
生成Makefile.in,depcomp,install-sh,和missing(根據Makefile.am,和aclocal.m4)
[litao@vm0000131hello]$automake
configure.in:requiredfile`./install-sh'notfound
configure.in:requiredfile`./missing'notfound
Makefile.am:requiredfile`./depcomp'notfound
[litao@vm0000131hello]$automake--add-missing
configure.in:installing`./install-sh'
configure.in:installing`./missing'
Makefile.am:installing`./depcomp'
[litao@vm0000131hello]$ll
total192
-rw-rw-r--1litaolitao31120Aug1212:08aclocal.m4
drwxr-xr-x2litaolitao4096Aug1212:14autom4te.cache
-rw-rw-r--1litaolitao0Aug1212:03autoscan.log
-rwxrwxr-x1litaolitao122297Aug1212:11configure
-rw-rw-r--1litaolitao496Aug1212:08configure.in
lrwxrwxrwx1litaolitao31Aug1212:16depcomp->/usr/share/automake-1.9/depcomp
-rw-rw-r--1litaolitao68Aug1212:02hello.c
lrwxrwxrwx1litaolitao34Aug1212:16install-sh->/usr/share/automake-1.9/install-sh
-rw-rw-r--1litaolitao69Aug1212:15Makefile.am
-rw-rw-r--1litaolitao16561Aug1212:16Makefile.in
lrwxrwxrwx1litaolitao31Aug1212:16missing->/usr/share/automake-1.9/missing
六、configure
生成Makefile,config.log,和config.status
Summarize:
如果拿到的工程文件中,沒有Makefile文件,而只有configure.in和Makefile.am文件,我們是不能夠直接進行編譯的,必須根據configure.in和Makefile.am文件生成編譯所需的Makefile文件。具體操作步驟如下:
1、執行aclocal,產生aclocal.m4文件
aclocal是一個perl腳本程序,它的定義是:“aclocal-createaclocal.m4byscanningconfigure.ac”。aclocal根據configure.in文件的內容,自動生成aclocal.m4文件。而aclocal.m4文件中,包含了生成configure文件所必須的宏。
2、執行autoconf,生成configure文件
autoconf會根據configure.in和aclocal.m4文件,生成configure文件。其實,autoconf就是把configure.in和aclocal.m4文件中定義的內容,變成檢查系統特性、環境變量、軟件必須的參數的shell腳本。
3、執行automake命令,產生Makefile.in
具體命令為:automake--add-missing
automake會根據Makefile.am文件產生一些文件,包含最重要的Makefile.in。前面所生成的configure,會根據Makefile.in文件,來生成最終的Makefile文件。
4、執行configure命令,生成Makefile文件
這樣,就產生了編譯所需要的Makefile文件。運行make,即可編譯。