第 1 章 从一条正确的路开始

目录

1.1. Debian 的社会驱动力
1.2. 开发时需要的软件
1.3. Documentation needed for development
1.4. 到何处寻求帮助

这篇文档试图为普通 Debian 用户,和希望对 Debian 软件包有所了解的开发人员讲述如何制作 Debian 软件包。在这里,我们尽可能使用通俗的语言,并辅以大量实例来直观地展示每一个细节。正如一句古罗马谚语说得好:一例胜千言!

本文档已经针对 Debian squeeze 进行了更新。[1]

Debian 的软件包系统是使它跻身顶级发行版行列的重要原因之一。尽管已经有相当数量的软件被打包成 Debian 的格式,但有时还是需要安装一些不是这一格式的软件。可能你正为如何制作自己的软件包而感到迷惑,也可能正认为这么做很难。如果你是一个刚刚接触 Debian 的初学者,那么是的,它的确很难;不过假如你真的只是一个初入此门的新手,现在大概也不会来读这篇文档了。:-) 你的确需要对 Unix 编程有所了解,但显然没必要是这方面的天才。[2]

对于 Debian 软件包维护人员来说,有一件事是非常明确的:创建并维护一个 Debian 软件包需要花费很多精力,所需的时间很可能远不只是几个小时。维护人员需要有良好的技术基础,同时也需要十分勤奋,这样才能保证我们的系统正常运行而不出现问题。

如果你在打包方面需要别人帮助,请阅读 第 1.4 节 “到何处寻求帮助”

本文的最新版随时都可以在 http://www.debian.org/doc/maint-guide/ 上和 maint-guide 软件包里找到。文档的简体中文翻译可以在 maint-guide-zh-cn 软件包里找到。还有一点需要注意的是,这篇文档的内容相对于当前的开发情况可能会有略微的延迟。

由于这篇文档是一份手把手的教程,所以在一些重要的话题上会对每个步骤都做详细的解释。因而你可能觉得它们之中有一些与你的想法毫不相干。请准备好足够的耐心来学习。同时我也有意地省略了某些不必要的细节,以使这篇文档尽可能保持简洁。

1.1. Debian 的社会驱动力

以下是一些有关 Debian 的社会动力学报告,希望它们有助于你掌握如何与 Debian 项目进行互动的方法。

  • 我们都是志愿者。

    • 任何人都不能把事情强加给他人。

    • 你应该主动地做自己的事情。

  • 友好合作是我们前行的动力。

    • 你的贡献不应致使他人过劳。

    • 只有当别人欣赏你的贡献时,它才真正有价值。

  • Debian 不是一所学校,没有老师会自动地注意你。

    • 你需要有自学大量知识的能力。

    • 其他志愿者的注意是非常稀缺的资源。

  • Debian 在不断进步。

    • Debian 期望你制作出高质量的软件包。

    • 你应该适时改变自己来适应变化。

在 Debian 社区中有几个常见的角色。

  • Upstream author (上游作者):程序的原始作者。

  • Upstream maintainer (上游维护者):目前在上游维护程序代码的人。

  • Maintainer (软件包维护者):制作并维护该程序的 Debian 软件包的人。

  • Sponsor (保证人):检查内容后帮助维护者上传软件包到 Debian 官方仓库的人。

  • Mentor (指导者):帮助维护者熟悉和深入打包的人。

  • Debian Developer (DD):Debian 社区的官方成员。DD 拥有向 Debian 官方仓库上传的全部权限。

  • Debian Maintainer (DM):拥有对 Debian 官方仓库部分上传权限的人。

注意,你不可能在一夜之间成为 Debian Developer,因为成为 DD 所需要的远不只是技术技巧。别因此气馁,如果你的软件包对其他人有用,你可以作为软件包的 Maintainer,通过一位 Sponsor 来上传它,或者申请成为 Debian Maintainer

还有,要成为 Debian Developer 不一定要创建新软件包。对已有软件做出贡献也是成为 Debian Developer 的理想途径。眼下正有很多软件包等着好的维护者来接手(参看 第 2.2 节 “选择你的程序”)。

在这篇文档里,我们的重点在于打包的技术细节,所以请参考以下的文档来了解 Debian 是如何运转的。

1.2. 开发时需要的软件

在开始之前,你需要确认你是否已经正确安装了开发所需要的附加软件包。注意这些软件包不包含任何已经被标记为 essentialrequired —— 我们假设你已经安装了它们。

The following packages come with the standard Debian installation, so you probably have them already (along with any additional packages they depend on). Still, you should check it with aptitude show package or with dpkg -s package.

The most important package to install on your development system is the build-essential package. Once you try to install that, it will pull in other packages required to have a basic build environment.

For some types of packages, that is all you will require; however, there is another set of packages that while not essential for all package builds are useful to have installed or may be required by your package:

  • autoconf, automake, and autotools-dev - many newer programs use configure scripts and Makefile files preprocessed with the help of programs like these (see info autoconf, info automake). autotools-dev keeps up-to-date versions of certain auto files and has documentation about the best way to use those files.

  • dh-makedebhelper - dh-make 是用于创建我们示例软件包骨架所必须的,它会使用 debhelper 中的一些工具来创建软件包。他们不是创建软件包所必须的,但对新维护人员而言,我们 强烈推荐 使用。它使得整个过程极为简化,并易于在将来维护。(参看 dh_make(8)debhelper(1)/usr/share/doc/debhelper/README) [3]

  • devscripts - this package contains some useful scripts that can be helpful for maintainers, but they are also not necessary for building packages. Packages recommended and suggested by this package are worth looking into. (See /usr/share/doc/devscripts/README.gz.)

  • fakeroot - this utility lets you emulate being root which is necessary for some parts of the build process. (See fakeroot(1).)

  • file - this handy program can determine what type a file is. (See file(1).)

  • gfortran - the GNU Fortran 95 compiler, necessary if your program is written in Fortran. (See gfortran(1).)

  • git - this package provides a popular version control system designed to handle very large projects with speed and efficiency; it is used for many high profile open source projects, most notably the Linux kernel. (See git(1), git Manual (/usr/share/doc/git-doc/index.html).)

  • gnupg - a tool that enables you to digitally sign packages. This is especially important if you want to distribute it to other people, and you will certainly be doing that when your work gets included in the Debian distribution. (See gpg(1).)

  • gpc - the GNU Pascal compiler, necessary if your program is written in Pascal. Worthy of note here is fp-compiler, the Free Pascal Compiler, which is also good at this task. (See gpc(1), ppc386(1).)

  • lintian - this is the Debian package checker, which can let you know of any common mistakes after you build the package, and explains the errors found. (See lintian(1), Lintian User's Manual.)

  • patch - this very useful utility will take a file containing a difference listing (produced by the diff program) and apply it to the original file, producing a patched version. (See patch(1).)

  • patchutils - 此软件包提供了一些可以帮助处理补丁的工具,如 lsdiffinterdifffilterdiff 命令。

  • pbuilder - 这个软件包提供了创建和维护 chroot 环境。在此 chroot 环境中编译 Debian 软件包可以检查编译依赖是否合适并避免 FTBFS (Fails To Build From Source,从源代码编译失败)的 Bug。(参看 pbuilder(8)pdebuild(1))

  • perl - Perl is one of the most used interpreted scripting languages on today's Unix-like systems, often referred to as Unix's Swiss Army Chainsaw. (See perl(1).)

  • python - Python is another of the most used interpreted scripting languages on the Debian system, combining remarkable power with very clear syntax. (See python(1).)

  • quilt - this package helps you to manage large numbers of patches by keeping track of the changes each patch makes. Patches can be applied, un-applied, refreshed, and more. (See quilt(1), and /usr/share/doc/quilt/quilt.pdf.gz.)

  • xutils-dev - some programs, usually those made for X11, also use these programs to generate Makefile files from sets of macro functions. (See imake(1), xmkmf(1).)

The short descriptions that are given above only serve to introduce you to what each package does. Before continuing please read the documentation of each relevant program including ones installed through the package dependency such as make, at least, for the standard usage. It may seem like heavy going now, but later on you'll be very glad you read it. If you have specific questions later, I would suggest re-reading the documents mentioned above.

1.3. Documentation needed for development

以下是 非常重要 的文档,你应该在读本文档时同时参看它们:

  • debian-policy - the Debian Policy Manual includes explanations of the structure and contents of the Debian archive, several OS design issues, the Filesystem Hierarchy Standard (FHS, which says where each file and directory should be), etc. For you, the most important thing is that it describes requirements that each package must satisfy to be included in the distribution. (See the local copies of /usr/share/doc/debian-policy/policy.pdf.gz and /usr/share/doc/debian-policy/fhs/fhs-2.3.pdf.gz.)

  • developers-reference - the Debian Developer's Reference describes all matters not specifically about the technical details of packaging, like the structure of the archive, how to rename, orphan, or adopt packages, how to do NMUs, how to manage bugs, best packaging practices, when and where to upload etc. (See the local copy of /usr/share/doc/developers-reference/developers-reference.pdf.)

The following is the important documentation which you should read along with this document:

If this document contradicts any of the documents mentioned above, they are correct. Please file a bug report on the maint-guide package using reportbug.

The following is an alternative tutorial documentation which you may read along with this document:

1.4. 到何处寻求帮助

Before you decide to ask your question in some public place, please read the fine documentation.

You can use web search engines more effectively by including search strings such as site:lists.debian.org to limit the domain.

Making a small test package is a good way to learn details of packaging. Inspecting existing well maintained packages is the best way to learn how other people make packages.

If you still have questions about packaging that you couldn't find answers to in the available documentation and web resources, you can ask them interactively.

The more experienced Debian developers will gladly help you, if you ask properly after making your required efforts.

When you receive a bug report (yes, actual bug reports!), you will know that it is time for you to dig into the Debian Bug Tracking System and read the documentation there, to be able to deal with the reports efficiently. I highly recommend reading the Debian Developer's Reference, 5.8. "Handling bugs".

即使以上的问题都解决了,也不能高兴得太早。为什么?因为几个小时或几天内就会有人开始使用你的软件包,如果你犯了某些严重的错误,将被无数生气的 Debian 用户的邮件所轰炸…… 只是开个玩笑。:-)

放松一点并准备好处理 Bug 报告,在你的软件包完全符合 Debian 的各项规范前还需要付出很多努力,处理 Bug 也是对你很好的锻炼(再一次提醒,阅读那些 必须的文档 来了解详情)。祝你好运!



[1] 在写这份文档时,我们默认你使用 squeeze 操作系统。如果你需要在 lenny 系统上使用本文所记述的方法,则必须安装 backports 仓库中的 dpkgdebhelper 软件包。

[2] Debian Reference 中,你可以了解到使用 Debian 系统的一些基本信息和关于 Unix 编程的一些指引。

[3] There are also some more specialized but similar packages such as dh-make-perl, dh-make-php, etc.