自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Linux Makefile自動(dòng)生成的運(yùn)行步驟

運(yùn)維 系統(tǒng)運(yùn)維
首先創(chuàng)建一個(gè) Linux Makefile.am.這一步是創(chuàng)建Linux Makefile很重要的一步,automake要用的腳本配置文件是Linux Makefile.am,用戶需要自己創(chuàng)建相應(yīng)的文件。之后,automake工具轉(zhuǎn)換成Linux Makefile.in。

在向大家詳細(xì)介紹Linux Makefile之前,首先讓大家了解下Linux Makefile,然后全面介紹Linux Makefile,希望對(duì)大家有用。由于畢業(yè)設(shè)計(jì)開(kāi)發(fā)的平臺(tái)是Linux, 為了在Linux進(jìn)行,Linux Makefile的編寫(xiě)是必不可少的,為偷懶,我想使用autotools來(lái)進(jìn)行Makefile的自動(dòng)生成,在閱讀大量的資料后,在理解的基礎(chǔ)之上,做了一個(gè)小實(shí)驗(yàn),過(guò)程記錄得非常詳細(xì)!

我的平臺(tái)是:HP 6510B Notebook Fedora 8 32 位的Autotools工具的版本均為Fedora 8 完全自帶的,尚未進(jìn)行過(guò)升級(jí)!為了編譯一個(gè)簡(jiǎn)單的源文件main.c,需要自動(dòng)生成一個(gè)makefile,以下是步驟:

Linux Makefile第一步

在/root/project/main目錄下創(chuàng)建一個(gè)文件main.c,其內(nèi)容如下:

  1. #include <stdio.h>   
  2. int main(int argc, char** argv)   
  3. {   
  4. printf("Hello, Auto Makefile!\n");   
  5. return 0;   
  6. }  

此時(shí)狀態(tài)如下:

  1. [root@localhost main]# pwd  
  2. /root/project/main  
  3. [root@localhost main]# ls  
  4. main.c  
  5. [root@localhost main]#  

Linux Makefile第二步:

  1. 運(yùn)行 autoscan , 自動(dòng)創(chuàng)建兩個(gè)文件:   
  2. autoscan.log  configure.scan此時(shí)狀態(tài)如下:  
  3. [root@localhost main]# autoscan  
  4. [root@localhost main]# ls  
  5. autoscan.log  configure.scan  main.c  
  6. [root@localhost main]#  

第三步:修改configure.scan的文件名為configure.in查看configure.in的內(nèi)容:

  1. # -*- Autoconf -*-  
  2. # Process this file with autoconf to produce a configure script.  
  3.  
  4. AC_PREREQ(2.61)  
  5. AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)  
  6. AC_CONFIG_SRCDIR([main.c])  
  7. AC_CONFIG_HEADER([config.h])  
  8.  
  9. # Checks for programs.  
  10. AC_PROG_CC  
  11.  
  12. # Checks for libraries.  
  13. # Checks for header files.  
  14. # Checks for typedefs, structures, and compiler characteristics.  
  15. # Checks for library functions.  
  16. AC_OUTPUT  

解讀以上的文件:

  1. # -*- Autoconf -*-  
  2. # Process this file with autoconf to produce a configure script.  
  3. # AC_PREREQ:  
  4. # 確保使用的是足夠新的Autoconf版本。如果用于創(chuàng)建configure的Autoconf的版  
  5. # 本比version 要早,就在標(biāo)準(zhǔn)錯(cuò)誤輸出打印一條錯(cuò)誤消息并不會(huì)創(chuàng)建configure。  
  6. AC_PREREQ(2.61)  
  7. #  
  8. # 初始化,定義軟件的基本信息,包括設(shè)置包的全稱,版本號(hào)以及報(bào)告BUG時(shí)需要用的郵箱地址  
  9. #  
  10. AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)  
  11. #  
  12. # 用來(lái)偵測(cè)所指定的源碼文件是否存在,來(lái)確定源碼目錄的有效性  
  13. #  
  14. AC_CONFIG_SRCDIR([main.c])  
  15. #  
  16. # 用于生成config.h文件,以便autoheader使用  
  17. #  
  18. AC_CONFIG_HEADER([config.h])  
  19. # Checks for programs.  
  20. AC_PROG_CC  
  21. # Checks for libraries.  
  22. # Checks for header files.  
  23. # Checks for typedefs, structures, and compiler characteristics.  
  24. # Checks for library functions.  
  25. # 創(chuàng)建輸出文件。在`configure.in'的末尾調(diào)用本宏一次。  
  26. #  
  27. AC_OUTPUT  
  28.  

修改動(dòng)作:
1.修改AC_INIT里面的參數(shù): AC_INIT(main,1.0, pgpxc@163.com)
2.添加宏AM_INIT_AUTOMAKE, 它是automake所必備的宏,也同前面一樣,PACKAGE是所要產(chǎn)生軟件套件的名稱,VERSION是版本編號(hào)。
3.在AC_OUTPUT后添加輸出文件Linux Makefile

修改后的結(jié)果:

  1. #                                               -*- Autoconf -*-  
  2. # Process this file with autoconf to produce a configure script.  
  3.  
  4. AC_PREREQ(2.61)  
  5. AC_INIT(main, 1.0, pgpxc@163.com)  
  6. AC_CONFIG_SRCDIR([main.c])  
  7. AC_CONFIG_HEADER([config.h])  
  8. AM_INIT_AUTOMAKE(main,1.0)  
  9.  
  10. # Checks for programs.  
  11. AC_PROG_CC  
  12. # Checks for libraries.  
  13. # Checks for header files.  
  14. # Checks for typedefs, structures, and compiler characteristics.  
  15. # Checks for library functions.  
  16. AC_OUTPUT([Makefile]) 


第四步:運(yùn)行 aclocal,

生成一個(gè)“aclocal.m4”文件和一個(gè)緩沖文件夾autom4te.cache,該文件主要處理本地的宏定義。此時(shí)的狀態(tài)是:

  1. [root@localhost main]# aclocal  
  2. [root@localhost main]# ls  
  3. aclocal.m4  autom4te.cache  autoscan.log  configure.in  configure.in~  main.c  
  4. [root@localhost main]#  

第五步:運(yùn)行 autoconf, 目的是生成 configure 此時(shí)的狀態(tài)是:

  1. [root@localhost main]# autoconf  
  2. [root@localhost main]# ls  
  3. aclocal.m4      autoscan.log  configure.in   main.c  
  4. autom4te.cache  configure     configure.in~  
  5. [root@localhost main]#  

第六步:運(yùn)行 autoheader,它負(fù)責(zé)生成config.h.in文件。

該工具通常會(huì)從“acconfig.h”文件中復(fù)制用戶附加的符號(hào)定義,因此此處沒(méi)有附加符號(hào)定義,所以不需要?jiǎng)?chuàng)建“acconfig.h”文件。此時(shí)的狀態(tài)是:

  1. [root@localhost main]# autoheader  
  2. [root@localhost main]# ls  
  3. aclocal.m4      autoscan.log  configure     configure.in~  
  4. autom4te.cache  config.h.in   configure.in  main.c  
  5. [root@localhost main]#  

第七步:下面即將運(yùn)行 automake, 但在此之前應(yīng)該做一下準(zhǔn)備工作!

首先創(chuàng)建一個(gè) Linux Makefile.am.這一步是創(chuàng)建Linux Makefile很重要的一步,automake要用的腳本配置文件是Linux Makefile.am,用戶需要自己創(chuàng)建相應(yīng)的文件。之后,automake工具轉(zhuǎn)換成Linux Makefile.in。

這個(gè)Linux Makefile.am的內(nèi)容如下:

  1. AUTOMAKE_OPTIONS=foreign 
  2. bin_PROGRAMS=main 
  3. mainmain_SOURCES=main.c 

下面對(duì)該腳本文件的對(duì)應(yīng)項(xiàng)進(jìn)行解釋。其中的AUTOMAKE_OPTIONS為設(shè)置automake的選項(xiàng)。由于GNU(在第1章中已經(jīng)有所介紹)對(duì)自己發(fā)布的軟件有嚴(yán)格的規(guī)范,比如必須附帶許可證聲明文件COPYING等,否則automake執(zhí)行時(shí)會(huì)報(bào)錯(cuò)。

automake提供了三種軟件等級(jí):foreign、gnu和gnits,讓用戶選擇采用,默認(rèn)等級(jí)為gnu。在本例使用foreign等級(jí),它只檢測(cè)必須的文件。定義要產(chǎn)生的執(zhí)行文件名。如果要產(chǎn)生多個(gè)執(zhí)行文件,每個(gè)文件名用空格隔開(kāi)。

main_SOURCES定義“main”這個(gè)執(zhí)行程序所需要的原始文件。如果”main”這個(gè)程序是由多個(gè)原始文件所產(chǎn)生的,則必須把它所用到的所有原始文件都列出來(lái),并用空格隔開(kāi)。例如:若目標(biāo)體“main”需要“main.c”、“sunq.c”、“main.h”三個(gè)依賴文件,則定義main_SOURCES=main.c sunq.c main.h。要注意的是,如果要定義多個(gè)執(zhí)行文件,則對(duì)每個(gè)執(zhí)行程序都要定義相應(yīng)的file_SOURCES。

其次使用automake對(duì)其生成“configure.in”文件,在這里使用選項(xiàng)“—adding-missing”可以讓automake自動(dòng)添加有一些必需的腳本文件。
運(yùn)行后的狀態(tài)是:

  1. [root@localhost main]# automake --add-missing  
  2. configure.in:8: installing `./missing'  
  3. configure.in:8: installing `./install-sh'  
  4. Makefile.am: installing `./depcomp'  
  5. [root@localhost main]# ls  
  6. aclocal.m4      config.h.in   configure.in~  main.c        Makefile.in  
  7. autom4te.cache  configure     depcomp        Makefile.am   missing  
  8. autoscan.log    configure.in  install-sh     Makefile.am~  
  9. [root@localhost main]#  

Linux Makefile第八步運(yùn)行configure,

在這一步中,通過(guò)運(yùn)行自動(dòng)配置設(shè)置文件configure,把Makefile.in變成了最終的Makefile。運(yùn)行的結(jié)果如下:

  1. [root@localhost main]# ./configure   
  2. checking for a BSD-compatible install... /usr/bin/install -c  
  3. checking whether build environment is sane... yes  
  4. checking for a thread-safe mkdir -p... /bin/mkdir -p  
  5. checking for gawk... gawk  
  6. checking whether make sets $(MAKE)... yes  
  7. checking for gcc... gcc  
  8. checking for C compiler default output file name... a.out  
  9. checking whether the C compiler works... yes  
  10. checking whether we are cross compiling... no  
  11. checking for suffix of executables...   
  12. checking for suffix of object files... o  
  13. checking whether we are using the GNU C compiler... yes  
  14. checking whether gcc accepts -g... yes  
  15. checking for gcc option to accept ISO C89... none needed  
  16. checking for style of include used by make... GNU  
  17. checking dependency style of gcc... gcc3  
  18. configure: creating ./config.status  
  19. config.status: creating Makefile  
  20. config.status: creating config.h  
  21. config.status: executing depfiles commands  
  22. [root@localhost main]# ls  
  23. aclocal.m4      config.h.in    configure.in   main.c        Makefile.in  
  24. autom4te.cache  config.log     configure.in~  Makefile      missing  
  25. autoscan.log    config.status  depcomp        Makefile.am   stamp-h1  
  26. config.h        configure      install-sh     Makefile.am~  
  27. [root@localhost main]#  

Linux Makefile第九步運(yùn)行 make,

對(duì)配置文件Makefile進(jìn)行測(cè)試一下此時(shí)的狀態(tài)如下:

  1. [root@localhost main]# make  
  2. cd . && /bin/sh /root/project/main/missing --run aclocal-1.10   
  3. cd . && /bin/sh /root/project/main/missing --run automake-1.10 --foreign   
  4. cd . && /bin/sh /root/project/main/missing --run autoconf  
  5. /bin/sh ./config.status --recheck  
  6. running CONFIG_SHELL=/bin/sh /bin/sh ./configure   --no-create --no-recursion  
  7. checking for a BSD-compatible install... /usr/bin/install -c  
  8. checking whether build environment is sane... yes  
  9. checking for a thread-safe mkdir -p... /bin/mkdir -p  
  10. checking for gawk... gawk  
  11. checking whether make sets $(MAKE)... yes  
  12. checking for gcc... gcc  
  13. checking for C compiler default output file name... a.out  
  14. checking whether the C compiler works... yes  
  15. checking whether we are cross compiling... no  
  16. checking for suffix of executables...   
  17. checking for suffix of object files... o  
  18. checking whether we are using the GNU C compiler... yes  
  19. checking whether gcc accepts -g... yes  
  20. checking for gcc option to accept ISO C89... none needed  
  21. checking for style of include used by make... GNU  
  22. checking dependency style of gcc... gcc3  
  23. configure: creating ./config.status  
  24. /bin/sh ./config.status  
  25. config.status: creating Makefile  
  26. config.status: creating config.h  
  27. config.status: config.h is unchanged  
  28. config.status: executing depfiles commands  
  29. cd . && /bin/sh /root/project/main/missing --run autoheader  
  30. rm -f stamp-h1  
  31. touch config.h.in  
  32. make  all-am  
  33. make[1]: Entering directory `/root/project/main'  
  34. gcc -DHAVE_CONFIG_H -I.     -g -O2 -MT main.o -MD -MP -MF .deps/main.Tpo -c -o main.o main.c  
  35. mv -f .deps/main.Tpo .deps/main.Po  
  36. gcc  -g -O2   -o main main.o    
  37. cd . && /bin/sh ./config.status config.h  
  38. config.status: creating config.h  
  39. config.status: config.h is unchanged  
  40. make[1]: Leaving directory `/root/project/main'  
  41. [root@localhost main]# ls  
  42. aclocal.m4      autoscan.log  config.h.in  config.status  configure.in   depcomp     main    main.o    Makefile.am   Makefile.in  stamp-h1  
  43. autom4te.cache  config.h      config.log   configure      configure.in~  install-sh  main.c  Makefile  Makefile.am~  missing  
  44. [root@localhost main]#   
  45.  

Linux Makefile第十步運(yùn)行生成的文件 main:

  1. [root@localhost main]# ./main  
  2. Hello, Auto Makefile!  
  3. [root@localhost main]#  

至此,所有的步驟完成了,為了理解并做好這個(gè)實(shí)驗(yàn),我花費(fèi)了兩天的時(shí)間了??!能夠看到最終的成果,這是最讓人開(kāi)心的?。≠澴约阂幌?!

【編輯推薦】

  1. Linux Makefile編譯使用的環(huán)境從helloworld入手
  2. Linux Makefile系統(tǒng)的真相符合自由軟件慣例
  3. Linux Makefile介紹自動(dòng)編譯和鏈接
  4. Linux Makefile自動(dòng)編譯和鏈接使用的環(huán)境
  5. Linux Makefile介紹使用的環(huán)境深入淺出
責(zé)任編輯:佚名 來(lái)源: CSDN
相關(guān)推薦

2010-06-22 17:28:35

Linux Autom

2010-02-25 15:11:48

Linux Makef

2010-03-01 16:40:40

Linux Makef

2010-02-24 16:01:39

Linux Makef

2017-09-12 09:22:51

LinuxMakefileautoconf工具

2010-06-22 15:40:54

Autoconf使用

2009-10-26 13:45:39

linux Makef

2009-12-14 10:47:34

Linux makef

2009-10-26 11:34:42

linux makef

2019-10-14 09:14:37

Linuxbash命令

2009-10-27 17:58:12

linux make命

2010-06-22 17:09:52

Linux Autom

2010-02-26 10:47:30

Linux Makef

2020-08-11 18:20:42

Linux運(yùn)行腳本開(kāi)機(jī)啟動(dòng)

2020-06-11 07:57:48

Linux腳本數(shù)據(jù)

2010-02-24 14:55:35

Linux Makef

2023-07-31 17:29:21

Docker鴻蒙

2022-05-12 12:55:28

容器Kubernetes運(yùn)行容器

2023-03-02 23:45:23

linux開(kāi)機(jī)啟動(dòng)Windows

2011-03-09 10:25:25

Linux安裝LAMP
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)