您的位置:首页 > 其它

automake 安装及使用

2015-01-13 00:23 197 查看
/article/2422085.html

autotools是个系列工具,首先确认你的Ubuntu系统是否安装了以下工具(可以通过which命令查看):

aclocal

autoscan

autoconf

autoheader

automake
安装方法:

root@ubuntu:~# sudo apt-get install autoconf (我只执行了这一条安装指令 下面的使用中没有出错)

显示如下:

正在读取软件包列表... 完成

正在分析软件包的依赖关系树

正在读取状态信息... 完成

E: 无法找到软件包 autoscan

将会安装下列额外的软件包:

automake autotools-dev m4

建议安装的软件包:

autoconf2.13 autobook autoconf-archive gnu-standards autoconf-doc libtool

gettext

下列【新】软件包将被安装:

autoconf automake autotools-dev m4

共升级了 0 个软件包,新安装了 4 个软件包,要卸载 0 个软件包,有 28 个软件未被升级。

需要下载 1315kB 的软件包。

解压缩后会消耗掉 4366kB 的额外空间。

您希望继续执行吗?[Y/n]

输入y,安装

最好一起安装它建议安装的软件包,否则autotools工具使用可能出错。

root@ubuntu:~# sudo apt-get install autotools-dev m4 autoconf2.13 autobook autoconf-archive gnu-standards autoconf-doc libtool

使用:
官方文档http://www.gnu.org/software/automake/manual/index.html

流程

第一部份:执行autoscan 修改configure.scan 成 configure.in

[cpp]
view plaincopyprint?

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

AC_PREREQ(2.68)
AC_INIT(hello,1.0)
AM_INIT_AUTOMAKE(hello,1.0)
AC_CONFIG_SRCDIR([hello.c])
AC_CONFIG_HEADERS([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

第二部份:执行aclocal 执行autoconf

第三部份: 执行autoheader

第四部份: 新建makefile.am 执行automake -a

[cpp]
view plaincopyprint?

AUTOMAKE_OPTIONS=foreign
bin_PROGRAMS= hello
hello_SOURCES= hello.c

最后:

。/configure make make install make clean



教程:

http://public0821.iteye.com/blog/665786

这片文章不错 : /article/6310724.html

http://www.jcwcn.com/article-22327-1.html

文库教程: http://wenku.baidu.com/view/bcb0074669eae009581becbb.html

实例:(应注意观察每一步的执行结果是否正确,是否生成了想要的文件)

实例1:精简实例很不错

(我测试过没问题 只是中间有个单词写错了

vim Makefile.am

文件内容为:

AUTOMAKE——OPTIONS=foreign

bin_PROGRAMS=hello

hello_SUORCES=hello.c 此处应为 hello_SOURCES=hello.c
)

/article/6310724.html

实例2:(未测试,但流程正确)

http://blog.163.com/adam_mhl/blog/static/64278267200710291130488/
建立目录: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

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.scan 成 condigure.in:

1,修改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汇报地址)
2,添加AM_INIT_AUTOMAKE

3,添加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

第二部份:(执行两条命令)

执行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 执行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

第三部份(执行一条命令)
5、autoheader
root@localhost str]# autoheader

第四部份(新建文件+执行automake)

6、创建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/
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、执行automake -a

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

最后一步:
10、执行测试:

执行./configure

执行 make 此时应该已经生成可执行文件,ls看一下

执行 make install

11、测试程序:#可执行文件
make clean 清除编译过程生成的文件
make uninstall 卸载

辅助知识

12. 添加测试包:make dist-gzip

13.添加一个支持子目录、静态库、自定义configure选项的包

支持子目录Makefile.am 选项 SUBDIR =

#Automake interface

SUBDIRS = src

支持静态库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.ac:

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: