linux軟體編譯安裝:make與configure
1. 什麼是make和configure
make命令主要是用來簡化編譯過程。 make執行時,會在目前的目錄下搜尋 Makefile( or makefile) 檔案, 而Makefile裡面記錄了源碼如何編譯的詳細資料。 make會自動判斷源碼是否經過了變動了而自動更新執行檔案。
軟體開發商通常都會寫一個檢測使用者作業環境的程式,就是configure 或 config, 運行檢測完畢後會主動建 Makefile 檔案。
2. make命令好處
簡化編譯時間所需要執行的命令。編譯完成後,如果修改了某個源碼檔案,則 make 只會針對被修改的檔案進行編譯,其他的目標檔案不會被改變。重新編譯只會更新(update)操作,
3. Makefile文法
文法: 目標(target): 目標檔案1 目標檔案2 gcc -o 欲建立的可執行檔 目標檔案1 目標檔案2
[gang@www]$ vim Makefilehello: hello.o thank_you.o gcc -o hello hello.o thank_you.o clean: rm -f hello hello.o thank_you.o
clean刪除目標檔案
[gang@www]$ make cleanrm -f hello hello.o thank_you.o [gang@www]$ makecc -c -o hello.o hello.ccc -c -o thank_you.o thank_you.cgcc -o hello hello.o thank_you.o [gang@www]$ ./hello Hello World. Thank you.
makefile可以使用變數
[gang@www]$ vim MakefileOBJS = hello.o thank_you.oCFLAGS = -Wallhello: ${OBJS} gcc -o hello ${OBJS}clean: rm -f hello ${OBJS}變數賦值 = 兩邊有空格, $@ : 代表當前的目標 gcc -o $@ ${OBJS}
4. 安裝基本步驟
1. ./configure 建立Makefile 檔案 2. make clean 刪除目標檔案, 3. make 根據 Makefile 進行編譯。 產生可執行檔, 可執行檔放在目前的目錄, 尚未被安裝到預定安裝目錄中。 4. make install 會根據Makefile 中的 install 選項, 將上一步編譯完的資料安裝到預設目錄中。