UbuntuJapaneseWiki

In this example we will be using the GNU hello program as our example. You can download the source tarball from ftp.gnu.org. For the purposes of this example, we will be using the ~/hello/ directory.

ここでは、GNU helloを例題として使用します。ソースファイルは ftp.gnu.org からダウンロードすることができます。その前に、例題用に~/hello/ディレクトリを作成しておきましょう。

mkdir ~/hello
cd ~/hello
wget http://ftp.gnu.org/gnu/hello/hello-2.1.1.tar.gz

We will also compare our package to one that is already packaged in the Ubuntu repository. For now, we will place it in the ubuntu directory so we can look at it later. To get the source package, make sure you have a "deb-src" line in your /etc/apt/sources.list file for the Main repository. Then, simply execute:

Ubuntuレポジトリにすでに存在するhelloパッケージと比較するために、ubuntuディレクトリを作成しそのパッケージを保存しておきます。ソースパッケージを手に入れるためには、まず/etc/apt/sources.listファイルにあるメインレポジトリ用の"deb-src"の行が有効になっていることを確認してください。その後、以下のコマンドを実行します:

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

What the apt-get source command does is:

apt-get sourceコマンドは、以下の作業を行います:

  1. Download the source package. A source package commonly contains a .dsc file describing the package and giving md5sums for the source package, an .orig.tar.gz file containing the source code from the author(s), and a .diff.gz file containing patches applied against the source code with the packaging information.
  2. Untar the .orig.tar.gz file into the current directory.
  3. Apply the gunzipped .diff.gz to the unpacked source directory.
  4. ソースパッケージをダウンロードします。ソースパッケージには、パッケージの概要やソースパッケージのmd5sum値を記した.dscファイル、ソフトウェア作成者のソースコードである.orig.tar.gzファイル、パッケージングの際にソースコードに対して適用されるパッチである.diff.gzなどが含まれています。
  5. .orig.tar.gzファイルを現在のディレクトリに展開します。
  6. .diff.gzファイルを伸張し、展開されたソースディレクトリに適用します。

If you manually download the source package (.dsc, .orig.tar.gz, and .diff.gz files), you can unpack them in the same way apt-get source does by using dpkg-source as follows:

ソースパッケージ(.dsc, .orig.tar.gz, .diff.gz)を手動でダウンロードした場合は、以下のようにdpkg-sourceコマンドを使えばapt-get sourceと同じ方法でそれらを展開することができます:

dpkg-source -x *.dsc

The first thing you will need to do is make a copy of the original (sometimes called "upstream") tarball in the following format: <packagename>_<version>.orig.tar.gz. This step does two things. First, it creates two copies of the source code. If you accidentally change or delete the working copy you can use the one you downloaded. Second, it is considered poor packaging practice to change the original source tarball unless absolutely necessary. See the section called “Common Mistakes” for reasons.

まず最初に、オリジナル(しばしば"上流(upstream)"とも呼ばれます)のソースアーカイブファイルを複製し、次の形式に名前を変更する必要があります:<packagename>_<version>.orig.tar.gz。これには二つの理由があります。一つはソースコードアーカイブの複製を作成することで、複製物をうっかり変更したり、削除してしまっても、すぐにダウンロードしたものに戻すことができます。もう一つは、オリジナルのソースアーカイブは本当に必要になるまでは修正を加えるべきでないという考えがあるからです。二つ目の理由については“よくある間違い”のセクションを参照してください。

cp hello-2.1.1.tar.gz hello_2.1.1.orig.tar.gz
tar -xzvf hello_2.1.1.orig.tar.gz

We now have a hello-2.1.1 directory containing the source files. Now we need to create the customary debian directory where all the packaging information is stored, allowing us to separate the packaging files from the application source files.

この時点でソースファイルが格納されているhello-2.1.1ディレクトリが作成されているはずです。次に、パッケージに関するすべての情報を格納するdebianディレクトリを作成します。これにより、アプリケーションのソースファイルと、パッケージングに関する情報を分離することができます。

mkdir hello-2.1.1/debian
cd hello-2.1.1/debian/

We now need to create the essential files for any Ubuntu source package: changelog, control, copyright, and rules. These are the files needed to create the binary packages (.deb files) from the original (upstream) source code. Let us look at each one in turn.

次にUbuntuのソースパッケージに必要不可欠なファイルである、changelogcontrolcopyrightrulesを作成します。これらのファイルはオリジナルの(上流の)ソースコードからバイナリパッケージ(.debファイル)を作成する際に必要になります。それぞれのファイルについて見ていきましょう。

changelog

The changelog file is, as its name implies, a listing of the changes made in each version. It has a specific format that gives the package name, version, distribution, changes, and who made the changes at a given time. If you have a GPG key, make sure to use the same name and email address in changelog as you have in your key. The following is a template changelog:

changelogファイルはその名のとおり、バージョンごとの変更点を記録するファイルです。パッケージ名やバージョン、ディストリビューション、変更点、その変更を行った人の名前などを決められた形式で記録します。GPG鍵を持っている場合は、鍵を作成したときと同じ名前とメールアドレスをchangelogに記載してください。以下はchangelogのテンプレートです:

package (version) distribution; urgency=urgency

  * change details
    more change details
  * even more change details

 -- maintainer name <email address>[two spaces]  date

The format (especially of the date) is important. The date should be in RFC822 format, which can be obtained from the 822-date program.

形式(特に日付)は重要です。日付はRFC822の形式に従うべきです。822-dateというプログラムを利用すれば、その形式に従った日付を生成してくれます。

Here is a sample changelog file for hello: これは、helloのためのchangelogファイルの例です:

hello (2.1.1-1) edgy; urgency=low

   * New upstream release with lots of bug fixes.

 -- Captain Packager <[email protected]>  Wed,  5 Apr 2006 22:38:49 -0700

Notice that the version has a -1 appended to it, or what is called the Debian revision, which is used so that the packaging can be updated (to fix bugs for example) with new uploads within the same source release version.

バージョンに-1が追加されたことに気づくでしょう。これはDebianリビジョンと呼ばれるもので、ソースファイルのバージョンが同じままで、パッケージのみを(不具合の修正などで)アップデートする時に使われます。

Now look at the changelog for the Ubuntu source package that we downloaded earlier:

先ほどダウンロードした、Ubuntuのソースパッケージのchangelogを見てみましょう:

less ../../ubuntu/hello-2.1.1/debian/changelog

Notice that in this case the distribution is unstable (a Debian branch), because the Debian package has not been changed by Ubuntu. Remember to set the distribution to your target distribution release.

distributionが(Debianのブランチの一つである)unstableになっています。これは、このソースパッケージがDebianのパッケージから修正されていないためです。このdistributionを、作成対象のディストリビューションのリリース名に変更することを忘れないでください。

At this point create a changelog file in the debian directory where you should still be.

changelogファイルは、現時点であなたがいるはずのdebianディレクトリに作成してください。

control

The control file contains the information that the package manager (such as apt-get, synaptic, and aptitude) uses, build-time dependencies, maintainer information, and much more.

controlファイルには、パッケージマネージャ(apt-getsynapticaptitudeなど)が利用する情報、ビルド時の依存情報、メンテナに関する情報などなどが含まれています。

For the Ubuntu hello package, the control file looks something like:

Ubuntu helloパッケージのcontrolファイルは次のようになっています:

Source: hello
Section: devel
Priority: optional
Maintainer: Captain Packager <[email protected]> 
Standards-Version: 3.6.1

Package: hello
Architecture: any
Depends: ${shlibs:Depends}
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).

Create control using the information above (making sure to provide your information for the Maintainer field).

上記の情報を利用してcontrolファイルを作成してください(Maintainerフィールドにはあなたの情報を入力してください)。

The first paragraph gives information about the source package. Let us go through each line:

最初の段落にはソースパッケージの情報を入力します。それぞれの行については以下のようになっています:

The second paragraph is for the binary package that will be built from the source. If multiple binary packages are built from the source package, there should be one section for each one. Again, let us go through each line:

二つ目の段落にはソースから生成されるバイナリパッケージの情報を記載します。そのソースパッケージから複数のバイナリパッケージを生成する場合は、そのそれぞれについて、一つのセクションが必要になります。それぞれの行については以下のようになっています:

This file gives the copyright information. Generally, copyright information is found in the COPYING file in the program's source directory. This file should include such information as the names of the author and the packager, the URL from which the source came, a Copyright line with the year and copyright holder, and the text of the copyright itself. An example template would be:

このファイルには著作権情報を記録します。一般的に、ソースコードの著作権情報はソースディレクトリのCOPYINGファイルに書いてあります。よって、copyrightファイルにはそれらの情報を参考に、作者とパッケージ作成者の名前、ソースコードが存在するURL、年や著作権保持者が記載されたCopyrightの行、ライセンス文などを書いていきます。例えば次のようになります:

This package was debianized by {Your Name} <your email address>
{Date}

It was downloaded from: {URL of webpage} 

Upstream Author(s): {Name(s) and email address(es) of author(s)}

Copyright:
        Copyright (C) {Year(s)} by {Author(s)} {Email address(es)}

License:

As one can imagine, hello is released under the GPL license. In this case it is easiest to just copy the copyright file from the Ubuntu package:

ご存知のとおり、helloはGPLというライセンスでリリースされています。この場合、Ubuntuパッケージからcopyrightファイルをコピーすればいいだけです:

cp ../../ubuntu/hello-2.1.1/debian/copyright .

You must include the complete copyright unless it is is GPL, LGPL, BSD, or Artistic License, in which case you can refer to the corresponding file in the /usr/share/common-licenses/ directory.

ライセンスがGPLやLGPL、BSD、Artistic Licenseでない場合は、完全なライセンス文を書く必要がありますが、それらのライセンスである場合は、/usr/share/common-licenses/ディレクトリの適切なファイルを指定するだけでもかまいません。

Notice that the Ubuntu package's copyright includes a license statement for the manual. It is important that all the files in the source be covered by a license statement.

Ubuntuパッケージのcopyrightには、マニュアルなどのライセンスも含めなくてはいけないことに注意してください。ソースパッケージに含まれるすべてのファイルのライセンス情報を書く必要があります。

rules

The rules file is an executable Makefile that has rules for building the binary package from the source packages. For hello, it will be easier to use the rules from the Ubuntu package:

rulesファイルは、ソースパッケージからバイナリパッケージをビルドするためのルールが記載されている、実行可能なMakefileです。helloの場合は、既存のUbuntuパッケージのrulesを流用できます:

# Sample debian/rules file - for GNU Hello.
# Copyright 1994,1995 by Ian Jackson.
# I hereby give you perpetual unlimited permission to copy,
# modify and relicense this file, provided that you do not remove
# my name from the file itself.  (I assert my moral right of
# paternity under the Copyright, Designs and Patents Act 1988.)
# This file may have to be extensively modified

package = hello
docdir = debian/tmp/usr/share/doc/$(package)

CC = gcc
CFLAGS = -g -Wall
INSTALL_PROGRAM = install

ifeq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
  CFLAGS += -O2
endif
ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
  INSTALL_PROGRAM += -s
endif

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

clean:
        $(checkdir)
        rm -f build
        -$(MAKE) -i distclean
        rm -rf *~ debian/tmp debian/*~ debian/files* debian/substvars

binary-indep:   checkroot build
        $(checkdir)
# There are no architecture-independent files to be uploaded
# generated by this package.  If there were any they would be
# made here.

binary-arch:    checkroot build
        $(checkdir)
        rm -rf debian/tmp
        install -d debian/tmp/DEBIAN $(docdir)
        install -m 755 debian/postinst debian/prerm debian/tmp/DEBIAN
        $(MAKE) INSTALL_PROGRAM="$(INSTALL_PROGRAM)" \
                prefix=$$(pwd)/debian/tmp/usr install
        cd debian/tmp &amp;&amp; mv usr/info usr/man usr/share
        cp -a NEWS debian/copyright $(docdir)
        cp -a debian/changelog $(docdir)/changelog.Debian
        cp -a ChangeLog $(docdir)/changelog
        cd $(docdir) &amp;&amp; gzip -9 changelog changelog.Debian
        gzip -r9 debian/tmp/usr/share/man
        gzip -9 debian/tmp/usr/share/info/*
        dpkg-shlibdeps debian/tmp/usr/bin/hello
        dpkg-gencontrol -isp
        chown -R root:root debian/tmp
        chmod -R u+w,go=rX debian/tmp
        dpkg --build debian/tmp ..

define checkdir
        test -f src/$(package).c -a -f debian/rules
endef

binary: binary-indep binary-arch

checkroot:
        $(checkdir)
        test $$(id -u) = 0

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

Let us go through this file in some detail. One of the first parts you will see is the declaration of some variables:

ファイルの中身について、詳しく見ていきましょう。最初の部分は、いくつかの変数の宣言となります:

package = hello
docdir = debian/tmp/usr/share/doc/$(package)

CC = gcc
CFLAGS = -g -Wall
INSTALL_PROGRAM = install

ifeq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
  CFLAGS += -O2
endif
ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
  INSTALL_PROGRAM += -s
endif

This section sets the CFLAGS for the compiler and also handles the noopt and nostrip DEB_BUILD_OPTIONS for debugging.

このセクションでは、コンパイラに渡すCFLAGSの設定と、デバッグ用のnooptnostrip DEB_BUILD_OPTIONSの処理を行っています。

Next is the build rule:

次はbuildルールです:

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

This rule runs ./configure with the proper prefix, runs make, and creates a build file that is a timestamp of the build to prevent erroneous multiple compilations.

このルールでは適切なプレフィックス(prefix)を指定して./configureを実行し、makeを実行し、コンパイルの重複を防ぐためにビルドのタイムスタンプ記録するbuildファイルを作成しています。

The next rule is clean, which runs make -i distclean and removes the files that are made during the package building.

次のルールはcleanと呼ばれるもので、make -i distcleanを実行し、パッケージのビルド時に作られたファイルを削除します。

clean:
        $(checkdir)
        rm -f build
        -$(MAKE) -i distclean
        rm -rf *~ debian/tmp debian/*~ debian/files* debian/substvars

Next we see an empty binary-indep rule, because there are no architecture-independent files created in this package.

次のbinary-indepは空です。このパッケージで生成されるファイルに、アーキテクチャに依存しないものがないためです。

There are, however, many architecture-dependent files, so binary-arch is used:

しかしながら、アーキテクチャに依存するファイルはたくさんあるので、binary-archは必要になります:

binary-arch:    checkroot build
                $(checkdir)
                rm -rf debian/tmp
                install -d debian/tmp/DEBIAN $(docdir)
                install -m 755 debian/postinst debian/prerm debian/tmp/DEBIAN
                $(MAKE) INSTALL_PROGRAM="$(INSTALL_PROGRAM)" \
                prefix=$$(pwd)/debian/tmp/usr install
                cd debian/tmp &amp;&amp; mv usr/info usr/man usr/share
                cp -a NEWS debian/copyright $(docdir)
                cp -a debian/changelog $(docdir)/changelog.Debian
                cp -a ChangeLog $(docdir)/changelog
                cd $(docdir) &amp;&amp; gzip -9 changelog changelog.Debian
                gzip -r9 debian/tmp/usr/share/man
                gzip -9 debian/tmp/usr/share/info/*
                dpkg-shlibdeps debian/tmp/usr/bin/hello
                dpkg-gencontrol -isp
                chown -R root:root debian/tmp
                chmod -R u+w,go=rX debian/tmp
                dpkg --build debian/tmp ..

First, notice that this rule calls the checkroot rule to make sure the package is built as root and calls the build rule to compile the source. Then the debian/tmp/DEBIAN and debian/tmp/usr/share/doc/hello files are created, and the postinst and the prerm scripts are installed to debian/tmp/DEBIAN. Then make install is run with a prefix that installs to the debian/tmp/usr directory. Afterward the documentation files (NEWS, ChangeLog, and the debian changelog) are gzipped and installed. dpkg-shlibdeps is invoked to find the shared library dependencies of the hello executable, and it stores the list in the debian/substvars file for the ${shlibs:Depends} variable in control. Then dpkg-gencontrol is run to create a control file for the binary package, and it makes the substitutions created by dpkg-shlibdeps. Finally, after the permissions of the debian/tmp have been set, dpkg --build is run to build the binary .deb package and place it in the parent directory.

最初に、管理者権限でパッケージをビルドしているかどうかを確認するためにcheckrootを、ソースをコンパイルするためにbuildルールを呼び出しています。その後、debian/tmp/DEBIANdebian/tmp/usr/share/doc/helloが作成され、postinstスクリプトとprermスクリプトがdebian/tmp/DEBIANにインストールされます。そしてdebian/tmp/usrディレクトリをプレフィックスに指定して、make installが実行されます。さらに文書ファイル(NEWSやChangeLog、Debianのchangelog)がgzip圧縮されインストールされます。helloを実行するために必要な共有ライブラリがdpkg-shlibdepsによって検索され、controlファイルの${shlibs:Depends}変数が参照するためにdebian/substvarsにその一覧が格納されます。その後、dpkg-gencontrolの実行によって、バイナリパッケージ用のcontrolファイルが作成され、dpkg-shlibdepsによって作成されたリストに置き換えられます。最後に、debian/tmpのパーミッションを変更したあと、バイナリパッケージ(.debファイル)を作成するためにdpkg --buildが実行され、親ディレクトリに保存されます。

postinstとprerm

The postinst and prerm files are examples of maintainer scripts. They are shell scripts that are executed after installation and before removal, respectively, of the package. In the case of the Ubuntu hello package, they are used to install (and remove) the info file. Go ahead and copy them into the current debian directory.

postinstprermファイルは、メンテナスクリプトと呼ばれるものの一例です。それぞれ、パッケージのインストール後、パッケージの削除前に実行されるシェルスクリプトになっています。Ubuntuのhelloパッケージの場合、infoファイルをインストール(もしくは削除)するために使われています。とりあえず今は、debianディレクトリにコピーしてください。

cp ../../ubuntu/hello-2.1.1/debian/postinst .
cp ../../ubuntu/hello-2.1.1/debian/prerm .

ソースパッケージのビルド

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

以上で、hello用のdebianディレクトリにあるファイルの解説は終了です。これでソースパッケージ(とバイナリパッケージ)のビルドが行えます。最初に、ソースファイルを展開したディレクトリに移動しましょう:

cd ..

Now we build the source package using dpkg-buildpackage:

dpkg-buildpackageを使ってソースパッケージのビルドを行います:

dpkg-buildpackage -S -rfakeroot

The -S flag tells dpkg-buildpackage to build a source package, and the -r flag tells it to use fakeroot to allow us to have fake root privileges when making the package. dpkg-buildpackage will take the .orig.tar.gz file and produce a .diff.gz (the difference between the original tarball from the author and the directory we have created, debian/ and its contents) and a .dsc file that has the description and md5sums for the source package. The .dsc and *_source.changes (used for uploading the source package) files are signed using your GPG key.

dpkg-buildpackageにソースパッケージをビルドするよう指示するために-Sフラグが使用されています。また、-rフラグは、パッケージ作成時に擬似的に管理者権限を与えるためにfakerootを使うことを意味しています。dpkg-buildpackage.orig.tar.gzを取得し、.diff.gz(これはソフトウェアの作成者によるオリジナルのアーカイブファイルと、私たちが作成したディレクトリやdebian/ディレクトリやその中身との差分です)、ソースパッケージの概要やmd5sumを記録した.dscファイルを生成します。.dscと(ソースパッケージのアップロードに使われる)*_source.changesファイルは、あなたのGPG鍵で署名されます。

In addition to the source package, we can also build the binary package with pbuilder:

ソースパッケージができたので、pbuilderを使えばバイナリパッケージも生成できます:

sudo pbuilder build ../*.dsc

Using pbuilder to build the binary packages is very important. It ensures that the build dependencies are correct, because pbuilder provides only a minimal environment, so all the build-time dependencies are determined by the control file.

バイナリパッケージを生成するためにpbuilderを使用することは、とても重要です。pbuilderは最小限の環境のみを用意し、ビルド時に必要なものはcontrolファイルのみに従って取得していくために、ビルド依存性(Build-Depends)の正しさを確認できるからです。

We can check the source package for common mistakes using lintian: ソースパッケージのよくある間違いはlintianを使って確認できます:

cd ..
lintian -i *.dsc

<=

=>

基本的なパッケージング

一からパッケージングする

Debhelperによるパッケージング

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