• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            面對(duì)現(xiàn)實(shí),超越自己
            逆水行舟,不進(jìn)則退
            posts - 269,comments - 32,trackbacks - 0
            為了編譯一個(gè)簡(jiǎn)單的源文件main.c,需要自動(dòng)生成一個(gè)makefile,以下是步驟:

            第一步:
            ----------
            在/root/project/main目錄下創(chuàng)建一個(gè)文件main.c,其內(nèi)容如下:
            ------------------------------------------------
            #include <stdio.h>
            int main(int argc, char** argv)
            {
                printf("Hello, Auto Makefile!\n");
                return 0;
            }
            ------------------------------------------------

            此時(shí)狀態(tài)如下:
            [root@localhost main]# pwd
            /root/project/main
            [root@localhost main]# ls
            main.c
            [root@localhost main]#

            第二步:
            ----------
            運(yùn)行 autoscan , 自動(dòng)創(chuàng)建兩個(gè)文件: autoscan.log configure.scan

            此時(shí)狀態(tài)如下:
            [root@localhost main]# autoscan
            [root@localhost main]# ls
            autoscan.log configure.scan main.c
            [root@localhost main]#

            第三步:
            ----------
            修改configure.scan的文件名為configure.in

            查看configure.in的內(nèi)容:
            ------------------------------------------------
            #                                               -*- 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([main.c])
            AC_CONFIG_HEADER([config.h])

            # Checks for programs.
            AC_PROG_CC

            # Checks for libraries.

            # Checks for header files.

            # Checks for typedefs, structures, and compiler characteristics.

            # Checks for library functions.

            AC_OUTPUT
            ------------------------------------------------

            解讀以上的文件:

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

            # AC_PREREQ:
            # 確保使用的是足夠新的Autoconf版本。如果用于創(chuàng)建configure的Autoconf的版
            # 本比version 要早,就在標(biāo)準(zhǔn)錯(cuò)誤輸出打印一條錯(cuò)誤消息并不會(huì)創(chuàng)建configure。
            AC_PREREQ(2.61)

            #
            # 初始化,定義軟件的基本信息,包括設(shè)置包的全稱,版本號(hào)以及報(bào)告BUG時(shí)需要用的郵箱地址
            #
            AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)

            #
            # 用來(lái)偵測(cè)所指定的源碼文件是否存在,來(lái)確定源碼目錄的有效性
            #
            AC_CONFIG_SRCDIR([main.c])

            #
            # 用于生成config.h文件,以便autoheader使用
            #
            AC_CONFIG_HEADER([config.h])

            # Checks for programs.
            AC_PROG_CC

            # Checks for libraries.

            # Checks for header files.

            # Checks for typedefs, structures, and compiler characteristics.

            # Checks for library functions.

            #
            # 創(chuàng)建輸出文件。在`configure.in'的末尾調(diào)用本宏一次。
            #
            AC_OUTPUT
            ------------------------------------------------

            修改動(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后添加輸出文件Makefile


            修改后的結(jié)果:
            ------------------------------------------------
            #                                               -*- Autoconf -*-
            # Process this file with autoconf to produce a configure script.

            AC_PREREQ(2.61)
            AC_INIT(main, 1.0, pgpxc@163.com)
            AC_CONFIG_SRCDIR([main.c])
            AC_CONFIG_HEADER([config.h])
            AM_INIT_AUTOMAKE(main,1.0)

            # Checks for programs.
            AC_PROG_CC

            # Checks for libraries.

            # Checks for header files.

            # Checks for typedefs, structures, and compiler characteristics.

            # Checks for library functions.

            AC_OUTPUT([Makefile])
            ------------------------------------------------

            第四步:
            運(yùn)行 aclocal, 生成一個(gè)“aclocal.m4”文件和一個(gè)緩沖文件夾autom4te.cache,該文件主要處理本地的宏定義。

            此時(shí)的狀態(tài)是:
            [root@localhost main]# aclocal
            [root@localhost main]# ls
            aclocal.m4 autom4te.cache autoscan.log configure.in configure.in~ main.c
            [root@localhost main]#


            第五步:
            運(yùn)行 autoconf, 目的是生成 configure

            此時(shí)的狀態(tài)是:
            [root@localhost main]# autoconf
            [root@localhost main]# ls
            aclocal.m4      autoscan.log configure.in   main.c
            autom4te.cache configure     configure.in~
            [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)是:
            [root@localhost main]# autoheader
            [root@localhost main]# ls
            aclocal.m4      autoscan.log configure     configure.in~
            autom4te.cache config.h.in   configure.in main.c
            [root@localhost main]#

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

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

            這個(gè)Makefile.am的內(nèi)容如下:
            ------------------------------------------------
            AUTOMAKE_OPTIONS=foreign
            bin_PROGRAMS=main
            main_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è)必須的文件。
                bin_PROGRAMS定義要產(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)是:
            ------------------------------------------------
            [root@localhost main]# automake --add-missing
            configure.in:8: installing `./missing'
            configure.in:8: installing `./install-sh'
            Makefile.am: installing `./depcomp'
            [root@localhost main]# ls
            aclocal.m4      config.h.in   configure.in~ main.c        Makefile.in
            autom4te.cache configure     depcomp        Makefile.am missing
            autoscan.log    configure.in install-sh     Makefile.am~
            [root@localhost main]#
            ------------------------------------------------

            第八步
            運(yùn)行configure,在這一步中,通過(guò)運(yùn)行自動(dòng)配置設(shè)置文件configure,把Makefile.in變成了最終的Makefile。
            運(yùn)行的結(jié)果如下:
            ------------------------------------------------
            [root@localhost main]# ./configure
            checking for a BSD-compatible install... /usr/bin/install -c
            checking whether build environment is sane... yes
            checking for a thread-safe mkdir -p... /bin/mkdir -p
            checking for gawk... gawk
            checking whether make sets $(MAKE)... yes
            checking for gcc... gcc
            checking for C compiler default output file name... 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 ISO C89... 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: creating config.h
            config.status: executing depfiles commands
            [root@localhost main]# ls
            aclocal.m4      config.h.in    configure.in   main.c        Makefile.in
            autom4te.cache config.log     configure.in~ Makefile      missing
            autoscan.log    config.status depcomp        Makefile.am   stamp-h1
            config.h        configure      install-sh     Makefile.am~
            [root@localhost main]#
            ------------------------------------------------

            第九步
            運(yùn)行 make,對(duì)配置文件Makefile進(jìn)行測(cè)試一下

            此時(shí)的狀態(tài)如下:
            ------------------------------------------------
            [root@localhost main]# make
            cd . && /bin/sh /root/project/main/missing --run aclocal-1.10
            cd . && /bin/sh /root/project/main/missing --run automake-1.10 --foreign
            cd . && /bin/sh /root/project/main/missing --run autoconf
            /bin/sh ./config.status --recheck
            running CONFIG_SHELL=/bin/sh /bin/sh ./configure   --no-create --no-recursion
            checking for a BSD-compatible install... /usr/bin/install -c
            checking whether build environment is sane... yes
            checking for a thread-safe mkdir -p... /bin/mkdir -p
            checking for gawk... gawk
            checking whether make sets $(MAKE)... yes
            checking for gcc... gcc
            checking for C compiler default output file name... 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 ISO C89... none needed
            checking for style of include used by make... GNU
            checking dependency style of gcc... gcc3
            configure: creating ./config.status
            /bin/sh ./config.status
            config.status: creating Makefile
            config.status: creating config.h
            config.status: config.h is unchanged
            config.status: executing depfiles commands
            cd . && /bin/sh /root/project/main/missing --run autoheader
            rm -f stamp-h1
            touch config.h.in
            make all-am
            make[1]: Entering directory `/root/project/main'
            gcc -DHAVE_CONFIG_H -I.     -g -O2 -MT main.o -MD -MP -MF .deps/main.Tpo -c -o main.o main.c
            mv -f .deps/main.Tpo .deps/main.Po
            gcc -g -O2   -o main main.o
            cd . && /bin/sh ./config.status config.h
            config.status: creating config.h
            config.status: config.h is unchanged
            make[1]: Leaving directory `/root/project/main'
            [root@localhost main]# ls
            aclocal.m4      autoscan.log config.h.in config.status configure.in   depcomp     main    main.o    Makefile.am   Makefile.in stamp-h1
            autom4te.cache config.h      config.log   configure      configure.in~ install-sh main.c Makefile Makefile.am~ missing
            [root@localhost main]#
            ------------------------------------------------

            第十步
            運(yùn)行生成的文件 main:
            ------------------------------------------------
            [root@localhost main]# ./main
            Hello, Auto Makefile!
            [root@localhost main]#
            ------------------------------------------------



            我用的是ubuntu
            以上就是全文了.但有一處要改:用aclocal
            全報(bào)有一個(gè)m4文件有錯(cuò).找到報(bào)錯(cuò)的那一行.把變量加個(gè)中括號(hào)就可以了.

            下面來(lái)分別解釋一下上面的文件和命令:
                autoscan :           用來(lái)掃描源代碼的目錄生成configure.scan,如果不指定掃描目錄,則他會(huì)掃描當(dāng)前工作目錄,
                configure.scan : 包含了系統(tǒng)配置的基本選項(xiàng),一般用來(lái)制作configure.in文件。
                configure.in :      該文件的內(nèi)容都是一些宏,其中的順序沒(méi)有硬性的規(guī)定,不過(guò)建議的順序是:
                                AC_INIT
                                    測(cè)試程序
                                    測(cè)試函數(shù)
                                    測(cè)試頭文件
                                    測(cè)試類型定義
                                    測(cè)試結(jié)構(gòu)
                                    測(cè)試編譯器
                                    測(cè)試庫(kù)函數(shù)
                                    測(cè)試系統(tǒng)調(diào)用
                                AC_OUTPOUT
                                更詳細(xì)的請(qǐng)參閱《GNU/Linux編程指南(第二版)》

                aclocal:             根據(jù)configure.in的內(nèi)容自動(dòng)生成aclocal.m4文件,其定義為:alocal : creat alocal.m4 by scanning configure.ac
                alocal.m4 :          在執(zhí)行automake的時(shí)候還需要其他的一些宏,這就由alocal產(chǎn)生。當(dāng)有了 configure.in和alocal.m4兩個(gè)宏文件后,就可以用automake來(lái)產(chǎn)生Makefile.in文件了。
                autoconf:          用來(lái)產(chǎn)生configure腳本程序。
                configure:         他能根據(jù)不同的系統(tǒng),產(chǎn)生不同的Makefile,從而是我們的程序具有可移植性。他還有一些參數(shù):
                                --cache-file=FILE                                            測(cè)試系統(tǒng)的特性,并將結(jié)果放到FILE中

                                --help                                                               輸出幫助信息

                                --no-create                                                      阻止其生成輸出文件

                                --quiet                                                               執(zhí)行是不做輸出

                                --silent                                                              同上,若設(shè)置則不會(huì)有任何輸出到屏幕

                                --version                                                          輸出automake的版本號(hào)

                                --prefix=PEWFIX                                             安裝位置設(shè)置(常用)

                                --exec-prefix=EPREFIX                                  設(shè)置結(jié)構(gòu)倚賴的文件的安裝位置

                                --bindir=DIR                                                指定可執(zhí)行文件的安裝位置.

                                --sbindir=DIR                                                    指定超級(jí)用戶可執(zhí)行的安裝位置.

                                --libexecdir=DIR                                              指定可執(zhí)行支持文件的安裝位置.
                                --datadir=DIR                                              指定通用數(shù)據(jù)文件的安裝位置.

                                --sysconfdir=DIR                                        指定只讀數(shù)據(jù)的安裝位置.

                                --sharedstatedir=DIR                                   指定共享的可寫數(shù)據(jù)的安裝位置.

                                --localstatedir=DIR                                     指定(非共享)可寫數(shù)據(jù)的安裝位置.

                                --libdir=DIR                                                 指定庫(kù)文件的安裝位置.

                                --includedir=DIR                                         指定C頭文件的安裝位置.

                                --oldincludedir=DIR                                   指定為除GCC外編譯器安裝的C頭文件的安裝位置.

                                --infodir=DIR                                               指定Info格式文檔的安裝位置.

                                --mandir=DIR                                               指定手冊(cè)頁(yè)的安裝位置.

                                --srcdir=DIR                                                源碼的位置

                                --program-prefix=PREFIX                         增加安裝程序名字前綴.

                                --program-suffix=SUFFIX                          增加安裝程序名字后綴.

                                --program-transform-name=PROGRAM  產(chǎn)生安裝名

                                --build=BUILD                                              指定軟件包安裝的系統(tǒng)平臺(tái).

                                --host=HOST                                                指定軟件運(yùn)行的系統(tǒng)平臺(tái).
                                --target=GARGET                                        指定軟件面向的系統(tǒng)平臺(tái)

                                --disable-FEATURE                                     提供為大型選項(xiàng)的編譯時(shí)配置

                                --enable-FEATURE[=ARG]                           提供了一些默認(rèn)被禁止的特性

                                --enable-FEATURE=no                                     同--disable-FEATURE

                                --with-PACKAGE[=ARG]                              使用已有軟件包和庫(kù)
                                --with-PACKAGE=no                                         --without-PACKAGE同義

                                --without-PACKAGE                                    禁止軟件包與系統(tǒng)已有的軟件包交互

                                --x-includes=DIR                                         --with-PACKAGE的一個(gè)特例

                                --x-libraries=DIR                                        向configure腳本指明包含X11庫(kù)的目錄
                makefile.am :      根據(jù)他生成makefile.in文件。
                                AUTOMAKE_OPTIONS = foreign                         設(shè)置automake的選項(xiàng),設(shè)置成foreign表示按一般軟件處理。
                                bin_PROGRAMS = filename1 [...]       產(chǎn)生的可執(zhí)行文件名
                                filename1_SOURCES = f1.c f2.c                       指明生成filename可執(zhí)行文件的源碼                            
                                [...]
                                filename_LDADD =
                                filename_LDFLAGS =
                                filename_DEPENDENCIES =
                                靜態(tài)庫(kù)lib_LIBRARIES = libfilename.a
                                filename_a_SOURCES =
                                filename_a_LDADD =
                                filename_a_LIBADD =
                                filename_a_LDFALGS =
                                頭文件include_HEADERS = filename.h
                                數(shù)據(jù)文件data_DATA = data1 data2
                                (對(duì)于可執(zhí)行文件和靜態(tài)庫(kù)類型如果只想編譯,不想安裝到系統(tǒng)中,可以用:noinst_PROGRAMS代替bin_PROGRAMS
                                和noinst_LIBRARIES代替lib_LIBRARIES)
                automake :          使用automake --add-missing來(lái)生成Makefile.in文件,后面的選項(xiàng)使我們制作出來(lái)的Makfile符合GNU的習(xí)慣,
                Makefile :             GNU的習(xí)慣:
                                make                     編譯,連接,生成可執(zhí)行文件;
                                make clean          清除編譯產(chǎn)生的obj文件,以及可執(zhí)行文件;
                                make install         安裝到系統(tǒng)中,一般是/usr/local/bin
                                make dist             將源碼打包,以便發(fā)布
                                make diskcheck 生成包,并對(duì)其進(jìn)行檢查,以確保其正確性;

            以上相關(guān)鏈接:http://www.cnblogs.com/Safe3/archive/2009/02/10/1387460.html
                                http://blog.csdn.net/hadesgin/article/details/6704371


             

            posted on 2012-11-08 15:37 王海光 閱讀(1489) 評(píng)論(0)  編輯 收藏 引用 所屬分類: Linux
            国产精品视频久久| 精品乱码久久久久久夜夜嗨 | 久久久久这里只有精品 | 伊人热人久久中文字幕| 久久人人爽人人澡人人高潮AV| 久久精品国产99久久久古代 | 久久亚洲欧洲国产综合| 久久青青草原亚洲av无码app | 久久人人爽人人人人爽AV| 国产精品久久久久影视不卡| 香港aa三级久久三级老师2021国产三级精品三级在 | 无码精品久久久天天影视| AAA级久久久精品无码区| 亚洲狠狠婷婷综合久久蜜芽| 久久精品亚洲精品国产欧美| 亚洲AV无一区二区三区久久| 久久综合狠狠综合久久97色| 久久成人国产精品二三区| 无码精品久久久久久人妻中字| 久久人人爽人人澡人人高潮AV| 免费国产99久久久香蕉| 久久久久亚洲AV片无码下载蜜桃 | 亚洲精品白浆高清久久久久久| 国产精品99久久久久久宅男| 久久久国产乱子伦精品作者| 久久久久青草线蕉综合超碰| 亚洲午夜无码久久久久小说| 久久乐国产精品亚洲综合| 一级做a爰片久久毛片16| 久久精品国产99国产精品澳门| 亚洲国产精品无码久久久不卡| 久久久亚洲欧洲日产国码是AV| 性高湖久久久久久久久AAAAA| 久久国产精品免费| 久久露脸国产精品| 日韩电影久久久被窝网| 久久久无码精品午夜| 四虎久久影院| 亚洲精品无码久久久久| 久久这里只有精品18| 精品久久久久中文字幕日本|