<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設計應用 > Linux下automake軟件編譯與發(fā)布快速入門

          Linux下automake軟件編譯與發(fā)布快速入門

          作者: 時間:2016-10-08 來源:網(wǎng)絡 收藏

          本例假設要產(chǎn)生一個simserver1的軟件包,源文件只有1個,simserver1.cpp。使用了pthread庫。

          本文引用地址:http://www.ex-cimer.com/article/201610/305726.htm

          1.運行autoscan掃描源碼目錄

          執(zhí)行

          $autoscan

          執(zhí)行后生成configure.scan。

          2.編輯configure.in文件

          步驟1執(zhí)行后生成了configure.scan,本步驟需要復制一份該文件并命名為configure.in,然后編輯該文件。

          命令如下:

          $cp configure.scan configure.in

          $vim configure.in

          用vim編輯器打開后,文件原內(nèi)容如下:

          configure.scan開始

          # -*- Autoconf -*-

          # Process this file with autoconf to produce a configure script.

          AC_PREREQ(2.61)

          AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)

          AC_CONFIG_SRCDIR([simserver1.cpp])

          AC_CONFIG_HEADER([config.h])

          # Checks for programs.

          AC_PROG_CXX

          # Checks for libraries.

          # FIXME: Replace `main' with a function in `-lpthread':

          AC_CHECK_LIB([pthread], [main])

          # Checks for header files.

          AC_CHECK_HEADERS([arpa/inet.h netinet/in.h sys/socket.h])

          # Checks for typedefs, structures, and compiler characteristics.

          # Checks for library functions.

          AC_HEADER_STDC

          AC_CHECK_FUNCS([bzero inet_ntoa socket])

          AC_CONFIG_FILES([Makefile])

          AC_OUTPUT

          configure.scan結束

          編輯修改成如下內(nèi)容:

          configure.in開始

          # -*- Autoconf -*-

          # Process this file with autoconf to produce a configure script.

          AC_INIT(simserver1.cpp) #這個宏用來檢查源代碼所在的路徑,放在文件開頭

          AM_INIT_AUTOMAKE(simserver1,1.0)   #描述軟件包名稱及版本號

          # Checks for programs.

          AC_PROG_CXX #使用C++

          # Checks for libraries.

          # Checks for header files.

          AC_CHECK_HEADERS([arpa/inet.h netinet/in.h sys/socket.h])

          # Checks for typedefs, structures, and compiler characteristics.

          # Checks for library functions.

          AC_HEADER_STDC

          AC_CHECK_FUNCS([bzero inet_ntoa socket])

          AC_OUTPUT(Makefile) #這個宏是我們要輸出的Makefile的名字

          configure.in結束

          3.運行aclocal生成aclocal.m4文件

          configure.in文件編輯保存完后,用aclocal命令生成aclocal.m4文件。

          執(zhí)行以下命令:

          $aclocal

          然后用ls列出生成的文件。如果沒有找到aclocal.m4文件,那一般是configure.in文件不對,修改后再重試。

          4.運行autoconf生成configure文件

          用autoconf命令來生成configure可執(zhí)行文件。

          執(zhí)行以下命令:

          $autoconf

          然后用ls檢查configure是否已經(jīng)成功生成。

          5.建立Makefile.am文件

          Makefile.am是用來生成Makefile.in的,需要你手工書寫。Makefile.am中定義了一些內(nèi)容:

          AUTOMAKE_OPTIONS

          這個是automake的選項。在執(zhí)行automake時,它會檢查目錄下是否存在標準GNU軟件包中應具備的各種文件,例如AUTHORS、ChangeLog、NEWS等文件。我們將其設置成foreign時,automake會改用一般軟件包的標準來檢查。

          bin_PROGRAMS

          這個是指定我們所要產(chǎn)生的可執(zhí)行文件的文件名。如果你要產(chǎn)生多個可執(zhí)行文件,那么在各個名字間用空格隔開。

          helloworld_SOURCES

          這個是指定產(chǎn)生“helloworld”時所需要的源代碼。如果它用到了多個源文件,那么請使用空格符號將它們隔開。比如需要 helloworld.h,helloworld.c那么請寫成helloworld_SOURCES= helloworld.h helloworld.c。

          如果你在bin_PROGRAMS定義了多個可執(zhí)行文件,則對應每個可執(zhí)行文件都要定義相對的filename_SOURCES。

          LIBS

          這個用來指定鏈接的程序庫。如LIBS += -lpthread,指定鏈接pthread庫。

          執(zhí)行命令:

          $vim Makefilemam

          進入編輯界面,輸入內(nèi)容如下:

          AUTOMAKE_OPTIONS=foreign

          bin_PROGRAMS=simserver1 #軟件包名稱

          simserver1_SOURCES=simserver1.cpp  #源文件列表,如果有多個則用空格分開

          LIBS += -lpthread #鏈接pthread庫

          6.運行automake

          執(zhí)行automake --add-missing來產(chǎn)生Makefile.in。

          $automake --add-missing

          執(zhí)行后應該生成Makefile.in文件.

          7.運行configure生成Makefile

          執(zhí)行:

          $./configure

          8.執(zhí)行make生成可執(zhí)行文件

          $make

          執(zhí)行后應該編譯輸出simserver1可執(zhí)行文件.

          make還有以下幾個命令:

          make install可以將simserver1安裝到/usr/local/bin目錄下;

          make clean可清除上次編譯結果

          make dist可將代碼打包成packagename-ver.tar.gz文件

          make distcheck用來檢查打包的軟件包是否正常。



          關鍵詞:

          評論


          相關推薦

          技術專區(qū)

          關閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();