網路城邦
上一篇 回創作列表 下一篇   字體:
Automake
2007/01/03 15:20:53瀏覽1509|回應0|推薦2
我們從大家最常使用的例例程helloworld開始。
  下面的過程如果簡單地說來就是:A撰寫基本Scrept B執行
  新建三個文件
 helloworld.c ( 0程式碼本身)
 configure.in(1用autoscan命令來幫助產生configure.scan模版
 Makefile.am
  然後執行:


aclocal; autoconf(用來產生自動配置軟體scrept的工具); automake --add-missing; ./configure; make; ./helloworld

  就可以看到Makefile被產生出來,而且可以將helloworld.c編譯透過。
------------------------------------------------------------------------------------------------------    現在開始介紹詳細的過程:
PARTA
1、撰寫程式碼

2、編輯 configure.in (Way1:藉.in設定,經由autoconf 處理後,檢查系統特性、環境變量、軟體必須的參數的shell腳本。Way2:手寫增加缺少的部分)

PS1:autoscan是用來掃描原始碼所在目錄產生configure.scan文件包含了系統配置的基本選項,裏面都是一些巨集定義。autoscan可以用目錄名稱做為參數,但如果你不使用參數的話,那麼
autoscan將認為使用的是目前工作目錄。
PS2:a我們需要將它改名為configure.ac
b增加AM_INIT_AUTOMAKE(targe,Ver),AC_CONFIG_FILES([Makefile]),AC_OUTPUT

注意automake這行沒有下的話,不會建立aclocal.m4
PS3:configure.in文件中的巨集的順序並沒有規定,但是你必須在所有巨集的最前面和最後面分別加上AC_INIT、AC_OUTPUT

3、建立Makefile.am (vi )內容(.am定義巨集和目標,指示automake產生指定的code。例如:巨集bin_PROGRAMS將導致編譯和連接的目標被產生)如下
AUTOMAKE_OPTIONS=foreign
bin_PROGRAMS=helloworld
helloworld_SOURCES=helloworld.c
automake會根據你寫的Makefile.am來自動產生Makefile.in。

---基礎打好後面沒煩惱基礎打好後面沒煩惱基礎打好後面沒煩惱------------------
PARTB
4a、執行 aclocal 根據configure.ac產生 aclcal.m4 (錯誤檢查configure.acPS2、PS3)
PS4:aclocal是一個perl 腳本程式,它的定義是:“aclocal - create aclocal.m4 by scanning configure.ac)
PS5:m4是一個巨集處理器。將輸入拷貝到輸出,同時將巨集展開。巨集可以是內嵌的,也可以是用戶定義的。除了可以展開巨集,m4還有一些內建的函數,用來引用文件,執行命令,整數運算,文本操作,循環等。m4既可以作為編譯器的前端,也可以單獨作為一個巨集處理器

4b、執行autoconf產生 configure(使用GNU m4巨集處理器來處理aclocal.m4產生configure 腳本 ~注意 產生configure完後還需要automake產生Makefile.in才能使用)

PS6:autoconf是用來產生configure文件的。configure是一個腳本,它能設定原始程式來適應各種不同的作業系統平台,並且根據不同的系統來產生合適的Makefile,從而可以使你的源代碼能在不同的作業系統平台上被編譯出來。
PS7:如果檢查通過後,出現....忘記了
 
5、執行automake,會根據Makefile.am文件產生一些文件,包含最重要的Makefile.in。(別忘記Makefile.am,參數要加上去,否則缺少的檔案會出現錯誤訊息命令:



$ automake --add-missing
configure.in: installing `./install-sh'
configure.in: installing `./mkinstalldirs'
configure.in: installing `./missing'
Makefile.am: installing `./depcomp'

  6、執行configure產生Makefile



$ ./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking for gcc... gcc
checking for C compiler default output... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ANSI C... none needed
checking for style of include used by make... GNU
checking dependency style of gcc... gcc3
configure: creating ./config.status
config.status: creating Makefile(output要打才有歐)
config.status: executing depfiles commands
$ ls -l Makefile
-rw-rw-r-- 1 yutao yutao 15035 Oct 15 10:40 Makefile
此時Makefile已經產生出來了。
---幾乎成功了幾乎成功了幾乎成功了幾乎成功了幾乎成功了幾乎成功了幾乎成功了
  7、使用Makefile編譯代碼



$ make
if gcc -DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\" -

DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE=\"helloworld\" -DVERSION=\"1.0\"

-I. -I. -g -O2 -MT helloworld.o -MD -MP -MF ".deps/helloworld.Tpo" \
-c -o helloworld.o `test -f 'helloworld.c' || echo './'`helloworld.c; \
then mv -f ".deps/helloworld.Tpo" ".deps/helloworld.Po"; \
else rm -f ".deps/helloworld.Tpo"; exit 1; \
fi
gcc -g -O2 -o helloworld helloworld.o

  執行helloworld





$ ./helloworld
Hello, Linux World!
( 時事評論政治 )
回應 推薦文章 列印 加入我的文摘
上一篇 回創作列表 下一篇

引用
引用網址:https://classic-blog.udn.com/article/trackback.jsp?uid=keithmin&aid=629648