= Autotool 環境設定及範例筆記 = == 目標 == 將寫好的程式碼透過以下指令就可編譯.安裝及使用 {{{ #!text 1. ./configure 2. make 3. make install }}} === 第一階段:寫好source code及 Makefile === === Step2. 編輯程式碼 === 1. 參考[http://markuskimius.wikidot.com/programming:tut:autotools:2 autotool tutorial][[BR]] 2. 新增hello.c[[BR]] {{{ #!text /* hello.c: A standard "Hello, world!" program */ #include int main(int argc, char* argv[]) { printf("Hello, world!\n"); return ; } }}} 3. 編輯Makefile(註:指令前的空白為)[[BR]] {{{ #!text # Makefile: A standard Makefile for hello.c all: gcc hello.c -o hello clean: rm -f hello }}} === Step3. 執行make,產生執行檔 === * 執行 {{{ $ make }}} *步驟結束後目錄下會有以下檔案: hello.c hello Makefile === 第二階段:使用autoconf產生安裝及設定檔 === ==== Step1. 工具取得及安裝 ==== 1. 工具取得 [ftp://ftp.ntu.edu.tw/gnu/autoconf/autoconf-2.68.tar.gz autoconf下載(v2.68)] 2. 安裝(步驟略) ==== Step2. autoscan ==== * 此一步驟為讓系統自動產生 configure.scan * 將產生的configure.scan更名為configure.ac,以便日後自行修改configure時不會被覆寫掉 * 將Makefile 更名為 Makefile.in 做為日後修改的樣板 ==== Step3. autoconf ==== * 產生configure的可執行檔 * 執行configure {{{ checking for gcc... gcc checking whether the C compiler works... yes checking for C compiler default output file name... a.out checking for suffix of executables... checking whether we are cross compiling... no 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 ISO C89... none needed configure: creating ./config.status config.status: creating Makefile config.status: error: cannot find input file: `config.h.in' }}} * 錯誤訊息:因為無法找到header檔 ==== Step4. autoheader ==== * 執行 autoheader * 產生header檔 * 執行configure {{{ checking for gcc... gcc checking whether the C compiler works... yes checking for C compiler default output file name... a.out checking for suffix of executables... checking whether we are cross compiling... no 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 ISO C89... none needed configure: creating ./config.status config.status: creating Makefile config.status: creating config.h }}} === 第三階段:修改Source Code ===