前段時間,學習c,用autoconf和automake生成了乙個簡單的makefile檔案。
autoconf是乙個用於生成可以自動地配置軟體原始碼包,用以適應多種unix類系統的shell指令碼工具,其中autoconf需要用到 m4,便於生成指令碼。automake是乙個從makefile.am檔案自動生成makefile.in的工具。為了生成makefile.in,automake還需用到perl,由於automake建立的發布完全遵循gnu標準,所以在建立中不需要perl。
具體步驟如下:
1.在linux下新建乙個helloworld目錄。
2.在helloworld下新建乙個helloworld.c檔案,內容如下:
int main(int argc,char **argv)
3.生成configure
3.1 先用autoscan命令根據原始碼生成configure.scan,把configure.scan重新命名為configure.in,編輯此檔案,找到
#process this file with autoconif to ...
...<1>
#checks for programs ...
...ac_output<2>
把<1>標註的內容改為:
ac_init(helloworld.c)
am_init_automake(helloworld,1.0)
把<2>標註的內容改為:
ac_output(makefile)
3.2 執行aclocal生成aclocal.m4檔案
3.3 執行autoconf生成configure檔案
4.新建makefile.am,內容如下:
automake_options=foreign
bin_programs=helloworld
helloworld_sources=helloworld.c
5.執行automake --add-missing 生成makefile.in
6.執行configure生成makefile
7.執行make生成helloworld.o,helloworld檔案
8.執行程式,執行./helloworld
Makefile自動生成標頭檔案依賴
makefile自動生成標頭檔案依賴是很常用的功能,本文的目的是想盡量詳細說明其中的原理和過程。首先給出乙個本人在小專案中常用的makefile模板,支援自動生成標頭檔案依賴。cc gcc cflags wall o includeflags ldflags objs seq.o targets t...
Makefile自動生成標頭檔案依賴
makefile自動生成標頭檔案依賴是很常用的功能,本文的目的是想盡量詳細說明其中的原理和過程。首先給出乙個本人在小專案中常用的makefile模板,支援自動生成標頭檔案依賴。cc gcc cflags wall o includeflags ldflags objs seq.o targets t...
三 Makefile 生成多個目標檔案
一 makefile規則 二 makefile案例 多個檔案生成乙個目標檔案 三 makefile 生成多個目標檔案 四 makefile包含 標頭檔案和庫檔案 我們工作的時候經常會遇到 要多寫幾個不同的測試案例,去測試不同的功能,這個時候 需要編譯多個 可執行檔案。假如我們的目錄下有三個原檔案需要...