Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2570262
  • 博文数量: 315
  • 博客积分: 3901
  • 博客等级: 少校
  • 技术积分: 3640
  • 用 户 组: 普通用户
  • 注册时间: 2011-05-08 15:32
个人简介

知乎:https://www.zhihu.com/people/monkey.d.luffy Android高级开发交流群2: 752871516

文章分类

全部博文(315)

文章存档

2019年(2)

2018年(1)

2016年(7)

2015年(32)

2014年(39)

2013年(109)

2012年(81)

2011年(44)

分类: 项目管理

2011-11-26 11:03:57

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

aclocal
autoscan
autoconf
autoheader
automake

安装方法:
lin@lenovo:~$ 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,安装

装完后,用which 命令查看

如下:
lin@lenovo:~$ which aclocal
/usr/bin/aclocal
lin@lenovo:~$ which autoscan
/usr/bin/autoscan
lin@lenovo:~$ which autoconf
/usr/bin/autoconf
lin@lenovo:~$ which auto header
lin@lenovo:~$ automake
automake: `configure.ac' or `configure.in' is required
lin@lenovo:~$ which automake
/usr/bin/automake

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

下面开始来生成一个Makefile:

建立以下代码文件:
    add.h
    add.c
    main.c

以下直接贴出我的操作过程:(看了好多帖子,发现都不一样,最后测试了以下,发现这样可以的。所以留下,万一改天用到来看看)

huanglei@huanglei-laptop:~/automake$ ls
add.c  add.h  main.c  README
huanglei@huanglei-laptop:~/automake$ autoscan
huanglei@huanglei-laptop:~/automake$ ls
add.c  add.h  autoscan.log  configure.scan  main.c  README
huanglei@huanglei-laptop:~/automake$ mv configure.scan configure.in
huanglei@huanglei-laptop:~/automake$ ls
add.c  add.h  autoscan.log  configure.in  main.c  README
huanglei@huanglei-laptop:~/automake$ vim configure.in

内容修内容为:(注释内容我没有列出,这里有些地方说是把AC_CONFIG_HEADERS([config.h]))的AC_那个C改为M,但是不行的,我认为写法应该和AC_CONFIG_SRCDIR类似,实验也证明了这点。不信可以试试看。

AC_PREREQ([2.65])
#AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])
AC_INIT(ADD, 1.0)
AM_INIT_AUTOMAKE(ADD, 1.0)
AC_CONFIG_SRCDIR([add.c])
AC_CONFIG_HEADERS([config.h])

AC_PROG_CC

AC_OUTPUT(Makefile)

huanglei@huanglei-laptop:~/automake$ aclocal
huanglei@huanglei-laptop:~/automake$ ls
aclocal.m4  add.h           autoscan.log  main.c
add.c       autom4te.cache  configure.in  README
huanglei@huanglei-laptop:~/automake$ autoheader
huanglei@huanglei-laptop:~/automake$ ls
aclocal.m4  add.h           autoscan.log  configure.in  README
add.c       autom4te.cache  config.h.in   main.c
huanglei@huanglei-laptop:~/automake$ vim Makefile.am
内容如下:

AUTOMAKE_OPTIONS=gnu

bin_PROGRAMS=add

add_SOURCES=add.h add.c main.c

huanglei@huanglei-laptop:~/automake$ automake --add-missing
configure.in:7: installing `./install-sh'
configure.in:7: installing `./missing'
Makefile.am: installing `./INSTALL'
Makefile.am: required file `./NEWS' not found
Makefile.am: required file `./AUTHORS' not found
Makefile.am: required file `./ChangeLog' not found
Makefile.am: installing `./COPYING' using GNU General Public License v3 file
Makefile.am:     Consider adding the COPYING file to the version control system
Makefile.am:     for your code, to avoid questions about which license your project uses.
Makefile.am: installing `./depcomp'
huanglei@huanglei-laptop:~/automake$ touch NEWS AUTHORS ChangeLog

问题:
    网上有些人说是不用管上一步的警告也行,但是我测试了,发现如果这步没有,那么后面是无法生成Makefile.in文件的。

huanglei@huanglei-laptop:~/automake$ automake --add-missing
huanglei@huanglei-laptop:~/automake$ ls
aclocal.m4  autom4te.cache  configure.in  install-sh   missing
add.c       autoscan.log    COPYING       main.c       NEWS
add.h       ChangeLog       depcomp       Makefile.am  README
AUTHORS     config.h.in     INSTALL       Makefile.in
huanglei@huanglei-laptop:~/automake$ autoconf
huanglei@huanglei-laptop:~/automake$ ls
aclocal.m4  autom4te.cache  configure     INSTALL      Makefile.in
add.c       autoscan.log    configure.in  install-sh   missing
add.h       ChangeLog       COPYING       main.c       NEWS
AUTHORS     config.h.in     depcomp       Makefile.am  README
huanglei@huanglei-laptop:~/automake$ ./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 whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
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
huanglei@huanglei-laptop:~/automake$ ls
aclocal.m4      autoscan.log  config.status  INSTALL      Makefile.in
add.c           ChangeLog     configure      install-sh   missing
add.h           config.h      configure.in   main.c       NEWS
AUTHORS         config.h.in   COPYING        Makefile     README
autom4te.cache  config.log    depcomp        Makefile.am  stamp-h1
huanglei@huanglei-laptop:~/automake$ make
make  all-am
make[1]: 正在进入目录 `/home/huanglei/automake'
gcc -DHAVE_CONFIG_H -I.     -g -O2 -MT add.o -MD -MP -MF .deps/add.Tpo -c -o add.o add.c
mv -f .deps/add.Tpo .deps/add.Po
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 add add.o main.o  
make[1]:正在离开目录 `/home/huanglei/automake'

最后贴上网上关于相关命令的解释:
(感谢博主分享)
autotools 主要就是利用各个工具的脚本文件以生成最后的 Makefile。其总体流程是这样的。
 ? 使用 aclocal 生成一个“aclocal.m4”文件,该文件主要处理本地的宏定义;
 ? 改写“configure.scan”文件,并将其重命名为“configure.in”,并使用 autoconf 文件生成 configure 文件。
 接下来, 将通过一个简单的 hello.c 例子熟悉 autotools 生成 makefile 的过程,由于在这过程中有涉及较多的脚本文件,为了更清楚地了解相互之间的关系,强烈建议实际动手操作以体会其整个过程。

具体解释步骤参数解释网上资料多。这里就先学步骤了。相信用多了就熟悉了。


参考资料:(需要自己综合以下,实验下,因为有些地方都太对)
(这个好点)http://andychenkan.blog.163.com/blog/static/56300913200881922531784/


http://wujunmin-1983.blog.163.com/blog/static/3545122620100163431218/
http://blog.sina.com.cn/s/blog_63ed6f620100pown.html
阅读(2941) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~