linux 源码包的制作

来源:互联网 发布:js confirm的返回值 编辑:程序博客网 时间:2024/05/16 23:59
本文以“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的源代码
包生成了。
原创粉丝点击