2009年4月2日星期四

简单源代码包的制作


                                                     图1. 生成Makefile流程图

本文以"hello world"程序为例,简单说明linux下源代码包(.tar.gz)的制作。

在此,谨以说明源代码包的制作过程。
首先,确保你的系统装有以下GNU软件:
Automake
Autoconf
m4
perl
libtool
1.新建一目录,将你的源代码放在此目录下,以下的操作均在此目录里进行。
shell>; mkdir hello
2.执行autoscan命令来扫描源代码。
shell>;autoscan
执行该命令后会生成configure.scan 和configure.log文件。
3.修改configure.scan文件。
shell>;vi configure.scan
添加,修改以下几行,其它的注释掉。
AC_INIT(hello.c) //括号内为你的源代码.
AC_PROG_CC
AM_INIT_AUTOMAKE(hello,1.0) //括号内hello为文件名,1.0为版本号.
AC_OUTPUT(makefile) //在括号内加入makefile.
保存文件,并修改此文件名为configure.in
shell>;mv configure.scan configure.in
4.运行aclocal命令,之后会生成aclocal.m4文件。
shell>;aclocal
5.运行autoconf命令,之后会生成autom4te.cache目录和configure可执行文件。
shell>;autoconf
6.自己编写makefile.am文件。
shell>;vi makefile.am
此文件格式为:
AUTOMAKE_OPTIONS=foreign
bin_PROGRAMS=hello
hello_SOURCES=hello.c
当然,有兴趣你也可对makefile.am文件进行扩展。
7.用automake --add-missing加入一些生成标准的软件包所必需的文件。
shell>;automake --add-missing
8.执行configure文件。 会生成make所需的makefile及其它文件。
shell>;./configure
9.用make编译,后已生成可执行文件hello,但只能在当前目录下用./执行。要想在任何目录都能执行,还要进行make
install.下述。
shell>;make
10.make install,将可执行文件写入/usr/local/bin下。
shell>;make install
11.最后一步,打包。会生成 .tar.gz的包,注意,这个包并非是用tar命令生成的。
shell>;make dist
至此,一个简单的源代码包制作完毕。ls
看一下,会有一个hello-1.tar.gz的源代码包生成了。

佳文推荐:
http://blog.chinaunix.net/u2/79955/showart_1830365.html
http://hi.baidu.com/zhanglei_186/blog/item/abe75b5c8cafc745faf2c008.html

致所有的已婚夫妻

嘴巴一张一合,一场战争就过去了;
  嘴巴一张不合,一场婚姻就过去了。