以Debian的方式系列(IN THE DEBIAN WAY):

构建 Debian 软件包

etony C.F.AN etony@tom.com

v0.0.1, 2006-6-29
本文档主要简单介绍几种构建 Debian 软件包的方法.

1. 声明

2. Debian软件包介绍

在Debian中存在两种类型的软件包:

在本文中我们将主要讲述 .deb 包的构建,源代码包的只会有少量舍己

软件包命名约定

Debian软件包命名遵循下列约定: <软件包名称>_<版本>-<Debian修订号>_<平台>.deb

例如

nano_1.3.10-2_i386.deb

        软件包名称: nano
        版本: 1.3.10
        修订号: 2
        平台: i386

3. .deb 文件的结构

参阅 Debian 的软件包管理系统介绍

4. 修改现有 .deb 文件

比如 nano(1.3.10) 需要满足以下依赖关系:

$ dpkg-deb -f nano_1.3.10-2_i386.deb depends            //depends 为对应查询段

libc6 (>= 2.3.5-1), libncursesw5 (>= 5.4-5)

当系统不能满足依赖关系, 比如不能满足里来版本, 可以通过下边的方法处理, 当然这种情况下安装的nano并不一定运行正常, 这种方法可以应用于某些软件的变通安装.

$ mkdir nano //创建nano目录

$ dpkg-deb -e ./nano_1.3.10-2_i386.deb ./nano/DEBIAN    //解压控制文件

$ dpkg-deb -x ./nano_1.3.10-2_i386.deb ./nano           //解压程序文件

$ vi ./nano/DEBIAN/control                                //修改控制信息

$ dpkg-deb -b nano nano_1.3.10-2_ill.deb                //重新打包

注:

下载 .deb 包的方法

5. 从当前系统构建 .deb 包

Debian软件包: dpkg-repack 可以用来重新构建已经安装到系统中的软件包为 .deb 文件. 并包含已经修改了的配置文件. 详细新息参阅:

dpkg-repack manpages

Debian GNU/Linux Anwenderhandbuch

对于某些需要修改配置后进行大面积安装的软件包, 可以是用 dpkg-repack 重新打包, 然后分发.

运行 dpkg-repack 需要 root 权限,也可以是用 fakeroot 取代 root 权限。例如:

# aptitude install dpkg-repack

$ fakeroot -u dpkg-repack nano
dpkg-deb: building package `nano' in `./nano_1.3.11-2_i386.deb'.

user@debian:~$ fakeroot -u dpkg-repack apt
dpkg-deb: building package `apt' in `./apt_0.5.22_i386.deb'.

可以使用 dpkg-deb 进行验证

$ dpkg-deb  -I ./nano_1.3.11-2_i386.deb 
 new debian package, version 2.0.
 size 256488 bytes: control archive= 2749 bytes.
      12 bytes,     1 lines      conffiles            
     857 bytes,    22 lines      control              
    3529 bytes,    51 lines      md5sums              
     613 bytes,    21 lines   *  postinst             #!/bin/sh
     160 bytes,     5 lines   *  postrm               #!/bin/sh
     379 bytes,    20 lines   *  preinst              #!/bin/sh
     288 bytes,    14 lines   *  prerm                #!/bin/sh
 Package: nano
 Priority: important
 Section: editors
 Installed-Size: 1452
 Maintainer: Jordi Mallach <jordi@debian.org>
 Architecture: i386
 Version: 1.3.11-2
 Replaces: pico
 Provides: editor
 Depends: libc6 (>= 2.3.5-1), libncursesw5 (>= 5.4-5)
 Suggests: spell
 Conflicts: nano-tiny (<= 1.0.0-1), pico
 Conffiles:
  /etc/nanorc 0f0e96f9c7e5ffe2338e79c9aacb9b9f
 Description: free Pico clone with some new features
  GNU nano is a free replacement for Pico, the default Pine editor. Pine is
  copyrighted under a restrictive licence, that makes it unsuitable for
  Debian's main section. GNU nano is an effort to provide a Pico-like
  editor, but also includes some features that were missing in the original,
  such as 'search and replace', 'goto line' or internationalization support. .
  (Repackaged on Fri, 26 May 2006 22:17:52 +0800 by dpkg-repack.)
 Architecture: i386

tony@tony:~/doc/build_package$ 

$dpkg-deb -c ./nano_1.3.11-2_i386.deb 
drwxr-xr-x root/root         0 2006-05-26 22:17:52 ./
drwxr-xr-x root/root         0 2006-05-26 22:17:52 ./etc/
-rw-r--r-- root/root     13611 2006-04-06 06:22:03 ./etc/nanorc
drwxr-xr-x root/root         0 2006-05-26 22:17:52 ./usr/
drwxr-xr-x root/root         0 2006-05-26 22:17:52 ./usr/share/
drwxr-xr-x root/root         0 2006-05-26 22:17:52 ./usr/share/doc/
drwxr-xr-x root/root         0 2006-05-26 22:17:52 ./usr/share/doc/nano/
-rw-r--r-- root/root      3419 2002-07-19 09:08:58 ./usr/share/doc/nano/BUGS.gz
-rw-r--r-- root/root      1847 2005-08-30 02:29:02 ./usr/share/doc/nano/AUTHORS
-rw-r--r-- root/root    102030 2006-03-30 14:34:43 ./usr/share/doc/nano/changelog.gz
-rw-r--r-- root/root      2338 2005-03-20 05:33:13 ./usr/share/doc/nano/README
-rw-r--r-- root/root      3234 2006-03-17 01:57:28 ./usr/share/doc/nano/THANKS
-rw-r--r-- root/root      2206 2005-06-08 10:28:06 ./usr/share/doc/nano/TODO
-rw-r--r-- root/root      1066 2003-03-24 21:09:26 ./usr/share/doc/nano/UPGRADE

.....

6. 使用源提供的源代码构建 .deb 包

7. 对现有文件打包:

8. 源代码构建

这次以 leafpad 为例, leafpad 的当前版本为 0.8.9

9. 参考文档