章 1. 從一條正確的路開始

內容目錄

1.1. Social dynamics of Debian
1.2. Programs needed for development
1.3. Documentation needed for development
1.4. 到何處尋求幫助

This document tries to describe the building of a Debian package to ordinary Debian users and prospective developers. It uses fairly non-technical language, and it's well covered with working examples. There is an old Latin saying: Longum iter est per praecepta, breve et efficax per exempla (It's a long way by the rules, but short and efficient with examples).

This document has been updated for the Debian squeeze release. [1]

One of the things that makes Debian such a top-notch distribution is its package system. While there is a vast quantity of software already in the Debian format, sometimes you need to install software that isn't. You may be wondering how you can make your own packages; and perhaps you think it is a very difficult task. Well, if you are a real novice on Linux, it is hard, but if you were a rookie, you wouldn't be reading this document now :-) You do need to know a little about Unix programming but you certainly don't need to be a wizard. [2]

One thing is certain, though: to properly create and maintain Debian packages takes many hours. Make no mistake, for our system to work the maintainers need to be both technically competent and diligent.

如果需要幫助,請閱讀 節 1.4, “到何處尋求幫助”

Newer versions of this document should always be available online at http://www.debian.org/doc/maint-guide/ and in the maint-guide package. The translations may be available in packages such as maint-guide-es. Please note that this documentation may be slightly outdated.

Since this is a tutorial, I choose to explain each detailed step for some important topics. Some of them may look irrelevant to you. Please be patient. I have also intentionally skipped some corner cases and provided only pointers to keep this document simple.

1.1. Social dynamics of Debian

Here are some observations of Debian's social dynamics, presented in the hope that it will prepare you for interactions with Debian.

  • We all are volunteers.

    • You cannot impose on others what to do.

    • You should be motivated to do things by yourself.

  • Friendly cooperation is the driving force.

    • Your contribution should not overstrain others.

    • Your contribution is valuable only when others appreciate it.

  • Debian is not your school where you get automatic attention of teachers.

    • You should be able to learn many things by yourself.

    • Attention from other volunteers is a very scarce resource.

  • Debian is constantly improving.

    • You are expected to make high quality packages.

    • You should adapt yourself to change.

There are several types of people interacting around Debian with different roles.

  • upstream author: the person who made the original program.

  • upstream maintainer: the person who currently maintains the program.

  • maintainer: the person making the Debian package of the program.

  • sponsor: a person who helps maintainers to upload packages to the official Debian package archive (after checking their contents).

  • mentor: a person who helps novice maintainers with packaging etc.

  • Debian Developer (DD): a member of the Debian project with full upload rights to the official Debian package archive.

  • Debian Maintainer (DM): a person with limited upload rights to the official Debian package archive.

Please note that you cannot become an official Debian Developer (DD) overnight, because it takes more than technical skill. Please do not be discouraged by this. If it is useful to others, you can still upload your package either as a maintainer through a sponsor or as a Debian Maintainer.

Please note that you do not need to create any new package to become an official Debian Developer. Contributing to the existing packages can provide a path to becoming an official Debian Developer too. There are many packages waiting for good maintainers (see 節 2.2, “選擇你的程式”).

Since we focus only on technical aspects of packaging in this document, please refer to the following to learn how Debian functions and how you can get involved.

1.2. Programs needed for development

在開始之前,你需要確認你是否已經正確安裝了開發所需要的附加套件。注意這些套件不包含任何已經被標記爲 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.

  • debhelper and dh-make - dh-make is necessary to create the skeleton of our example package, and it will use some of the debhelper tools for creating packages. They are not essential for this purpose, but are highly recommended for new maintainers. It makes the whole process very much easier to start, and to control afterwards. (See dh_make(8), debhelper(1).) [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] The document assumes you are using a squeeze or newer system. If you need to follow this text in an older system (including an older Ubuntu system etc.), you must install backported dpkg and debhelper packages, at least.

[2] You can learn about the basic handling of a Debian system from the Debian Reference. It contains some pointers to learn about Unix programming, too.

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