## page was renamed from UbuntuPackagingGuideJa/basic-devhelper #title Debhelperによるパッケージング . [[attachment:UbuntuPackagingGuideJa/conventions/important.png|{{attachment:UbuntuPackagingGuideJa/conventions/important.png}}]] '''Requirements:''' The requirements from [[UbuntuPackagingGuideJa/basic-scratch|the section called “一からパッケージングする”]] plus debhelper and dh-make . [[attachment:UbuntuPackagingGuideJa/conventions/important.png|{{attachment:UbuntuPackagingGuideJa/conventions/important.png}}]] '''必要なパッケージ:''' [[UbuntuPackagingGuideJa/basic-scratch|“一からパッケージングする”セクション]]でインストールしたパッケージに加えて、debhelperとdh-makeが必要になります 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. パッケージ作成者は、前のセクションでやったように、一からパッケージを作成することがたまにあります。気づいているかもしれませんが、例えば`rules`ファイルの情報や作業の多くは、ほとんどのパッケージで共通です。より簡単で効率的にパッケージングを行うために、それらの作業を補助してくれる'''debhelper'''を使うことができます。debhelperはパッケージ作成作業を自動化してくれる、(''dh_''で始まる)Perlスクリプト集です。これらのスクリプトを利用すれば、Debianパッケージの作成はとてもシンプルになります。 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のソースコードを取得します: {{{ wget http://ftp.gnu.org/gnu/hello/hello-2.1.1.tar.gz }}} Then, get the Ubuntu source package: Ubuntuのソースパッケージを取得します: {{{ 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. 前回の例では、上流のソースアーカイブを`hello_2.1.1.orig.tar.gz`に複製しましたが、今回は'''dh_make'''がそれを行ってくれます。また、'''dh_make'''はdebian/ディレクトリのテンプレートも作成してくれます。 The only thing you have to do is rename the source folder, so it is in the form of ''-'' where packagename is lowercase. In this case, we want to name the package '''hello-debhelper'''. So, we rename the directory: やらなければいけないのはソースディレクトリを、''<パッケージ名>-<バージョン>''の形式に修正することです。ここでパッケージ名はすべて小文字にします。今回の場合だと、'''hello-debhelper'''という名前にしたいので、ディレクトリを次のように変更します: {{{ mv hello-2.1.1 hello-debhelper-2.1.1 }}} Now, from the package's directory, run '''dh_make''': パッケージディレクトリから、'''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: '''dh_make'''は、パッケージについていくつか質問しますので、それに答えていきます: {{{ Type of package: single binary, multiple binary, library, kernel module or cdbs? [s/m/l/k/b] s }}} {{{ Maintainer name : Captain Packager Email-Address : packager@coolness.com Date : Thu, 6 Apr 2006 10:07:19 -0700 Package Name : hello Version : 2.1.1 License : blank Type of Package : Single Hit to confirm: Enter }}} . [[attachment:UbuntuPackagingGuideJa/conventions/caution.png|{{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|{{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, 1. Creates the basic files needed in `debian/` and many template files (.ex) that may be needed. 1. 親ディレクトリに`hello_2.1.1.orig.tar.gz`が作成されます。 1. `debian/`ディレクトリに必要な基本的なファイルと、必要になると思われる多くのテンプレートファイル(.ex)が作成されます。 The '''Hello''' program is not very complicated, and as we have seen in [[UbuntuPackagingGuideJa/basic-scratch|the section called “一からパッケージングする”]], packaging it does not require much more than the basic files. Therefore, let us remove the `.ex` files: '''hello'''プログラムはそれほど複雑ではないので、[[UbuntuPackagingGuideJa/basic-scratch|“一からパッケージングする”セクション]]で見たように、基本的なファイル以上のものは必要ありません。そのため、`.ex`ファイルは削除します: {{{ cd debian rm *.ex *.EX }}} For '''hello''', you will also not need some of the files into the `debian` directory: '''hello'''では、`debian`ディレクトリにあるいくつかのファイルも必要ありません: * `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 [[UbuntuPackagingGuideJa/appendix-examples|the section called “'''dh_make''' example files”]]. 多くのパッケージでは、これらのファイルが必要になることを忘れないでください。これらのファイルについては[[UbuntuPackagingGuideJa/appendix-examples|“'''dh_make'''の例”セクション]]を参照してください。 At this point, you should have only `changelog`, `compat`, `control`, `copyright`, and `rules` files in the `debian` directory. From [[UbuntuPackagingGuideJa/basic-scratch|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. 現時点で、`debian`ディレクトリには`changelog`、`compat`、`control`、`copyright`、`rules`だけが存在するはずです。[[UbuntuPackagingGuideJa/basic-scratch|“一からパッケージングする”セクション]]と違うのは`compat`ファイルだけでしょう。これは、'''debhelper'''のバージョン(今回の場合は4)を保存するファイルです。 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'''から'''hello-debhelper'''に変更するため、`changelog`を少し修正します。 {{{ 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`ファイルに対して修正しなくてはいけないのは、パッケージ名('''hello'''を'''hello-debhelper'''に置き換える)と、ソースパッケージの''Build-Depends''に'''debhelper (>= 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 [[UbuntuPackagingGuideJa/basic-scratch|the section called “一からパッケージングする”]]. We will also copy the `rules` file so we can inspect it. `copyright`ファイルと`postinst`スクリプト、`prerm`スクリプトは[[UbuntuPackagingGuideJa/basic-scratch|“一からパッケージングする”セクション]]から変わりはないので、Ubuntuの'''hello-debhelper'''のものを、そのままコピーできます。`rules`ファイルも、確認のためにコピーしておきます。 {{{ 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 [[UbuntuPackagingGuideJa/basic-scratch#rules|the section called “rules”]]). 最後の`rules`ファイルを確認すると、'''debhelper'''スクリプトの威力がわかります。'''debhelper'''版の`rules`ファイルはいくらか小さくなっているのです([[UbuntuPackagingGuideJa/basic-scratch#rules|“rules”セクション]]にあるファイルが72行なのに対して、54行になっています)。 The '''debhelper''' version looks like: '''debhelper'''版は次のようになっています: {{{ #!/usr/bin/make -f package = hello-debhelper CC = gcc CFLAGS = -g -Wall ifeq (,$(findstring noopt,$(DEB_BUILD_OPTIONS))) CFLAGS += -O2 endif #export DH_VERBOSE=1 clean: dh_testdir dh_clean rm -f build -$(MAKE) -i distclean install: build dh_clean dh_installdirs $(MAKE) prefix=$(CURDIR)/debian/$(package)/usr \ mandir=$(CURDIR)/debian/$(package)/usr/share/man \ infodir=$(CURDIR)/debian/$(package)/usr/share/info \ install build: ./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 [[UbuntuPackagingGuideJa/appendix-debhelper|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_installdocs'''と'''dh_installchangelogs''')、ビルド後の掃除('''dh_clean''')などの作業が自動的に行われていることに気づくでしょう。'''hello'''よりも複雑な多くのパッケージでも、`rules`ファイルはそれほど大きくなりません。'''debhelper'''スクリプトが多くの作業を行ってくれるからです。完全な'''debhelper'''スクリプトの一覧は、[[UbuntuPackagingGuideJa/appendix-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: 以上で、'''hello-debhelper'''用の`debian`ディレクトリにあるファイルの解説は終了です。これでソースパッケージ(とバイナリパッケージ)のビルドが行えます。最初に、ソースファイルを展開したディレクトリに移動しましょう: {{{ cd .. }}} Now we build the source package using '''debuild''', a wrapper script for '''dpkg-buildpackage''': '''debuild'''を使ってソースパッケージを作成します、これは'''dpkg-buildpackage'''のラッパースクリプトです: {{{ debuild -S }}} the binary package, using '''pbuilder''': '''pbuilder'''を使ってバイナリパッケージを作成します: {{{ sudo pbuilder build ../*.dsc }}} and finally check the source package for common mistakes using '''lintian''': 最後に、'''lintian'''を使ってソースパッケージのよくある間違いをチェックします: {{{ cd .. lintian -i *.dsc }}} ||<:20%>,,<=,, ||<:60%>||<:20%> ,,=>,,|| ||<:20%>[[UbuntuPackagingGuideJa/basic-scratch|一からパッケージングする]]||<:60%>'''Debhelperによるパッケージング'''||<:20%> [[UbuntuPackagingGuideJa/basic-cdbs|CDBSによるパッケージング]]||