在開始試著用 Automake 之前,請先確認(rèn)你的系統(tǒng)已經(jīng)安裝以下的軟體: 1. GNU Automake 2. GNU Autoconf 3. GNU m4 4. perl 5. GNU LiBTool (假如你需要產(chǎn)生 shared library)
我會建議你最好也使用 GNU C/C++ 編譯器 、GNU Make 以及其它 GNU 的工具程式來做為開發(fā)的環(huán)境,這些工具都是屬於 Open Source Software不僅免費而且功能強大。假如你是使用Red Hat linux 可以找到所有上述軟體的 rpm 檔,F(xiàn)reeBSD 也有現(xiàn)成的 package 可以直 接安裝,或著你也可以自行下載這些軟體的原始檔回來 DIY。以下的范例是在 Red Hat linux 5.2 + CLE2 的環(huán)境下所完成的。
3. 一個簡單的例子
Automake 所產(chǎn)生的 Makefile 除了可以做到程式的編譯和連結(jié),也已經(jīng)把如何產(chǎn)生程式文件(如 manual page, info 檔及 dvi 檔) 的動作,還有把原始程式包裝起來以供散 的動作都考慮進去了,所以原始程式所存放的目錄架構(gòu)最好符合 GNU 的標(biāo)準(zhǔn)慣例,接下來我拿hello.c 來做為例子。
2. 編輯 configure.scan 檔,如下所示,并且把它的檔名改成configure.in dnl Process this file with autoconf to prodUCe a con figure script. AC_INIT(hello.c) AM_INIT_AUTOMAKE(hello, 1.0) dnl Checks for programs. AC_PROG_CC dnl Checks for libraries. dnl Checks for header files. dnl Checks for typedefs, structures, and compiler ch aracteristics. dnl Checks for library functions. AC_OUTPUT(Makefile)
6. 最後執(zhí)行 ./configure , % ./configure creating cache ./config.cache checking for a BSD compatible install... /usr/bin/in stall -c checking whether build environment is sane... yes checking whether make sets ${MAKE}... yes checking for working aclocal... found checking for working autoconf... found checking for working automake... found checking for working autoheader... found checking for working makeinfo... found checking for gcc... gcc checking whether the C compiler (gcc ) works... yes checking whether the C compiler (gcc ) is a cross-co mpiler... no checking whether we are using GNU C... yes checking whether gcc accepts -g... yes updating cache ./config.cache creating ./config.status creating Makefile
make all 產(chǎn)生我們設(shè)定的目標(biāo),即此范例中的執(zhí)行檔。只打 make 也可以,此時會開始編譯原始碼,然後連結(jié),并且產(chǎn)生執(zhí)行檔。
make clean 清除之前所編譯的執(zhí)行檔及目的檔 (object file, *.o)。
make distclean 除了清除執(zhí)行檔和目的檔外,也把 configure 所產(chǎn)生的 Makefile也清除掉。
make install 將程式安裝至系統(tǒng)中。假如原始碼編譯無誤,且執(zhí)行結(jié)果正確,便可以把程式安裝至系統(tǒng)預(yù)設(shè)的執(zhí)行檔存放路徑。假如我們用bin_PROGRAMS 巨集的話,程式會被安裝至 /usr/local/bin 這個目錄。
make dist 將程式和相關(guān)的檔案包裝成一個壓縮檔以供散播 (distribution) 。執(zhí)行完在目錄下會產(chǎn)生一個以 PACKAGE-VERSION.tar.gz 為名稱的檔案。PACKAGE 和 VERSION 這兩個變數(shù)是根據(jù) configure.in 檔中AM_INIT_AUTOMAKE(PACKAGE, VERSION) 的定義。在此范例中會產(chǎn)生 'hello-1.0.tar.gz' 的檔案。
make distcheck 和 make dist 類似,但是加入檢查包裝後的壓縮檔是否正常。這個目標(biāo)除了把程式和相關(guān)檔案包裝成 tar.gz 檔外,還會自動把這個壓 縮檔解開,執(zhí)行 configure,并且進行 make all 的動作,確認(rèn)編譯無誤後,會顯示這個 tar.gz 檔已經(jīng)預(yù)備好可供散播了。這個檢查非 常有用,檢查過關(guān)的套件,基本上可以給任何一個具備 GNU 發(fā)展境的人去重新編譯。就 hello-1.tar.gz 這個范例而言,除了在 Red
一九九八年是 Open Source 運動風(fēng)起云涌的一年,許多 Open Source 的軟體普遍受到網(wǎng)路上大眾的歡迎和使用。感謝所有為 Open Source 奉獻的人們,也希望藉由本文能吸引更多的人加入『自由』、『開放』的 OpenSource 行列。
About this document ...
輕輕松松產(chǎn)生 Makefile1
This document was generated using the LaTeX2Html translator Version 98.2 beta6 (August 14th, 1998) Copyright (C) 1993, 1994, 1995, 1996, Nikos Drakos, ComputerBased Learning Unit, University of Leeds.Copyright (C) 1997, 1998, Ross Moore, Mathematics Department,Macquarie University, Sydney.
The command line arguments were: latex2html -split 0 -show_section_numbers automake.tex The translation was initiated by on 1999-02-11