【转载】制作Linux下安装包
Hello world
-------------
$ vim hello.c
1 #include "hello.h"
2
3 int main(void)
4 {
5 printf("hell,world!\n");
6 return 0;
7 }
$ vim hello.h
1 #ifndef __HELLO_H_
2 #define __HELLO_H_
3 #include <stdio.h>
4
5 #endif
安装包制作
-------------
o 我们以 “hello world” 程序为例,来制作 linux 下源码包的制作。
o 需要安装下的所要用到的软件:
$ sudo apt-get Automake Autoconf m4 perl libtool -y
o 进入 hello world 源码目下
$ cd hello
o 运行 autoscan 命令来扫描源代码。
$ autoscan
o 运行 autoscan 命令后会生成 configure.scan 和 configure.log ==文件。
o 修改 configure.scan 文件。 添加,修改以下几行,其它的注释掉。
$ vim configure.scan
AC_INIT(hello.c) //括号内为你的源代码.
AC_PROG_CC
AM_INIT_AUTOMAKE(hello,1.0) //括号内hello为文件名,1.0为版本号.
AC_OUTPUT(makefile) //在括号内加入makefile.
o 保存文件,并修改此文件名为configure.in
$ mv configure.scan configure.in
o 运行 aclocal 命令,之后会生成 aclocal.m4 文件。
$ aclocal
o 运行 autoconf 命令,之后会生成 autom4te.cache 目录和 configure 可执行文件。
$ autoconf
o 自己编写 makefile.am 文件。此文件格式为:
$ vim makefile.am
AUTOMAKE_OPTIONS=foreign
bin_PROGRAMS=hello
hello_SOURCES=hello.c
注:当然,有兴趣你也可对makefile.am文件进行扩展。
o 用 automake --add-missing 加入一些生成标准的软件包所必需的文件。
$ 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的源代码包生成了。
1.auto
2.
3.
4.
5.
6. tar zcf hello.tgz hello
test:
1.configure
2.make
3.make install
4.make distcheck
浙公网安备 33010602011771号