#title 一からパッケージングする . [[attachment:UbuntuPackagingGuideJa/conventions/important.png|{{attachment:UbuntuPackagingGuideJa/conventions/important.png}}]] '''Requirements:''' build-essential, automake, gnupg, lintian, fakeroot and [[UbuntuPackagingGuideJa/gs-pbuilder|pbuilder]]. . [[attachment:UbuntuPackagingGuideJa/conventions/important.png|{{attachment:UbuntuPackagingGuideJa/conventions/important.png}}]] '''必要なパッケージ:''' build-essential, automake, gnupg, lintian, fakeroot, [[UbuntuPackagingGuideJa/gs-pbuilder|pbuilder]] In this example we will be using the GNU '''[[http://www.gnu.org/software/hello/hello.html|hello]]''' program as our example. You can download the source tarball from [[http://ftp.gnu.org/gnu/hello/hello-2.1.1.tar.gz|ftp.gnu.org]]. For the purposes of this example, we will be using the `~/hello/` directory. ここでは、GNU '''[[http://www.gnu.org/software/hello/hello.html|hello]]'''を例題として使用します。ソースファイルは [[http://ftp.gnu.org/gnu/hello/hello-2.1.1.tar.gz|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 .. }}} . [[attachment:UbuntuPackagingGuideJa/conventions/note.png|{{attachment:UbuntuPackagingGuideJa/conventions/note.png}}]] Unlike most '''apt-get''' commands, you do not need to have root privileges to get the source package, because it is downloaded to the current directory. In fact, it is recommended that you ''only'' use '''apt-get source''' as a regular user, because then you can edit files in the source package without needing root privileges. . [[attachment:UbuntuPackagingGuideJa/conventions/note.png|{{attachment:UbuntuPackagingGuideJa/conventions/note.png}}]] 他の'''apt-get'''コマンドと違い、このコマンドは現在のディレクトリにソースパッケージをダウンロードするだけなので、管理者権限は必要ありません。実際、あとでダウンロードしたソースパッケージのファイルを管理者権限なしに編集するために、'''apt-get source'''を一般ユーザで''のみ''実行することをおすすめします。 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. 1. Untar the .orig.tar.gz file into the current directory. 1. Apply the gunzipped .diff.gz to the unpacked source directory. 1. ソースパッケージをダウンロードします。ソースパッケージには、パッケージの概要やソースパッケージのmd5sum値を記した.dscファイル、ソフトウェア作成者のソースコードである.orig.tar.gzファイル、パッケージングの際にソースコードに対して適用されるパッチである.diff.gzなどが含まれています。 1. .orig.tar.gzファイルを現在のディレクトリに展開します。 1. .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 [[UbuntuPackagingGuideJa/basic-mistakes|the section called “Common Mistakes”]] for reasons. まず最初に、オリジナル(しばしば"上流(upstream)"とも呼ばれます)のソースアーカイブファイルを複製し、次の形式に名前を変更する必要があります:`_.orig.tar.gz`。これには二つの理由があります。一つはソースコードアーカイブの複製を作成することで、複製物をうっかり変更したり、削除してしまっても、すぐにダウンロードしたものに戻すことができます。もう一つは、オリジナルのソースアーカイブは本当に必要になるまでは修正を加えるべきでないという考えがあるからです。二つ目の理由については[[UbuntuPackagingGuideJa/basic-mistakes|“よくある間違い”のセクション]]を参照してください。 {{{ cp hello-2.1.1.tar.gz hello_2.1.1.orig.tar.gz tar -xzvf hello_2.1.1.orig.tar.gz }}} . [[attachment:UbuntuPackagingGuideJa/conventions/warning.png|{{attachment:UbuntuPackagingGuideJa/conventions/warning.png}}]] The underscore, "_", between the package name (hello) and the version (2.1.1), as opposed to a hyphen, "-", is very important. Your source package will incorrectly be built as a Debian native package. . [[attachment:UbuntuPackagingGuideJa/conventions/warning.png|{{attachment:UbuntuPackagingGuideJa/conventions/warning.png}}]] パッケージ名(hello)とバージョン(2.1.1)の間にあるハイフン("-")をアンダースコア("_")にすることはとても重要です。これを行わなければDebianパッケージとしてうまくビルドできないでしょう。 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のソースパッケージに必要不可欠なファイルである、`changelog`、`control`、`copyright`、`rules`を作成します。これらのファイルはオリジナルの(上流の)ソースコードからバイナリパッケージ(.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 [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 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リビジョンと呼ばれるもので、ソースファイルのバージョンが同じままで、パッケージのみを(不具合の修正などで)アップデートする時に使われます。 . [[attachment:UbuntuPackagingGuideJa/conventions/note.png|{{attachment:UbuntuPackagingGuideJa/conventions/note.png}}]] Ubuntu and Debian have slightly different package versioning schemes to avoid conflicting packages with the same source version. If a Debian package has been changed in Ubuntu, it has ''ubuntuX'' (where ''X'' is the Ubuntu revision number) appended to the end of the Debian version. So if the Debian '''hello''' package was changed by Ubuntu, the version string would be `2.1.1-1ubuntu1`. If a package for the application does not exist in Debian, then the Debian revision is ''0'' (''e.g.'', `2.1.1-0ubuntu1`). . [[attachment:UbuntuPackagingGuideJa/conventions/note.png|{{attachment:UbuntuPackagingGuideJa/conventions/note.png}}]] UbuntuとDebianでは、同じソースファイルのバージョンをパッケージにする際に衝突が起きないように、パッケージのバージョン番号の付け方が少し違います。DebianパッケージがUbuntuで修正された場合は、Debianのバージョンの後ろに''ubuntuX''(ここで''X''はUbuntuのリビジョン番号です)を追加します。例えば、このDebian '''hello'''パッケージがUbuntuで修正された場合は、そのバージョンは`2.1.1-1ubuntu1`となります。そのアプリケーションのパッケージがDebianに存在しない場合は、Debianのリビジョン番号は''0''であるとして扱います(''例えば''、`2.1.1-0ubuntu1`)。 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-get'''や'''synaptic'''、'''aptitude'''など)が利用する情報、ビルド時の依存情報、メンテナに関する情報などなどが含まれています。 For the Ubuntu '''hello''' package, the control file looks something like: Ubuntu '''hello'''パッケージのcontrolファイルは次のようになっています: {{{ Source: hello Section: devel Priority: optional Maintainer: Captain Packager 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: 最初の段落にはソースパッケージの情報を入力します。それぞれの行については以下のようになっています: * '''Source:''' This is the name of the source package, in this case, ''hello''. * '''Source:''' ソースパッケージの名前です。今回の場合は''hello''になります。 * '''Section:''' The apt repositories are split up into sections for ease of browsing and categorization of software. In this case, '''hello''' belongs in the ''devel'' section. * '''Section:''' aptレポジトリは、ソフトウェアの閲覧と分類を容易にするため、いくつかのセクションに分類されています。今回の'''hello'''は''devel''セクションに属しています。 * '''Priority:''' This sets the importance of the package to users. It should be one of the following: * '''Priority:''' ここでは、そのパッケージの重要度が指定されます。以下のうちの一つを選択してください: * '''Required''' - packages that are essential for the system to work properly. If they are removed it is highly likely that your system will break in an unrecoverable way. * '''Required''' - システムが正しく動作するために必要不可欠なパッケージです。このパッケージを削除することは、高確率でシステムが回復不能な状態になることを意味します。 * '''Important''' - minimal set of packages for a usable system. Removing these packages will not produce an unrecoverable breakage of your system, but they are generally considered important tools without which any Linux installation would be incomplete. Note: This does not include things like Emacs or even the X Window System. * '''Important''' - システムを利用するために必要最小限のパッケージに指定します。これらのパッケージを削除してもシステムが回復不能な状態に陥ることはありませんが、一般的にインストールしないとLinuxシステムとしては不完全であると考えられる重要なツールです。注意:EmacsやX Window Systemでさえ、ここには含まれません。 * '''Standard''' - Somewhat self explanatory. * '''Standard''' - そのままの意味です。 * '''Optional''' - in essence this category is for non-required packages, or the bulk of packages. However, these packages should not conflict with each other. * '''Optional''' - 基本的にこのカテゴリには、必須ではないパッケージや大半のパッケージが属しています。しかしながら、これらのパッケージはお互いに衝突しないようになっているべきです。 * '''Extra''' - packages that may conflict with packages in one of the above categories. Also used for specialized packages that would only be useful to people who already know the purpose of the package. * '''Extra''' - 上記カテゴリのどれかに属するパッケージと衝突しているパッケージが属します。そのパッケージの目的を既に知っている人にのみ役に立つような、特別なパッケージにも使われます。 * '''Maintainer:''' The package maintainer with email address. * '''Maintainer:''' パッケージメンテナとそのメールアドレスを記載します。 * '''Standards-Version:''' The version of the [[http://www.debian.org/doc/debian-policy/|Debian Policy]] to which the package adheres (in this case, version 3.6.1). An easy way to find the current version is ''apt-cache show debian-policy | grep Version''. * '''Standards-Version:''' そのパッケージが順守している[[http://www.debian.org/doc/debian-policy/|Debianポリシー]]のバージョン(今回の場合は3.6.1)を指定します。最新のバージョンを知る簡単な方法は''apt-cache show debian-policy | grep Version''を実行することです。 * '''Build-Depends:''' One of the most important fields and often the source of bugs, this line lists the binary packages (with versions if necessary) that need to be installed in order to create the binary package(s) from the source package. Packages that are essential are required by ''build-essential'' and do not need to be included in the Build-Depends line. In the case of '''hello''', all the needed packages are a part of build-essential, so a Build-Depends line is not needed. The list of build-essential packages can be found at `/usr/share/doc/build-essential/list`. * '''Build-Depends:''' もっとも重要で、しばしば不具合の原因にもなるこの行は、ソースパッケージからバイナリパッケージを作成する際に必要になる、バイナリパッケージ(と必要ならそのバージョン)の一群を指定します。''build-essential''やそれによって要求されるようなパッケージは、Build-Dependsに書く必要はありません。'''hello'''の場合は、必要なパッケージはすべてbuild-essentialの一部なので、Build-Dependsの行は必要ありません。build-essentialによってインストールされるパッケージのリストは、`/usr/share/doc/build-essential/list`で見ることができます。 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: 二つ目の段落にはソースから生成されるバイナリパッケージの情報を記載します。そのソースパッケージから複数のバイナリパッケージを生成する場合は、その''それぞれ''について、一つのセクションが必要になります。それぞれの行については以下のようになっています: * '''Package:''' The name for the binary package. Many times for simple programs (such as '''hello'''), the source and binary packages' names are identical. * '''Package:''' そのバイナリパッケージの名前です。('''hello'''のような)多くのシンプルなプログラムの場合、ソースパッケージとバイナリパッケージの名前はまったく同じになります。 * '''Architecture:''' The architectures for which the binary package(s) will be built. Examples are: * '''Architecture:''' そのバイナリパッケージがビルドされたアーキテクチャを指定します。例えば: * '''all''' - The source is ''not'' architecture-dependent. Programs that use Python or other interpreted languages would use this. The resulting binary package would end with `_all.deb`. * '''all''' - アーキテクチャに''依存しない''パッケージです。Pythonやその他のスクリプト言語を利用したプログラムなどで指定されます。生成されたバイナリパッケージ名の最後は、`_all.deb`となります。 * '''any''' - The source ''is'' architecture-dependent and should compile on all the supported architectures. There will be a .deb file for each architecture (`_i386.deb` for instance) * '''any''' - アーキテクチャに''依存し''、サポートされるすべてのアーキテクチャでコンパイル可能であるべきパッケージです。生成されたそれぞれの.debファイル名には、(例えば`_i386.deb`のように)それぞれのアーキテクチャが記載されます。 * A subset of architectures (i386, amd64, ppc, etc.) can be listed to indicate that the source is architecture-dependent and does not work for all architectures supported by Ubuntu. * アーキテクチャのリストを指定した場合(i386, amd64, ppcなど)、そのソースはアーキテクチャに依存しているが、Ubuntuがサポートするすべてのアーキテクチャで動作するわけではないことを意味します。 * '''Depends:''' The list of packages that the binary package depends on for functionality. For '''hello''', we see `${shlibs:Depends}`, which is a variable that substitutes in the needed shared libraries. See the `dpkg-source` man page for more information. * '''Depends:''' そのバイナリパッケージが機能するために必要なパッケージのリストを指定します。'''hello'''の場合、`${shlibs:Depends}`と書いてありますが、この変数は必要な共有ライブラリに置き換えられます。詳しいことは`dpkg-source`のManページを参照してください。 * '''Recommends:''' Used for packages that are highly recommended and usually are installed with the package. Some package managers, most notably '''aptitude''', automatically install Recommended packages. * '''Recommends:''' 普通はそのパッケージと一緒にインストールされるような、高く推奨されるパッケージを指定します。パッケージマネージャによっては、とりわけ'''aptitude'''では、推奨パッケージ(recommended package)も自動でインストールします。 * '''Suggests:''' Used for packages that are similar or useful when this package is installed. * '''Suggests:''' 一緒にインストールすると便利なパッケージを指定します。 * '''Conflicts:''' Used for packages that will conflict with this package. Both cannot be installed at the same time. If one is being installed, the other will be removed. * '''Conflicts:''' そのパッケージと衝突(conflict)するようなパッケージを指定します。そのため、同時にインストールすることはできません。もし片方がインストールされた場合、他方は削除されるでしょう。 * '''Description:''' Both short and long descriptions are used by package managers. The format is: * '''Description:''' パッケージマネージャで利用される、短い概要と長い概要を記載します。その形式は: {{{ Description: <一行で書かれた概要> <複数行に渡って書かれたより詳しい説明> }}} Note that there is one space at the beginning of each line in the long description. More information on how to make a good description can be found at [[http://people.debian.org/~walters/descriptions.html]]. 長い概要では、それぞれの行の先頭に一つの空白を含める必要があります。より良い概要の書き方については、[[http://people.debian.org/~walters/descriptions.html]]を参照してください。 <> == copyright == 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} {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`を流用できます: {{{ #!/usr/bin/make -f # 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 && 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) && 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の設定と、デバッグ用の`noopt`と`nostrip` 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 && 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) && 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/DEBIAN`と`debian/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. `postinst`と`prerm`ファイルは、メンテナスクリプトと呼ばれるものの一例です。それぞれ、パッケージのインストール後、パッケージの削除前に実行されるシェルスクリプトになっています。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鍵で署名されます。 . [[attachment:UbuntuPackagingGuideJa/conventions/warning.png|{{attachment:UbuntuPackagingGuideJa/conventions/warning.png}}]] If you do not have a '''gpg''' key set up you will get an error from  '''debuild'''. You can either set up a '''gpg''' key or use the ''-us -uc'' keys with '''debuild''' to turn off signing. However, you will not be able to have your packages uploaded to Ubuntu without signing them. . [[attachment:UbuntuPackagingGuideJa/conventions/warning.png|{{attachment:UbuntuPackagingGuideJa/conventions/warning.png}}]] '''gpg'''鍵を設定していない場合は、'''debuild'''からエラーが表示されるでしょう。'''gpg'''鍵を設定してもいいですが、'''debuild'''に''-us -uc''オプションを与えることで、署名をしないことも可能です。ただし、署名をしない限りUbuntuにパッケージをアップロードすることはできません。 . [[attachment:UbuntuPackagingGuideJa/conventions/tip.png|{{attachment:UbuntuPackagingGuideJa/conventions/tip.png}}]] To make sure '''debuild''' finds the right '''gpg''' key you should set the DEBFULLNAME and DEBEMAIL environment variables (in your `~/.bashrc` for instance) to the name and email address you use for your '''gpg''' key and in the `debian/changelog` . Some people have reported that they were unable to get '''debuild''' to find their '''gpg''' key properly, even after setting the above environment variables. To get around this you can give '''debuild''' the ''-k'' flag where is your '''gpg''' key ID. . [[attachment:UbuntuPackagingGuideJa/conventions/tip.png|{{attachment:UbuntuPackagingGuideJa/conventions/tip.png}}]] '''debuild'''が正しい'''gpg'''鍵を見つけるためには、(例えば`~/.bashrc`などで)環境変数DEBFULLNAMEとDEBEMAILに'''gpg'''鍵と`debian/changelog`で使用した名前とメールアドレスを与えておく必要があります。 . ただし、この設定を行っても'''debuild'''が正しい'''gpg'''鍵を見つけられないという報告もあります。その場合は、'''debuild'''実行時に''-k''フラグを与えてください。は'''gpg'''鍵のIDに置き換えてください。 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 }}} ||<:20%>,,<=,, ||<:60%>||<:20%> ,,=>,,|| ||<:20%>[[UbuntuPackagingGuideJa/basic-chap|基本的なパッケージング]]||<:60%>'''一からパッケージングする'''||<:20%> [[UbuntuPackagingGuideJa/basic-debhelper|Debhelperによるパッケージング]]||