As a packager, you will rarely create packages from scratch as we have done in the previous section. As you can imagine, many of the tasks and information in the rules file, for instance, are common to packages. To make packaging easier and more efficient, you can use debhelper to help with these tasks. Debhelper is a set of Perl scripts (prefixed with dh_) that automate the process of package-building. With these scripts, building a Debian package becomes quite simple.


In this example, we will again build the GNU Hello package, but this time we will be comparing our work to the Ubuntu hello-debhelper package. Again, create a directory where you will be working:

例として、もう一度GNU Helloパッケージを作成してみましょう。ただし今回は、Ubuntuのhello-debhelperと比較しながら作業を行います。前回と同様に、作業用ディレクトリを作成します:

mkdir ~/hello-debhelper
cd ~/hello-debhelper

Now, get the source code of GNU Hello from GNU Project's website:

GNUプロジェクトのウェブサイトからGNU Helloのソースコードを取得します:


Then, get the Ubuntu source package:


mkdir ubuntu
cd ubuntu
apt-get source hello-debhelper
cd ..

Like the previous example, the first thing we need to do is unpack the original (upstream) tarball.


tar -xzvf hello-2.1.1.tar.gz

Instead of copying the upstream tarball to hello_2.1.1.orig.tar.gz, as we did in the previous example, we will let dh_make do the work for us. It will also create a template of the debian/ directory.


The only thing you have to do is rename the source folder, so it is in the form of <packagename>-<version> where packagename is lowercase. In this case, we want to name the package hello-debhelper. So, we rename the directory:


mv hello-2.1.1 hello-debhelper-2.1.1

Now, from the package's directory, run dh_make:


cd hello-debhelper-2.1.1
dh_make -e your.maintainer@address -f ../hello-2.1.1.tar.gz

dh_make will then ask you a series of questions about your package:


Type of package: single binary, multiple binary, library, kernel module or cdbs?
[s/m/l/k/b] s

Maintainer name : Captain Packager
Email-Address   :
Date            : Thu,  6 Apr 2006 10:07:19 -0700
Package Name    : hello
Version         : 2.1.1
License         : blank
Type of Package : Single
Hit <enter> to confirm: Enter
  • attachment:UbuntuPackagingGuideJa/conventions/caution.png Only run dh_make -e once. If you run it again after you do it the first time, it will not work properly. If you want to change it or made a mistake, remove the source directory and untar the upstream tarball afresh. Then you can migrate into the source directory and try again.

  • attachment:UbuntuPackagingGuideJa/conventions/caution.png dh_make -eの実行は一度だけにしてください。一度実行した後にもう一度実行しても、正しく動作しません。間違って入力した場合など入力したデータを変更したいときは、一度ソースディレクトリを削除し、上流のアーカイブファイルをもう一度展開してください。その後、ソースディレクトリに移動すればdh_make -eをもう一度実行できます。

Running dh_make -e does two things:

dh_make -eの実行によって、二つのことが行われます:

  1. Creates the hello_2.1.1.orig.tar.gz file in the parent directory,

  2. Creates the basic files needed in debian/ and many template files (.ex) that may be needed.

  3. 親ディレクトリにhello_2.1.1.orig.tar.gzが作成されます。

  4. debian/ディレクトリに必要な基本的なファイルと、必要になると思われる多くのテンプレートファイル(.ex)が作成されます。

The Hello program is not very complicated, and as we have seen in the section called “一からパッケージングする”, packaging it does not require much more than the basic files. Therefore, let us remove the .ex files:


cd debian
rm *.ex *.EX

For hello, you will also not need some of the files into the debian directory:


  • README.Debian: the README file for specific Debian issues, not the program's README.

  • README.Debian: Debian特有の問題を記録するREADMEファイルで、ソフトウェアのREADMEファイルとは違います。

  • dirs: Used by dh_installdirs to create needed directories.

  • dirs: 必要なディレクトリを作成するためにdh_installdirsが利用します。

  • docs: Used by dh_installdocs to install program documentation.

  • docs: ソフトウェアのドキュメントをインストールするためにdh_installdocsが利用します。

  • info: Used by dh_installinfo to install the info file.

  • info: infoファイルをインストールするためにdh_installinfoが利用します。

Keep in mind that for most packages, these files are required. For more information on them, see the section called “'''dh_make''' example files”.


At this point, you should have only changelog, compat, control, copyright, and rules files in the debian directory. From the section called “一からパッケージングする”, the only file that is new is compat, which is a file that contains the debhelper version (in this case 4) that is used.


You will need to adjust the changelog slightly in this case to reflect that this package is named hello-debhelper rather than just hello:


hello-debhelper (2.1.1-1) edgy; urgency=low

  * Initial release

  -- Captain Packager <>  Thu,  6 Apr 2006 10:07:19 -0700

By using debhelper, the only things we need to change in control are the name (substituting hello for hello-debhelper) and adding debhelper (>= 4.0.0) to the Build-Depends field for the source package. The Ubuntu package for hello-debhelper looks like:

debhelperを使う場合、controlファイルに対して修正しなくてはいけないのは、パッケージ名(hellohello-debhelperに置き換える)と、ソースパッケージのBuild-Dependsdebhelper (>= 4.0.0)を追加することです。このhello-debhelperパッケージは次のようになります:

Source: hello-debhelper
Section: devel
Priority: extra
Maintainer: Capitan Packager <>
Standards-Version: 3.6.1
Build-Depends: debhelper (>= 4)

Package: hello-debhelper
Architecture: any
Depends: ${shlibs:Depends}
Conflicts: hello
Provides: hello
Replaces: hello
Description: The classic greeting, and a good example
 The GNU hello program produces a familiar, friendly greeting.  It
 allows non-programmers to use a classic computer science tool which
 would otherwise be unavailable to them.
 Seriously, though: this is an example of how to do a Debian package.
 It is the Debian version of the GNU Project's `hello world' program
 (which is itself an example for the GNU Project).
 This is the same as the hello package, except it uses debhelper to
 make the deb.  Please see debhelper as to what it is.

We can copy the copyright file and the postinst and prerm scripts from the Ubuntu hello-debhelper package, as they have not changed since the section called “一からパッケージングする”. We will also copy the rules file so we can inspect it.


cp ../../ubuntu/hello-debhelper-2.1.1/debian/copyright .
cp ../../ubuntu/hello-debhelper-2.1.1/debian/postinst .
cp ../../ubuntu/hello-debhelper-2.1.1/debian/prerm .
cp ../../ubuntu/hello-debhelper-2.1.1/debian/rules .

The last file we need to look at is rules, where the power of debhelper scripts can be seen. The debhelper version of rules is somewhat smaller (54 lines as opposed to 72 lines in the version from the section called “rules”).


The debhelper version looks like:


 #!/usr/bin/make -f

package = hello-debhelper

CC = gcc
CFLAGS = -g -Wall

ifeq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
  CFLAGS += -O2

#export DH_VERBOSE=1

        rm -f build
        -$(MAKE) -i distclean

install: build
        $(MAKE) prefix=$(CURDIR)/debian/$(package)/usr \
                mandir=$(CURDIR)/debian/$(package)/usr/share/man \
                infodir=$(CURDIR)/debian/$(package)/usr/share/info \

        ./configure --prefix=/usr
        $(MAKE) CC="$(CC)" CFLAGS="$(CFLAGS)"
        touch build

binary-indep: install
# There are no architecture-independent files to be uploaded
# generated by this package.  If there were any they would be
# made here.

binary-arch: install
        dh_testdir -a
        dh_testroot -a
        dh_installdocs -a NEWS
        dh_installchangelogs -a ChangeLog
        dh_strip -a
        dh_compress -a
        dh_fixperms -a
        dh_installdeb -a
        dh_shlibdeps -a
        dh_gencontrol -a
        dh_md5sums -a
        dh_builddeb -a

binary: binary-indep binary-arch

.PHONY: binary binary-arch binary-indep clean checkroot

Notice that tasks like testing if you are in the right directory (dh_testdir), making sure you are building the package with root privileges (dh_testroot), installing documentation (dh_installdocs and dh_installchangelogs), and cleaning up after the build (dh_clean) are handled automatically. Many packages much more complicated than hello have rules files no bigger because the debhelper scripts handle most of the tasks. For a complete list of debhelper scripts, please see the section called “List of debhelper scripts”. They are also well documented in their respective man pages. It is a useful exercise to read the man page (they are well written and not lengthy) for each helper script used in the above rules file.

正しいディレクトリにいるかどうかの確認(dh_testdir)や管理者権限でビルドしているかの確認(dh_testroot)、ドキュメントのインストール(dh_installdocsdh_installchangelogs)、ビルド後の掃除(dh_clean)などの作業が自動的に行われていることに気づくでしょう。helloよりも複雑な多くのパッケージでも、rulesファイルはそれほど大きくなりません。debhelperスクリプトが多くの作業を行ってくれるからです。完全なdebhelperスクリプトの一覧は、“debhelperスクリプトのリスト”を見てください。それぞれのmanページにも解説があります。上記rulesファイルで使われているそれぞれのスクリプトを調べれば、(よく書かれていて、それほど長くないので) manページを読む練習になるでしょう。


Now that we have gone through the files in the debian directory for hello-debhelper, we can build the source (and binary) packages. First, let us move back into the source directory:


cd ..

Now we build the source package using debuild, a wrapper script for dpkg-buildpackage:


debuild -S

the binary package, using pbuilder:


sudo pbuilder build ../*.dsc

and finally check the source package for common mistakes using lintian:


cd ..
lintian -i *.dsc






UbuntuJapaneseWiki: UbuntuPackagingGuideJa/basic-debhelper (最終更新日時 2012-01-10 11:49:06 更新者 匿名)