• <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>

            不會飛的鳥

            2010年12月10日 ... 不鳥他們?。?! 我要用自己開發(fā)的分布式文件系統(tǒng)、分布式調(diào)度系統(tǒng)、分布式檢索系統(tǒng), 做自己的搜索引擎!?。〈篝~有大志?。。?---楊書童

            linux c 一個autotools的最簡單例子

              1、準備:
                 

               需要工具autoscan aclocal autoheader automake autoconf make 等工具.


              2、測試程序編寫:
                 


                  建立目錄:mkdir include src
                 
                  編寫程序:include/str.h
                  
            #include <stdio.h>

            int str(char *string);

                  編寫程序:src/str.c
                  
            #include "str.h"
            //print string
            int str(char *string){
                    printf(
            "\n----PRINT STRING----\n\"%s\"\n",string);
                    
            return 0;
            }


            //interface of this program
            int main(int argc , char **argv){
                    
            char str_read[1024];
                    printf(
            "Please INPUT something end by [ENTER]\n");
                    scanf(
            "%s",str_read);
                    
            return str(str_read );
            }


            3、生成configure.in
               

            configure.in是automake的輸入文件,所以必須先生成該文件。
                執(zhí)行命令:
            [root@localhost str]# ls
            include  src
            [root
            @localhost str]# autoscan
            autom4te: configure.ac: no such file or directory
            autoscan
            : /usr/bin/autom4te failed with exit status: 1
            [root
            @localhost str]# ls
            autoscan.log  configure.scan  include  src
            [root
            @localhost str]# cp configure.scan configure.in 

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


            AC_PREREQ(
            2.59)
            AC_INIT(FULL
            -PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)
            AC_CONFIG_SRCDIR([include
            /str.h])
            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

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

            AC_INIT(str,0.0.1, [bug@sounos.org])

            FULL-PACKAGE-NAME 為程序名稱,VERSION為當前版本, BUG-REPORT-ADDRESS為bug匯報地址
                添加AM_INIT_AUTOMAKE
                添加AC_CONFIG_FILES([Makefile])
            #                                               -*- Autoconf -*-
            # Process this file with autoconf to produce a configure script.


            AC_PREREQ(
            2.59)
            #AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)
            AC_INIT(str, 0.0.1, [bug@sounos.org])
            AM_INIT_AUTOMAKE
            AC_CONFIG_SRCDIR([include
            /str.h])
            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_CONFIG_FILES([Makefile])
            AC_OUTPUT

            4、執(zhí)行aclocal

            [root@localhost str]# aclocal
            /usr/share/aclocal/libfame.m4:6: warning: underquoted definition of AM_PATH_LIBFAME
              run info 
            '(automake)Extending aclocal'
              or see http
            ://sources.redhat.com/automake/automake.html#Extending-aclocal

            5、制作Makefile.am


            [root@localhost str]# cat Makefile.am
            #Makefile.am

            bin_PROGRAMS    = str
            str_SOURCES     
            = include/str.h src/str.c
            str_CPPFLAGS    
            = -I include/

            6、autoheader

            [root@localhost str]# autoheader

            7、automake必須文件:


                *  install-sh
                
            * missing
                
            * INSTALL
                
            * NEWS
                
            * README
                
            * AUTHORS
                
            * ChangeLog
                
            * COPYING
                
            * depcomp 
            其中
                * install-sh
                
            * missing
                
            * INSTALL
                
            * COPYING
                
            * depcomp 
            可以通過automake -a選項自動生成,所以這里只需要建立如下文件
            [root@localhost str]# touch NEWS README AUTHORS ChangeLog

            8、執(zhí)行automake


            [root@localhost str]# automake -a
            configure.ac: installing `./install-sh'
            configure.ac: installing `./missing
            '
            Makefile
            .am: installing `./INSTALL'
            Makefile.am: installing `./COPYING
            '
            Makefile
            .am: installing `./compile'
            Makefile.am: installing `./depcomp
            '

            9、autoconf

            [root@localhost str]# autoconf
            [root@localhost str]# ls
            aclocal.m4      autoscan.log  config.h.in   configure.scan  include     Makefile.am  NEWS
            AUTHORS         ChangeLog     configure     COPYING         INSTALL     Makefile
            .in  README
            autom4te
            .cache  compile       configure.ac  depcomp         install-sh  missing      src

            10、執(zhí)行測試:


                  
            執(zhí)行./configure
            [root@localhost str]# ./configure --prefix=/u
            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 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 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: creating config.h
            config
            .status: config.h is unchanged
            config
            .status: executing depfiles commands
            執(zhí)行 make
            [root@localhost str]# make
            make  all-am
            make[
            1]: Entering directory `/data/devel/c/str'
            if gcc -DHAVE_CONFIG_H -I. -I. -I.  -I include/   -g -O2 -MT str-str.o -MD -MP -MF ".deps/str-str.Tpo" -c -o str-str.o `test -f 
            'src/str.c' || echo './'`src/str.c; \
            then mv -f ".deps/str-str.Tpo" ".deps/str-str.Po"; else rm -f ".deps/str-str.Tpo"; exit 1; fi
            gcc  -g -O2   -o str  str-str.o
            make[1]: Leaving directory `/data/devel/c/str
            '
            執(zhí)行 make install
            [root@localhost str]# make install
            make[1]: Entering directory `/data/devel/c/str'
            test -z "/u/bin" || mkdir -p -- "/u/bin"
              /usr/bin/install -c 
            'str' '/u/bin/str'
            make[1]: Nothing to be done for `install-data-am
            '.
            make[
            1]: Leaving directory `/data/devel/c/str'

            11、測試程序:

            [root@localhost str]# /u/bin/str
            Please INPUT something end by [ENTER]
            abcksdhfklsdklfdjlkfd

            ----PRINT STRING----
            "abcksdhfklsdklfdjlkfd"

            到此結(jié)束!!



            --------------------

            添加測試包:
            [root@localhost str]# make dist-gzip
            { test ! -d str-0.0.1 || { find str-0.0.1 -type d ! -perm -200 -exec chmod u+w {} ';' && rm -fr str-0.0.1; }; }
            mkdir str-0.0.1
            find str
            -0.0.1 -type d ! -perm -777 -exec chmod a+rwx {} \-\
              
            ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \-\
              
            ! -type d ! -perm -400 -exec chmod a+r {} \-\
              
            ! -type d ! -perm -444 -exec /bin/sh /data/devel/c/str/install-sh --m a+r {} {} \\
            || chmod -R a+r str-0.0.1
            tardir
            =str-0.0.1 && /bin/sh /data/devel/c/str/missing --run tar chof - "$tardir" | GZIP=--best gzip ->str-0.0.1.tar.gz
            { test 
            ! -d str-0.0.1 || { find str-0.0.1 -type d ! -perm -200 -exec chmod u+w {} ';' && rm -fr str-0.0.1; }; }

            添加一個支持子目錄、靜態(tài)庫、自定義configure選項的包

            支持子目錄Makefile.am 選項 SUBDIR =
            #Automake interface 
            SUBDIRS = src
            支持靜態(tài)庫Makefile.am
            EXTRA_DIST  用于添加除源碼外的文件到dist包
            #Automake interface
            bin_PROGRAMS = hello
            hello_SOURCES 
            = hello.c lib/sbase.h
            hello_CPPFLAGS 
            = -I lib
            hello_LDFLAGS 
            = -static lib/libsbase.a
            EXTRA_DIST 
            = lib/libsbase.a
            configure.in
            AC_PREREQ(2.59)
            #AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)
            AC_INIT(hello, 0.0.1, [SounOS@gmail.com])
            #AM 聲明
            AM_INIT_AUTOMAKE
            AC_CONFIG_SRCDIR([src
            /hello.c])
            AC_CONFIG_HEADER([config
            .h])

            # Checks for programs.
            AC_PROG_CC

            # Checks for libraries.

            # Checks for header files.

            AC_HEADER_STDC
            AC_CHECK_HEADERS([stdint
            .h stdlib.h sys/socket.h])

            # Checks for typedefs, structures, and compiler characteristics.
            AC_C_CONST
            AC_TYPE_SIZE_T
            AC_TYPE_UINT32_T
            AC_TYPE_UINT64_T

            #用于自定義configure 選項,見acinclude.am
            AC_CHECK_EXTRA_OPTIONS
            # Checks for library functions.

            AC_CONFIG_FILES([Makefile
                             src
            /Makefile])
            AC_OUTPUT

            posted on 2009-05-14 17:31 不會飛的鳥 閱讀(2027) 評論(1)  編輯 收藏 引用

            評論

            # re: linux c 一個autotools的最簡單例子 2010-01-20 09:32 微凌秋白

            講解詳細到位,很有實用價值,能不能寫一篇關于Makefile.am內(nèi)容編寫的帖子,那就太感謝了  回復  更多評論   

            亚洲AV无一区二区三区久久| 精品多毛少妇人妻AV免费久久 | 人妻无码αv中文字幕久久| 亚洲人成电影网站久久| 亚洲色大成网站WWW久久九九| 久久只这里是精品66| 久久国产精品无码一区二区三区| 四虎国产精品免费久久久 | 欧美亚洲色综久久精品国产| 天天综合久久久网| 一本色综合久久| 国产精品久久久久9999高清| 欧洲国产伦久久久久久久| 精品少妇人妻av无码久久| 亚洲&#228;v永久无码精品天堂久久| 久久久久久久久久久| 日本精品久久久中文字幕| 久久久久久国产精品美女| 99久久精品国产综合一区 | 97精品依人久久久大香线蕉97| 伊人色综合久久天天| 日产精品久久久一区二区| 久久婷婷色香五月综合激情 | 国产福利电影一区二区三区,免费久久久久久久精 | 一本色道久久88综合日韩精品 | 中文字幕久久欲求不满| 亚洲av日韩精品久久久久久a| 国产成人香蕉久久久久| 久久精品国产亚洲沈樵| 少妇高潮惨叫久久久久久 | 国产美女久久久| 久久久久久久久久久久中文字幕 | 国产精品美女久久久久av爽| 久久国产精品成人片免费| 久久久久久午夜精品| 亚洲精品无码专区久久同性男| 精品人妻伦九区久久AAA片69| 香蕉久久夜色精品国产小说| 久久国产乱子伦精品免费强| 97久久综合精品久久久综合| 国产亚洲色婷婷久久99精品|