找回密码
 注册
搜索
热搜: 回贴
微赢网络技术论坛 门户 服务器 Linux/BSD 查看内容

Linux 的源码安装工具 CheckInstall 转

2009-12-20 13:44| 发布者: admin| 查看: 64| 评论: 0|原作者: 琴姬


级别: 初级
王 丽娜
(
[email=wanglina@cn.ibm.com?subject=Linux 的源码安装工具 CheckInstall]wanglina@cn.ibm.com[/email]
), 软件工程师, IBM 中国软件开发中心
2008 年 12 月 11 日
Checkinstall 是一个能从 tar.gz 类的源代码自动生成 RPM/Debian 或Slackware 安装包的程序。通过 CheckInstall,你就能用几乎所有的 tar.gz 类的源代码来生成“干净”的安装或者卸载包。
引言
经常出现这样的问题:很想试用的程序只有源代码(比如 tar.gz )可用,没人提供 RPM 或者Debian 包。你只好下载源代码,解压,然后手动编译。到目前为止,一切正常。然而,当你想删除它的时候呢?
Makefile 文件只包括了很少情况下的卸载例程。当然,你可以把程序安装到临时文件夹,然后记下所有由程序生成或修改的文件,最后删除他们。但是如果这个程序要经常重新编译,这样做是非常痛苦的,工作量也相当大。Felipe Eduardo 所写的 CheckInstall 就是用来解决这个问题的。
用 GNU Autoconf 安装程序
一般说来,我们编译安装一个由 GNU Autoconf 配置的程序是采用如下的步骤:
./configure && make && make install
这个 configure 脚本文件是用来“猜”出一系列系统相关的变量,这些变量是在后面的编译过程要用到的。它将检查系统变量值是否满足编译要求,然后使用这些变量在程序包内每个文件夹下生成 Makefile。此外,configure 脚本还会生成其它文件:



每个文件夹/子文件夹下的一个或多个 Makefile(s)

一个名叫 config.status 的脚本

一个文本文件 config.log

Configure 脚本文件成功运行之后, 你会输入 make 来编译程序,得到你需要的可执行文件。如果 make 成功的完成,你可以使用 make install 来安装这个程序。
用 CheckInstall 安装程序
上节我们采用 GNU Autoconf 来编译程序,现在该是换一种方式的时候了。你可以使用CheckInstall 工具。它采用自己的指令 checkinstall 来代替 make install。其他两个指令保留下来跟以前一样,因此,现在这个指令序列使用 CheckInstall 变成:
./configure && make && checkinstall
指令 checkinstall 不仅默认运行了 make install,而且还监测所有安装过程中的写操作。为此,CheckInstall 使用了 Pancrazio de Mauro 所写的程序 Installwatch。在 make install 成功完成之后,CheckInstall 会产生一个 Slackware-,Debian- 或RPM- 安装包,然后按照软件包的默认配置来安装程序,并在当前目录(或标准安装包存储目录)留下一个生成的安装包。你可以通过修改变量 PAK_DIR 来修改这个保存目录。
CheckInstall 并不只是使用 make install,它还可以与其他安装指令相协调。例如,如果安装指令为 setup.sh,那么安装指令序列变成:
./configure && make && checkinstall setup.sh
我们还可以让 CheckInstall 带着很多参数运行。
图 1. 运行命令“checkinstall –h”显示所有可用的子参数
screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://www.ibm.com/developerworks/cn/linux/l-cn-checkinstall/images/image001.jpg');}" onmousewheel="return imgzoom(this);" alt="" />

 
这些子参数大致分为:



安装选项(Install options)

脚本处理选项(Scripting options)

信息显示选项(Info display options)

安装包选项(Package tuning options)

清除选项(Cleanup options)

关于 CheckInstall (About CheckInstall)。

如果 CheckInstall 带着这些参数运行,它会使用这些参数值来代替配置文件 checkinstallrc 中相应的值。
CheckInstall 也有自己的局限之处。它不能处理静态连接的程序,因为这样 Installwatch 就不能监测到安装过程中修改过文件了。总体说来,有两类连接库:动态的和静态的。这些连接库通过 include 指令整合到程序中。静态连接过的程序已经包含了所有需要的库文件,运行时也就不需要再将这些库载入内存中。这种程序与安装在系统中的连接库无关,因为所谓的连接器(Linker)已经在编译时把这些库内置到可执行程序里了。
CheckInstall 的安装
我们可以在 CheckInstall 的主页上下载各种预编译好的安装包或者合适的源码包。下面将展示安装最新的源代码 checkinstall-1.6.1.tgz 的全过程。这会安装上 CheckInstall、Installwatch和 makepak,其中 makepak 是 makepkg 的修改版。如果你对新版本的改进感兴趣,请参看Release Notes 和 Changelog。
清单 1. 生成 checkinstall 的 rpm 安装包
# tar xzf checkinstall-1.6.1.tgz
# cd checkinstall-1.6.1
checkinstall-1.6.1# make
checkinstall-1.6.1# make install
checkinstall-1.6.1# checkinstall
图 2. 运行命令“checkinstall”生成 rpm 包的图示过程
screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://www.ibm.com/developerworks/cn/linux/l-cn-checkinstall/images/image002.jpg');}" onmousewheel="return imgzoom(this);" alt="" />

图 2.1. 过程一
screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://www.ibm.com/developerworks/cn/linux/l-cn-checkinstall/images/image003.jpg');}" onmousewheel="return imgzoom(this);" alt="" />

图 2.2. 过程二
screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://www.ibm.com/developerworks/cn/linux/l-cn-checkinstall/images/image004.jpg');}" onmousewheel="return imgzoom(this);" alt="" />

图 2.3. 过程三
screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://www.ibm.com/developerworks/cn/linux/l-cn-checkinstall/images/image005.jpg');}" onmousewheel="return imgzoom(this);" alt="" />

checkinstall-1.6.1 的 rpm 包已经生成,我们用 rpm 来安装它。
清单 2. 用生成的 rpm 包安装 checkinstall
checkinstall-1.6.1# cd /usr/src/redhat/RPMS/i386/
i386# rpm -i checkinstall-1.6.1.rpm
checkinstall-1.6.1 安装完毕。使用包管理程序的查询语句,你可以检查安装包中文件是否完全在程序库中记录了,还可以查看安装包头部的一些额外信息。
图 3. 检查 checkinstall 的 RPM 包
screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://www.ibm.com/developerworks/cn/linux/l-cn-checkinstall/images/image006.jpg');}" onmousewheel="return imgzoom(this);" alt="" />

CheckInstall 的配置
你可以通过修改配置文件 /usr/local/lib/checkinstall/checkinstallrc 来改变 CheckInstall 的默认配置。
文件值得注意的变量有 INSTYPE,INSTALL 和 PAK_DIR。
INSTYPE 变量决定生成何种类型安装包。
图 4. 查看变量 INSTYPE
screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://www.ibm.com/developerworks/cn/linux/l-cn-checkinstall/images/image007.jpg');}" onmousewheel="return imgzoom(this);" alt="" />

PAK_DIR 变量决定安装包的存储目录。
图 5. 查看变量 PAK_DIR
screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://www.ibm.com/developerworks/cn/linux/l-cn-checkinstall/images/image008.jpg');}" onmousewheel="return imgzoom(this);" alt="" />

INSTALL 变量决定是只生成安装包还是一起将这个包马上安装。
0-只生成安装包
1-不仅生成安装包,还将包立即安装
图 6. 查看变量 INSTALL
screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://www.ibm.com/developerworks/cn/linux/l-cn-checkinstall/images/image009.jpg');}" onmousewheel="return imgzoom(this);" alt="" />

用 CheckInstall 制作 RPM 包实例
上两节我们把 Checkinstall 安装配置完成,这节以 squid-2.6.STABLE12.tar.bz2 为例,说明用checkinstall 制作编译成 squid-2.6.STABLE12-1.i386.rpm 包的具体方法。
清单 3. 生成 squid-2.6.STABLE12 的 rpm 安装包
# tar jxvf squid-2.6.STABLE12.tar.bz2
# cd squid-2.6.STABLE12
squid-2.6.STABLE12# ./configure --prefix=/usr/local/squid --sysconfdir=/etc \
--enable-arp-acl --enable-linux-netfilter -enable-err-language="Simplify_Chinese" \
--enable-storeio=ufs --enable-default-err-language="Simplify_Chinese" \
--enable-auth="basic" --enable-baisc-auth-helpers="NCSA" --enable-underscore
squid-2.6.STABLE12# make
squid-2.6.STABLE12# checkinstall
生成 rpm 包期间会出现一些选项,选择默认的即可。
图 7. 运行命令“checkinstall”生成 rpm 包的图示过程
screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://www.ibm.com/developerworks/cn/linux/l-cn-checkinstall/images/image010.jpg');}" onmousewheel="return imgzoom(this);" alt="" />

图 7.1. 过程一
screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://www.ibm.com/developerworks/cn/linux/l-cn-checkinstall/images/image011.jpg');}" onmousewheel="return imgzoom(this);" alt="" />

图 7.2. 过程二
screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://www.ibm.com/developerworks/cn/linux/l-cn-checkinstall/images/image012.jpg');}" onmousewheel="return imgzoom(this);" alt="" />

图 7.3. 过程三
screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://www.ibm.com/developerworks/cn/linux/l-cn-checkinstall/images/image013.jpg');}" onmousewheel="return imgzoom(this);" alt="" />

图 7.4. 过程四
screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://www.ibm.com/developerworks/cn/linux/l-cn-checkinstall/images/image014.jpg');}" onmousewheel="return imgzoom(this);" alt="" />

清单 4. 用生成的 rpm 包安装 squid-2.6.STABLE12
squid-2.6.STABLE12# cd /usr/src/redhat/RPMS/i386/
i386# rpm -ivh squid-2.6.STABLE12-1.i386.rpm
图 8. 检查 squid-2.6.STABLE12 的 RPM 包
screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://www.ibm.com/developerworks/cn/linux/l-cn-checkinstall/images/image015.jpg');}" onmousewheel="return imgzoom(this);" alt="" />

结束
CheckInstall 是一款优秀的源码安装软件,它使得 Linux 软件管理更加方便。特别是在源码需要经常重复编译的情况下,CheckInstall 可以让你丝毫不破坏系统一致性的前提下完全的卸载程序。而且,你还可以使用这些编译好的安装包直接在其他的机器上安装无须再重新编译。
参考资料



学习更多关于 Checkinstall 的知识请参阅:
http://asic-linux.com.mx/~izto/checkinstall/


GNU Autoconf Online Manual:
http://www.gnu.org/software/auto ... -2.57/autoconf.html


Installwatch Manual:
http://asic-linux.com.mx/~izto/checkinstall/installwatch.html


下载 Checkinstall 网站:
http://asic-linux.com.mx/~izto/checkinstall/download.php


Checkinstall 的 Release Notes:
http://asic-linux.com.mx/~izto/checkinstall/docs/RELNOTES


Checkinstall 的 Changelog:
http://asic-linux.com.mx/~izto/checkinstall/docs/Changelog


关于作者
screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://www.ibm.com/i/c.gif');}" onmousewheel="return imgzoom(this);" alt="" />

screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://www.ibm.com/i/c.gif');}" onmousewheel="return imgzoom(this);" alt="" />
王丽娜,中国软件开发中心 Tivoli 部门软件工程师,负责 IBM 产品TMF(Tivoli Management Framework)的维护和客户支持工作,热爱 Linux。





最新评论

QQ|小黑屋|最新主题|手机版|微赢网络技术论坛 ( 苏ICP备08020429号 )

GMT+8, 2024-9-30 07:30 , Processed in 0.161356 second(s), 12 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

返回顶部