成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

Linux Automake工具生成Makefile軟件實現步驟

運維 系統運維
在本文中,將給大家介紹如何使用Linux Automake和automake兩個工具來幫助我們自動地生成符合自由軟件慣例的Makefile,這樣就可以象常見的GNU程序一樣,只要使用“./configure”,“make”,“make instal”就可以把程序安裝到Linux系統中去了。

使用的環境,本文所提到的程序是基于Linux發行版本:Fedora Core release 1,它包含了我們要用到的Linux Automake,automake。 從helloworld入手,我們從大家最常使用的例子程序helloworld開始。 下面的過程如果簡單地說來就是:新建三個文件:
helloworld.c
configure.in
Makefile.am

然后執行:
aclocal; autoconf; automake --add-missing; ./configure; make; ./helloworld
就可以看到Makefile被產生出來,而且可以將helloworld.c編譯通過。
很簡單吧,幾條命令就可以做出一個符合慣例的Makefile,感覺如何呀。

現在開始介紹Linux Automake工具生成Makefile軟件實現步驟詳細的過程:

1、建目錄
在你的工作目錄下建一個helloworld目錄,我們用它來存放helloworld程序及相關文件,如在/home/my/build下:
$ mkdir helloword
$ cd helloworld

2、 helloworld.c
然后用你自己最喜歡的編輯器寫一個hellowrold.c文件,如命令:vi helloworld.c。使用下面的代碼作為helloworld.c的內容。
 

  1. int main(int argc, char** argv)  
  2. {  
  3. printf("Hello, Linux World!\n");  
  4. return 0;  
  5. }  

完成后保存退出。
現在在helloworld目錄下就應該有一個你自己寫的helloworld.c了。

3、生成configure
我們使用autoscan命令來幫助我們根據目錄下的源代碼生成一個configure.in的模板文件。
命令:
$ autoscan
$ ls
configure.scan helloworld.c
執行后在hellowrold目錄下會生成一個文件:configure.scan,我們可以拿它作為configure.in的藍本。
現在將configure.scan改名為configure.in,并且編輯它,按下面的內容修改,去掉無關的語句:
configure.in內容開始
 

  1. # -*- Autoconf -*-  
  2. # Process this file with autoconf to produce a configure script.   
  3. AC_INIT(helloworld.c)  
  4. AM_INIT_AUTOMAKE(helloworld, 1.0)   
  5. # Checks for programs.  
  6. AC_PROG_CC   
  7. # Checks for libraries.   
  8. # Checks for header files.   
  9. # Checks for typedefs, structures, and compiler characteristics.   
  10. # Checks for library functions.  
  11. AC_OUTPUT(Makefile)  

configure.in內容結束
然后執行命令aclocal和autoconf,分別會產生aclocal.m4及configure兩個文件:
 

  1. $ aclocal   
  2. $ls   
  3. aclocal.m4 configure.in helloworld.c   
  4. $ autoconf   
  5. $ ls   
  6. aclocal.m4 autom4te.cache configure configure.in helloworld.c   

 

大家可以看到configure.in內容是一些宏定義,這些宏經autoconf處理后會變成檢查系統特性、環境變量、軟件必須的參數的shell腳本。 autoconf 是用來生成自動配置軟件源代碼腳本(configure)的工具。configure腳本能獨立于autoconf運行,且在運行的過程中,不需要用戶的干預。 要生成configure文件,你必須告訴autoconf如何找到你所用的宏。方式是使用aclocal程序來生成你的aclocal.m4。
 
aclocal根據configure.in文件的內容,自動生成aclocal.m4文件。aclocal是一個perl 腳本程序,它的定義是:“aclocal - create aclocal.m4 by scanning configure.ac”。 autoconf從configure.in這個列舉編譯軟件時所需要各種參數的模板文件中創建configure。 autoconf需要GNU m4宏處理器來處理aclocal.m4,生成configure腳本。 m4是一個宏處理器。將輸入拷貝到輸出,同時將宏展開。宏可以是內嵌的,也可以是用戶定義的。除了可以展開宏,m4還有一些內建的函數,用來引用文件,執行命令,整數運算,文本操作,循環等。m4既可以作為編譯器的前端,也可以單獨作為一個宏處理器。

4、新建Makefile.am
新建Makefile.am文件,命令:
$ vi Makefile.am
內容如下:
AUTOMAKE_OPTIONS=foreign
bin_PROGRAMS=helloworld
helloworld_SOURCES=helloworld.c
automake會根據你寫的Makefile.am來自動生成Makefile.in。
Makefile.am中定義的宏和目標,會指導automake生成指定的代碼。例如,宏bin_PROGRAMS將導致編譯和連接的目標被生成。

5、運行automake
命令:
 

  1. $ automake --add-missing  
  2. configure.in: installing `./install-sh'  
  3. configure.in: installing `./mkinstalldirs'  
  4. configure.in: installing `./missing'  
  5. Makefile.am: installing `./depcomp'  


automake會根據Makefile.am文件產生一些文件,包含最重要的Makefile.in。

6、執行configure生成Makefile
 

  1. $ ./configure   
  2. checking for a BSD-compatible install... /usr/bin/install -c  
  3. checking whether build environment is sane... yes  
  4. checking for gawk... gawk  
  5. checking whether make sets $(MAKE)... yes  
  6. checking for gcc... gcc  
  7. checking for C compiler default output... a.out  
  8. checking whether the C compiler works... yes  
  9. checking whether we are cross compiling... no  
  10. checking for suffix of executables...   
  11. checking for suffix of object files... o  
  12. checking whether we are using the GNU C compiler... yes  
  13. checking whether gcc accepts -g... yes  
  14. checking for gcc option to accept ANSI C... none needed  
  15. checking for style of include used by make... GNU  
  16. checking dependency style of gcc... gcc3  
  17. configure: creating ./config.status  
  18. config.status: creating Makefile  
  19. config.status: executing depfiles commands  
  20. $ ls -l Makefile  
  21. -rw-rw-r-- 1 yutao yutao 15035 Oct 15 10:40 Makefile   

你可以看到,此時Makefile已經產生出來了。

7、使用Makefile編譯代碼
 

  1. $ make  
  2. if gcc -DPACKAGE_NAME="" -DPACKAGE_TARNAME="" -DPACKAGE_VERSION="" -   
  3. DPACKAGE_STRING="" -DPACKAGE_BUGREPORT="" -DPACKAGE="helloworld" -DVERSION="1.0"   
  4. -I. -I. -g -O2 -MT helloworld.o -MD -MP -MF ".deps/helloworld.Tpo" \  
  5. -c -o helloworld.o `test -f 'helloworld.c' || echo './'`helloworld.c; \  
  6. then mv -f ".deps/helloworld.Tpo" ".deps/helloworld.Po"; \  
  7. else rm -f ".deps/helloworld.Tpo"; exit 1; \  
  8. fi  
  9. gcc -g -O2 -o helloworld helloworld.o  
  10. 運行helloworld   
  11. $ ./helloworld   
  12. Hello, Linux World!  


這樣helloworld就編譯出來了,你如果按上面的步驟來做的話,應該也會很容易地編譯出正確的helloworld文件。你還可以試著使用一些其他的make命令,如make clean,make install,make dist,看看它們會給你什么樣的效果。感覺如何?自己也能寫出這么專業的Makefile,老板一定會對你刮目相看。

【編輯推薦】

  1. Autoconf使用關于autoconf安裝條件介紹 
  2. Autoconf使用生成Makefile的方法及其規則
  3. autoconf安裝關于可移植的源代碼詳解
  4. Autoconf教程關于UNIX文件系統概述
  5. Autoconf教程關于安全管理介紹

 

責任編輯:chenqingxiang 來源: 互聯網
相關推薦

2017-09-12 09:22:51

LinuxMakefileautoconf工具

2010-06-22 17:09:52

Linux Autom

2010-06-22 23:52:42

Automake使用

2010-03-01 09:57:55

Linux Makef

2010-06-22 15:45:06

Autoconf使用

2010-06-22 17:45:34

Linux Autom

2010-06-22 22:50:40

Automake使用

2009-10-26 13:45:39

linux Makef

2009-10-26 11:34:42

linux makef

2009-12-14 10:47:34

Linux makef

2016-10-18 11:16:42

評估選擇軟件

2010-02-25 17:49:36

Linux Makef

2010-06-13 15:26:42

2010-05-27 12:52:42

Linux流量監控軟件

2017-06-06 14:44:37

2010-06-18 16:35:54

Linux amidi

2010-06-22 15:40:54

Autoconf使用

2009-08-10 11:12:06

2010-01-05 15:26:04

Linux軟件

2010-05-28 14:34:17

Linux開發工具
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 久久噜噜噜精品国产亚洲综合 | 在线观看视频一区 | 日韩在线不卡视频 | 日韩在线观看网站 | 91精品国产美女在线观看 | 99久久精品国产麻豆演员表 | 日韩欧美中文字幕在线观看 | 久久久久久久久91 | 欧美精品一区二区三区在线播放 | 久久久久久久国产精品影院 | 精品国产三级 | 精品久久成人 | 久久久91精品国产一区二区精品 | 精品亚洲永久免费精品 | 99热99| 婷婷不卡 | 久久网日本| 色在线免费 | 做a视频在线观看 | 99热最新网址 | 欧美一区在线视频 | 91视频网| 成人精品一区二区三区中文字幕 | 成人免费黄色片 | 精品久久一区 | 日韩一区二区三区在线观看视频 | 国产精品国产三级国产aⅴ中文 | 国产日韩一区二区三区 | 天天干天天草 | 亚洲一区在线日韩在线深爱 | 手机在线观看av | 亚洲欧美一区二区三区1000 | 国外激情av | 人人干人人草 | v片网站 | 国产在线观看网站 | 日本在线综合 | 国产精品久久久久久亚洲调教 | 日韩插插| 国产精品国产成人国产三级 | 精品在线播放 |