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

Linux Makefile自動生成的運行步驟

運維 系統運維
首先創建一個 Linux Makefile.am.這一步是創建Linux Makefile很重要的一步,automake要用的腳本配置文件是Linux Makefile.am,用戶需要自己創建相應的文件。之后,automake工具轉換成Linux Makefile.in。

在向大家詳細介紹Linux Makefile之前,首先讓大家了解下Linux Makefile,然后全面介紹Linux Makefile,希望對大家有用。由于畢業設計開發的平臺是Linux, 為了在Linux進行,Linux Makefile的編寫是必不可少的,為偷懶,我想使用autotools來進行Makefile的自動生成,在閱讀大量的資料后,在理解的基礎之上,做了一個小實驗,過程記錄得非常詳細!

我的平臺是:HP 6510B Notebook Fedora 8 32 位的Autotools工具的版本均為Fedora 8 完全自帶的,尚未進行過升級!為了編譯一個簡單的源文件main.c,需要自動生成一個makefile,以下是步驟:

Linux Makefile第一步

在/root/project/main目錄下創建一個文件main.c,其內容如下:

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

此時狀態如下:

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

Linux Makefile第二步:

  1. 運行 autoscan , 自動創建兩個文件:   
  2. autoscan.log  configure.scan此時狀態如下:  
  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的內容:

  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版本。如果用于創建configure的Autoconf的版  
  5. # 本比version 要早,就在標準錯誤輸出打印一條錯誤消息并不會創建configure。  
  6. AC_PREREQ(2.61)  
  7. #  
  8. # 初始化,定義軟件的基本信息,包括設置包的全稱,版本號以及報告BUG時需要用的郵箱地址  
  9. #  
  10. AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)  
  11. #  
  12. # 用來偵測所指定的源碼文件是否存在,來確定源碼目錄的有效性  
  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. # 創建輸出文件。在`configure.in'的末尾調用本宏一次。  
  26. #  
  27. AC_OUTPUT  
  28.  

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

修改后的結果:

  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]) 


第四步:運行 aclocal,

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

  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]#  

第五步:運行 autoconf, 目的是生成 configure 此時的狀態是:

  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]#  

第六步:運行 autoheader,它負責生成config.h.in文件。

該工具通常會從“acconfig.h”文件中復制用戶附加的符號定義,因此此處沒有附加符號定義,所以不需要創建“acconfig.h”文件。此時的狀態是:

  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]#  

第七步:下面即將運行 automake, 但在此之前應該做一下準備工作!

首先創建一個 Linux Makefile.am.這一步是創建Linux Makefile很重要的一步,automake要用的腳本配置文件是Linux Makefile.am,用戶需要自己創建相應的文件。之后,automake工具轉換成Linux Makefile.in。

這個Linux Makefile.am的內容如下:

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

下面對該腳本文件的對應項進行解釋。其中的AUTOMAKE_OPTIONS為設置automake的選項。由于GNU(在第1章中已經有所介紹)對自己發布的軟件有嚴格的規范,比如必須附帶許可證聲明文件COPYING等,否則automake執行時會報錯。

automake提供了三種軟件等級:foreign、gnu和gnits,讓用戶選擇采用,默認等級為gnu。在本例使用foreign等級,它只檢測必須的文件。定義要產生的執行文件名。如果要產生多個執行文件,每個文件名用空格隔開。

main_SOURCES定義“main”這個執行程序所需要的原始文件。如果”main”這個程序是由多個原始文件所產生的,則必須把它所用到的所有原始文件都列出來,并用空格隔開。例如:若目標體“main”需要“main.c”、“sunq.c”、“main.h”三個依賴文件,則定義main_SOURCES=main.c sunq.c main.h。要注意的是,如果要定義多個執行文件,則對每個執行程序都要定義相應的file_SOURCES。

其次使用automake對其生成“configure.in”文件,在這里使用選項“—adding-missing”可以讓automake自動添加有一些必需的腳本文件。
運行后的狀態是:

  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第八步運行configure,

在這一步中,通過運行自動配置設置文件configure,把Makefile.in變成了最終的Makefile。運行的結果如下:

  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第九步運行 make,

對配置文件Makefile進行測試一下此時的狀態如下:

  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第十步運行生成的文件 main:

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

至此,所有的步驟完成了,為了理解并做好這個實驗,我花費了兩天的時間了!!能夠看到最終的成果,這是最讓人開心的!!贊自己一下!

【編輯推薦】

  1. Linux Makefile編譯使用的環境從helloworld入手
  2. Linux Makefile系統的真相符合自由軟件慣例
  3. Linux Makefile介紹自動編譯和鏈接
  4. Linux Makefile自動編譯和鏈接使用的環境
  5. Linux Makefile介紹使用的環境深入淺出
責任編輯:佚名 來源: CSDN
相關推薦

2010-06-22 17:28:35

Linux Autom

2010-03-01 16:40:40

Linux Makef

2010-02-25 15:11:48

Linux Makef

2010-02-24 16:01:39

Linux Makef

2017-09-12 09:22:51

LinuxMakefileautoconf工具

2009-10-26 13:45:39

linux Makef

2010-06-22 15:40:54

Autoconf使用

2009-10-26 11:34:42

linux makef

2009-12-14 10:47:34

Linux makef

2009-10-27 17:58:12

linux make命

2019-10-14 09:14:37

Linuxbash命令

2010-06-22 17:09:52

Linux Autom

2010-02-26 10:47:30

Linux Makef

2020-08-11 18:20:42

Linux運行腳本開機啟動

2020-06-11 07:57:48

Linux腳本數據

2010-02-24 14:55:35

Linux Makef

2023-07-31 17:29:21

Docker鴻蒙

2022-05-12 12:55:28

容器Kubernetes運行容器

2023-03-02 23:45:23

linux開機啟動Windows

2011-03-09 10:25:25

Linux安裝LAMP
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 亚洲在线一区 | 欧美精品a∨在线观看不卡 国产精品久久国产精品 | 中文字幕1区2区3区 日韩在线视频免费观看 | 国产免费一区二区三区 | 欧美在线色 | 国产一区二区在线视频 | 一级黄色录像片子 | 人人插人人 | 久久久黄色 | 亚洲一区二区精品 | 97久久精品午夜一区二区 | 五月激情婷婷网 | 久久久久久久久国产 | 欧美久久国产 | 亚洲综合无码一区二区 | 特黄一级 | 黄色精品 | 免费麻豆视频 | av免费在线观看网站 | 91嫩草精品 | 国产欧美日韩在线观看 | 婷婷免费视频 | www国产亚洲精品 | 久久精品国产亚洲一区二区三区 | 亚洲综合久久精品 | 日韩一区在线播放 | 日日噜噜夜夜爽爽狠狠 | 精品日本久久久久久久久久 | 欧美午夜一区二区三区免费大片 | 日韩午夜一区二区三区 | 国产真实精品久久二三区 | a级片在线观看 | 欧美另类视频在线 | 麻豆a级片 | 一区二区三区亚洲 | 成人午夜精品 | 99热这里都是精品 | 九九热免费视频在线观看 | 日韩中文一区二区三区 | 免费黄色在线观看 | 国产精品视频一区二区三区四蜜臂 |