• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
  • Linux 環境下 Makefile 文件制作淺談(一)

    發表于:2007-05-26來源:作者:點擊數: 標簽:
    get from bleaf.chinablog.com EMAIL:leaf_zhou_8@hotmail.com 無論對于一個初學者還是一個資深的Linux 程序員 ,編寫Makefile文件都是一件很麻煩的事;再者, 開發 人員應該把主要的精力放在程序代碼的編寫上,而在Makefile文件花費太多的精力顯然是不明智
    get from bleaf.chinablog.com            EMAIL:leaf_zhou_8@hotmail.com

    無論對于一個初學者還是一個資深的Linux程序員,編寫Makefile文件都是一件很麻煩的事;再者,開發人員應該把主要的精力放在程序代碼的編寫上,而在Makefile文件花費太多的精力顯然是不明智的;還有,對于不同的處理器架構,往往編譯器不同,環境不同,特別是一些嵌入式系統中的各種程序的編譯,于是移植問題也使Makefile文件編寫趨于復雜,也顯得這個問題很重要。對于這些問題Linux的高手們早已想到了,所以他們開發了一些能夠自動生成Makefile文件的工具。他們就是下面這些工具:

    〉GNU Automake
    〉GNU Autoconf
    〉GNU m4
    〉perl
    〉GNU Libtool
    因此您的操作系統必須安裝以上軟件,否則就不能夠自動生成Makefile文件或者在生成的過程中出現各種各樣的問題。用autoconf/automake/autoheader工具來處理各種移植性的問題,用這些工具完成系統配置信息的收集,制作Makefile文件。然后在打算編譯源碼時只需要通過 "./configure; make"這樣簡單的命令就可以得到干凈利落的編譯。

    制作Makefile文件需要以下幾步:
    1〉建立編譯目錄和源代碼目錄及源代碼文件(即要編譯的源文件)
    [root@localhost leaf]#mkdir testmk
    [root@localhost leaf]#cd testmk
    [root@localhost testmk]#vi hello.c
    編輯hello.c文件如下內容:
    /*filename:hello.c*/
    #include

    int main(int argc,char **argv)
    {
    printf("%s\n","Hello, World!")
    return 0;
    }
    2〉利用autoscan工具產生一個configure.in文件的模板文件configure.scan文件:
    [root@localhost testmk]#autoscan
    [root@localhost testmk]#ls
    configure.scan hello.c
    3〉把configure.scan文件更名為configure.in文件,并編譯其內容如下:
    [root@localhost testmk]#mv configure.scan configure.in
    [root@localhost testmk]#vi configure.in
    dnl Process this file with autoconf to produce a configure script.
    AC_INIT(hello.c)

    dnl Add the file by leaf
    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 characteristics.

    dnl Checks for library functions.

    AC_OUTPUT(Makefile)

    4〉執行aclocal,會產生aclocal.m4文件
    [root@localhost testmk]#aclocal
    [root@localhost testmk]#ls
    aclocal.m4 configure.in hello.c
    5〉執行autoconf,會產生confiure文件
    [root@localhost testmk]#autoconf
    [root@localhost testmk]#ls
    aclocal.m4 [autom4te.cache] configure configure.in hello.c
    6〉創建文件Makefile.am并編輯其內容如下:
    AUTOMAKE_OPTIONS=foreign
    bin_PROGRAMS=hello
    hello_SOURCES=hello.c
    其中,hello為編譯后產生的可執行文件名稱,而第三行等號后面為源文件列表
    7〉執行automake程序,automake程序會根據Makefile.am產生一些文件,其中最重要的是Makefile.in文件:
    [root@localhost testmk]#automake --add-missing
    configure.in: installing `./install-sh'
    configure.in: installing `./mkinstalldirs'
    configure.in: installing `./missing'
    Makefile.am: installing `./depcomp'
    [root@localhost testmk]#ls
    aclocal.m4 [autom4te.cache] configure configure.in depcomp
    hello.c install-sh Makefile.am Makefile.in missing
    mkinstalldirs
    8〉執行configure腳本,生成我們需要的Makefile文件。
    [root@localhost testmk]#./configure
    checking for a BSD-compatible install... /usr/bin/install -c
    checking whether build environment is sane... yes
    checking for gawk... gawk
    checking whether make sets $(MAKE)... yes
    checking for gcc... gcc
    checking for C compiler default output... a.out
    checking whether the C compiler works... yes
    checking whether we are cross compiling... no
    checking for suffix of executables...
    checking for suffix of object files... o
    checking whether we are using the GNU C compiler... yes
    checking whether gcc accepts -g... yes
    checking for gcc option to accept ANSI C... none needed
    checking for style of include used by make... GNU
    checking dependency style of gcc... gcc3
    configure: creating ./config.status
    config.status: creating Makefile
    config.status: executing depfiles commands
    9〉最后只執行make就大功告成了:
    [root@localhost testmk]#make
    source='hello.c' object='hello.o' libtool=no \
    depfile='.deps/hello.Po' tmpdepfile='.deps/hello.TPo' \
    depmode=gcc3 /bin/sh ./depcomp \
    gcc -DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\" -DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE=\"hello\" -DVERSION=\"1.0\" -I. -I. -g -O2 -c `test -f 'hello.c' || echo './'`hello.c
    gcc -g -O2 -o hello hello.o

    備注:
    1.以上內容均在RedHat Linux 9.0環境下測試通過。
    2.參考書目《Linux 程序設計權威指南》于明儉、陳向陽、方漢編著
    3.其它國內外網站資料
    4.RedHat 9.0下帶的程序文件及版本
    autoconf-2.57-3.noarch.rpm
    automake-1.6.3-5.noarch.rpm
    gcc-3.2.2-5.i386.rpm

    原文轉自:http://www.kjueaiud.com

    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>