linux下的Makefile的自動產生

來源:互聯網
上載者:User

 初學linux,看到linux程式的install有./configure,make,make install等命令感到奇怪便找了
 一些文章看.
   GNU autoconf和GNU automake是GNU用來協助自動產生makefile文檔的,能方便地安裝你開發的軟體
   
   make根據makefile編譯、連接程式,手寫makefile很困難因此有了autoconf,automake.

 

 請先確認你的系統已經安裝以下的軟體
 1.GNU Automake
 2.GNU Autoconf
 3.GNU m4
 4.perl
 5.GNU Libtool(如果你需要產生sharedlibrary)

 假設有一個hello.c檔案 在該檔案的目錄下

 a ./autoscan 產生 configure.scan 檔案

 b 編輯configure.scan為configure.in

 configure.in檔的內容是一連串GNU m4的巨集
 dnl Process this file with autoconf to produce  a con figure script.  //dnl是一個註解標誌
 AC_INIT(hello.c) // 用來檢查原碼路徑
 AM_INIT_AUTOMAKE(hello, 1.0) //產生軟體的名稱和版本
 dnl Checks for programs.  
 AC_PROG_CC  //檢查編譯器
 dnl Checks for libraries.  
 dnl Checks for header files. 
 dnl Checks for typedefs,structures,and compiler ch aracteristics.  
 dnl Checks for library functions.  
 AC_OUTPUT(Makefile) //configure產生的檔案

 c 執行aclocal,autoconf 產生  aclocal.m4 configure configure.in
 aclocal產生的aclocal.m4是一個巨集同configure.in供autoconf使用
 Autoconf會讀取configure.in檔然後產生''configure''這個 shell script
 ''configure''他使程式能在各種LINUX平台產生合適的Makefile或是C的頭文
 件(header file),讓原程式可以很方便地在這些不同的平台上被編 譯出來。

 d 編輯Makefile.am

 AUTOMAKE_OPTIONS=foreign//必須
 bin_PROGRAMS=hello//
 hello_SOURCES=hello.c//指定原檔案hello_SOURCES=hello.c main.c hello.h,
                         filename_SOURCES
 e automake - -add-missing automake根據makefile.am產生makefile.in

 - -add-missing選項是告訴automake順便幫我們加 入封裝一個軟體套件所必備的檔案

 f 執行./configure 產生makefile檔案然後使用 make編譯hello.c為執行文 。

 注意:Automake只需用到一些已經定義好的巨集(am),我們把巨集及目標(target)寫在Makefile.am檔內,Automake讀入Makefile.am檔後會把這一串已經定義好的巨集展開並且產生對應的Ma
 kefile.in檔,然後再由configure這個shellscript根據Makefile.in產生適合的Makefile。

 d 使用makefile
 make all 編譯器可寫為make
 make clean,make disclean,
 make install 程式會被安裝至/usr/local/bin這個目錄
 make dist 執行完在目錄下會產生一個以PACKAGE-VERSION.tar.gz為名稱的檔案
 make distcheck  比前一個多了檢查相關套件

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.