make file aotumake 編寫

來源:互聯網
上載者:User

 1、準備:
     需要工具autoscan aclocal autoheader automake autoconf make 等工具.
  2、測試程式編寫:
     建立目錄:mkdir include src
     編寫程式:include/str.h

{
function anonymous()
{
copycode($('code0'));
}
}" href="http://bbs.chinaunix.net/viewthread.php?tid=727270#">{
function anonymous()
{
toggle_collapse('code0');
}
}" href="http://bbs.chinaunix.net/viewthread.php?tid=727270#">

CODE:

#include <stdio.h>
int str(char *string);

編寫程式:src/str.c

{
function anonymous()
{
copycode($('code1'));
}
}" href="http://bbs.chinaunix.net/viewthread.php?tid=727270#">{
function anonymous()
{
toggle_collapse('code1');
}
}" href="http://bbs.chinaunix.net/viewthread.php?tid=727270#">

CODE:

#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.ac
    configure.ac是automake的輸入檔案,所以必須先產生該檔案。
    執行命令:

{
function anonymous()
{
copycode($('code2'));
}
}" href="http://bbs.chinaunix.net/viewthread.php?tid=727270#">{
function anonymous()
{
toggle_collapse('code2');
}
}" href="http://bbs.chinaunix.net/viewthread.php?tid=727270#">

CODE:

[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.ac

修改 configure.ac

{
function anonymous()
{
copycode($('code3'));
}
}" href="http://bbs.chinaunix.net/viewthread.php?tid=727270#">{
function anonymous()
{
toggle_collapse('code3');
}
}" href="http://bbs.chinaunix.net/viewthread.php?tid=727270#">

CODE:

#                                               -*- 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

修改

{
function anonymous()
{
copycode($('code4'));
}
}" href="http://bbs.chinaunix.net/viewthread.php?tid=727270#">{
function anonymous()
{
toggle_collapse('code4');
}
}" href="http://bbs.chinaunix.net/viewthread.php?tid=727270#">

CODE:

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

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

FULL-PACKAGE-NAME 為程式名稱,VERSION為目前的版本, BUG-REPORT-ADDRESS為bug彙報地址
    添加AM_INIT_AUTOMAKE
    添加AC_CONFIG_FILES([Makefile])

CODE:#                                               -*- 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、執行aclocal

CODE:[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

CODE:[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

{
function anonymous()
{
copycode($('code9'));
}
}" href="http://bbs.chinaunix.net/viewthread.php?tid=727270#">{
function anonymous()
{
toggle_collapse('code9');
}
}" href="http://bbs.chinaunix.net/viewthread.php?tid=727270#">

CODE:

[root@localhost str]# autoheader

7、automake必須檔案:

{
function anonymous()
{
copycode($('code10'));
}
}" href="http://bbs.chinaunix.net/viewthread.php?tid=727270#">{
function anonymous()
{
toggle_collapse('code10');
}
}" href="http://bbs.chinaunix.net/viewthread.php?tid=727270#">

CODE:

    *  install-sh
    * missing
    * INSTALL
    * NEWS
    * README
    * AUTHORS
    * ChangeLog
    * COPYING
    * depcomp

其中

{
function anonymous()
{
copycode($('code11'));
}
}" href="http://bbs.chinaunix.net/viewthread.php?tid=727270#">{
function anonymous()
{
toggle_collapse('code11');
}
}" href="http://bbs.chinaunix.net/viewthread.php?tid=727270#">

CODE:

    * install-sh
    * missing
    * INSTALL
    * COPYING
    * depcomp

可以通過automake -a選項自動產生,所以這裡只需要建立如下檔案

{
function anonymous()
{
copycode($('code12'));
}
}" href="http://bbs.chinaunix.net/viewthread.php?tid=727270#">{
function anonymous()
{
toggle_collapse('code12');
}
}" href="http://bbs.chinaunix.net/viewthread.php?tid=727270#">

CODE:

[root@localhost str]# touch NEWS README AUTHORS ChangeLog

8、執行automake

{
function anonymous()
{
copycode($('code13'));
}
}" href="http://bbs.chinaunix.net/viewthread.php?tid=727270#">{
function anonymous()
{
toggle_collapse('code13');
}
}" href="http://bbs.chinaunix.net/viewthread.php?tid=727270#">

CODE:

[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

{
function anonymous()
{
copycode($('code14'));
}
}" href="http://bbs.chinaunix.net/viewthread.php?tid=727270#">{
function anonymous()
{
toggle_collapse('code14');
}
}" href="http://bbs.chinaunix.net/viewthread.php?tid=727270#">

CODE:

[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、執行測試:
      執行./configure

{
function anonymous()
{
copycode($('code15'));
}
}" href="http://bbs.chinaunix.net/viewthread.php?tid=727270#">{
function anonymous()
{
toggle_collapse('code15');
}
}" href="http://bbs.chinaunix.net/viewthread.php?tid=727270#">

CODE:

[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

執行 make

{
function anonymous()
{
copycode($('code16'));
}
}" href="http://bbs.chinaunix.net/viewthread.php?tid=727270#">{
function anonymous()
{
toggle_collapse('code16');
}
}" href="http://bbs.chinaunix.net/viewthread.php?tid=727270#">

CODE:

[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'

執行 make install

{
function anonymous()
{
copycode($('code17'));
}
}" href="http://bbs.chinaunix.net/viewthread.php?tid=727270#">{
function anonymous()
{
toggle_collapse('code17');
}
}" href="http://bbs.chinaunix.net/viewthread.php?tid=727270#">

CODE:

[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、測試程式:

{
function anonymous()
{
copycode($('code18'));
}
}" href="http://bbs.chinaunix.net/viewthread.php?tid=727270#">{
function anonymous()
{
toggle_collapse('code18');
}
}" href="http://bbs.chinaunix.net/viewthread.php?tid=727270#">

CODE:

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

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

結束語:這隻是一個小例子,如果要把這個用得很好需要不斷的磨練。。。。呵呵,見笑了。

-----

添加測試包:

{
function anonymous()
{
copycode($('code19'));
}
}" href="http://bbs.chinaunix.net/viewthread.php?tid=727270#">{
function anonymous()
{
toggle_collapse('code19');
}
}" href="http://bbs.chinaunix.net/viewthread.php?tid=727270#">

CODE:

[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 {} /; -o /
  ! -type d ! -perm -444 -links 1 -exec chmod a+r {} /; -o /
  ! -type d ! -perm -400 -exec chmod a+r {} /; -o /
  ! -type d ! -perm -444 -exec /bin/sh /data/devel/c/str/install-sh -c -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 -c >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; }; }

添加一個支援子目錄、靜態庫、自訂configure選項的包

支援子目錄Makefile.am 選項 SUBDIR =

{
function anonymous()
{
copycode($('code20'));
}
}" href="http://bbs.chinaunix.net/viewthread.php?tid=727270#">{
function anonymous()
{
toggle_collapse('code20');
}
}" href="http://bbs.chinaunix.net/viewthread.php?tid=727270#">

CODE:

#Automake interface
SUBDIRS = src

支援靜態庫Makefile.am
EXTRA_DIST  用於添加除源碼外的檔案到dist包

{
function anonymous()
{
copycode($('code21'));
}
}" href="http://bbs.chinaunix.net/viewthread.php?tid=727270#">{
function anonymous()
{
toggle_collapse('code21');
}
}" href="http://bbs.chinaunix.net/viewthread.php?tid=727270#">

CODE:

#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.ac

CODE: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

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.