Chinaunix首页 | 论坛 | 博客
  • 博客访问: 150754
  • 博文数量: 12
  • 博客积分: 1401
  • 博客等级: 上尉
  • 技术积分: 415
  • 用 户 组: 普通用户
  • 注册时间: 2007-05-04 12:36
文章分类
文章存档

2009年(1)

2008年(11)

我的朋友

分类: LINUX

2008-04-25 21:08:25

linux autotools 软件包管理  ------by free coffee

从GNU网站上抄下来的,作了些备注。以备查用,也方便大家。
原文请看

2.4.1 Creating amhello-1.0.tar.gz

做一个简单的发布包。

Here is how we can recreate amhello-1.0.tar.gz from scratch. The package is simple enough so that we will only need to write 5 files. (You may copy them from the final amhello-1.0.tar.gz that is distributed with Automake if you do not want to write them.)

Create the following files in an empty directory.

进工作目录:cd ~/workspace。建src子目录文件夹放原代码main.c

  • src/main.c is the source file for the hello program. We store it in the src/ subdirectory, because later, when the package evolves, it will ease the addition of a man/ directory for man pages, a data/ directory for data files, etc.
              ~/amhello % cat src/main.c
    #include
    #include

    int
    main (void)
    {
    puts ("Hello World!");
    puts ("This is " PACKAGE_STRING "."); //会输出版本信息
    return 0;
    }
  • 做文档README,这个文件默认安装时会放在/usr/local/share/doc/hello下面
  • README contains some very limited documentation for our little package.
              ~/amhello % cat README
    This is a demonstration package for GNU Automake.
    Type `info Automake' to read the Automake manual.
  • Makefile.am and src/Makefile.am contain Automake instructions for these two directories.  顶目录和子目录都要Makfefile.am,以供autoconf(生成configure.ac)和automake(生成多个Makefile.in)调用。
              ~/amhello % cat src/Makefile.am
    bin_PROGRAMS = hello
    hello_SOURCES = main.c
    ~/amhello % cat Makefile.am
    SUBDIRS = src
    dist_doc_DATA = README

 这里本来还有个AUTOMAKE_OPTIONS选项:AUTOMAKE_OPTIONS=foreign..

automake提供了3种软件等级:foreign、gnu、gnits,让用户选择使用,默认等级是gnu,这个等级比较严格必须包含几个特定文件,如GPL协议。现在使用的foreign只是检测必要的文件。

bin_PROGRAMS=file定义了要产生的执行文件名。如果产生多个可执行文件,每个文件名用空格隔开。file_SOURCES定义file这个执行程序的依赖文件。同样的,对于多个执行文件,那就要定义相应的file_SOURCES。

  • Finally, configure.ac contains Autoconf instructions to create the configure script.
              ~/amhello % cat configure.ac
    AC_INIT([amhello], [1.0], [bug-automake@gnu.org]) //版本
    AM_INIT_AUTOMAKE([-Wall -Werror foreign]) //定makefile开关
    AC_PROG_CC //使configure脚本在系统中查找编译器,并确定CC
    AC_CONFIG_HEADERS([config.h]) //查找定义在configure.ac里的#define并生成configure.h
    AC_CONFIG_FILES([ //确定要生成哪些Makefile
    Makefile
    src/Makefile
    ])
    AC_OUTPUT


Once you have these five files, it is time to run the Autotools to instantiate the build system. Do this using the autoreconf command as follows:

     ~/amhello % autoreconf --install
configure.ac: installing `./install-sh'
configure.ac: installing `./missing'
src/Makefile.am: installing `./depcomp'

At this point the build system is complete.

In addition to the three scripts mentioned in its output, you can see that autoreconf created four other files: configure, config.h.in, Makefile.in, and src/Makefile.in. The latter three files are templates that will be adapted to the system by configure under the names config.h, Makefile, and src/Makefile. Let's do this:

     ~/amhello % ./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for gawk... no
checking for mawk... mawk
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 src/Makefile
config.status: creating config.h
config.status: executing depfiles commands

You can see Makefile, src/Makefile, and config.h being created at the end after configure has probed the system. It is now possible to run all the targets we wish (see ). For instance:

     ~/amhello % make
...
~/amhello % src/hello
Hello World!
This is amhello 1.0.
~/amhello % make distcheck
...
=============================================
amhello-1.0 archives ready for distribution:
amhello-1.0.tar.gz
=============================================
这样就生成了amhello-1.0.tar.gz.解压开来就可以./configure --prefix=..... 
make
sudo make install
了。
总结:
autotools主要的工具是autoconf,和automake。若只用这两工具的话configure.ac要自己写,如果项目大了,很麻烦。可以用autoscan扫描项目,生成configure.scan稍加修改就可以成configure.am,
至于Makefile.am 就只有自己写了。有很多文章介绍怎么一步步用aclocal autoconf,个人觉得比较麻烦
,可用autoreconf --install省去麻烦。
阅读(1456) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2008-08-04 17:54:20

SAP99,支持下,也欢迎访问我的博客, SAP资料多多 http://sap99.cublog.cn http://www.sap99.com 有很多的学习资料,推荐一下,