2 debhelper 論その 1 Debhelper とは何か. 存在意義は何か.

上川      
___________________________________________________________________________________________________________________________

2.1 Debian package の構成要件

Debian Package のソースパッケージには下記ファイルが必要です. 全てのファイルについては規定のフ ォー マ ット が あ り ま す .

emacs で編集するのであれば, devscripts-el パッケージをインストールすると編集しやすくなっています . vi を利用しているのであれば, devscripts パッケージを利用すると, 各ファイルを編集しやすいで す .

パッケージの作成の本質は, ディレクトリ以下にアプリケーションをインストールし, それ以下のファイ ル を tar でかためて, deb ファイルのなかにいれることです. その他に制御情報もありますが, それにつ い て は 後 日 .

例えば, debian/tmp/以下に / 以下にインストールされるはずのファイルを配置することでパッケージを 作 成 で き ま す . debian/tmp/usr/bin/binary-test というファイルを作成して, debian/tmp ディレクトリ を 指 定 し て dpkg-deb コマンドを実行してできたパッケージをインストールしたら/usr/bin/binary-testに フ ァイ ル が イ ン ス ト ー ル さ れ ま す .

2.2 dh-make

アップストリームからのソースパッケージから, Debian 用のパッケージのテンプレートを作成し ます.

さて, dh-make ではどんなファイルが作成されるのでしょうか.

なんでもないサンプルファイルを作成して試しに実行してみます.


[02:11:56]ibookg4:/tmp/dh> find -ls
 94712    0 drwxr-xr-x   3 dancer   dancer         80  1  27 02:08 .
 94686    4 -rw-r--r--   1 dancer   dancer        156  1  27 02:07 ./test-source_0.1.orig.tar.gz
 94672    0 drwxr-xr-x   2 dancer   dancer         60  1  27 02:07 ./test-source-0.1
 94675    0 -rw-r--r--   1 dancer   dancer          0  1  27 02:07 ./test-source-0.1/Makefile

dh-make コマンドをうつと, どんなバイナリを作成するのか, という点を聞かれます.


[02:13:42]ibookg4:/tmp/dh/test-source-0.1> dh_make

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

Maintainer name : Junichi Uekawa
Email-Address   : dancer@debian.org
Date            : Thu, 27 Jan 2005 02:13:46 +0900
Package Name    : test-source
Version         : 0.1
Type of Package : Single
Hit <enter> to confirm:
Done. Please edit the files in the debian/ subdirectory now. You should also
check that the test-source Makefiles install into $DESTDIR and not in / .
[02:13:51]ibookg4:/tmp/dh/test-source-0.1>

[02:27:24]ibookg4:/tmp/dh/test-source-0.1> ls debian/
README.Debian  dirs    manpage.sgml.ex  rules
changelog      docs    manpage.xml.ex   test-source-default.ex
compat        emacsen-install.ex  menu.ex     test-source.doc-base.EX
conffiles.ex   emacsen-remove.ex   postinst.ex     watch.ex
control        emacsen-startup.ex  postrm.ex
copyright      init.d.ex    preinst.ex
cron.d.ex      manpage.1.ex    prerm.ex

大量にファイルができます. これらのファイルで, .ex で終了しているのはサンプルファイルで, 特に必 要でないのなら削除します.

debian/rules として, 次のようなファイルができます.

#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
# This file was originally written by Joey Hess and Craig Small.
# As a special exception, when this file is copied by dh-make into a
# dh-make output file, you may use that output file without restriction.
# This special exception was added by Craig Small in version 0.37 of dh-make.

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1




CFLAGS = -Wall -g

ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
CFLAGS += -O0
else
CFLAGS += -O2
endif

configure: configure-stamp
configure-stamp:
dh_testdir
# Add here commands to configure the package.

touch configure-stamp


build: build-stamp

build-stamp: configure-stamp
dh_testdir

# Add here commands to compile the package.
$(MAKE)
#docbook-to-man debian/test-source.sgml > test-source.1

touch build-stamp

clean:
dh_testdir
dh_testroot
rm -f build-stamp configure-stamp

# Add here commands to clean up after the build process.
-$(MAKE) clean

dh_clean

install: build
dh_testdir
dh_testroot
dh_clean -k
dh_installdirs

# Add here commands to install the package into debian/test-source.
$(MAKE) install DESTDIR=$(CURDIR)/debian/test-source


# Build architecture-independent files here.
binary-indep: build install
# We have nothing to do by default.

# Build architecture-dependent files here.
binary-arch: build install
dh_testdir
dh_testroot
dh_installchangelogs
dh_installdocs
dh_installexamples
# dh_install
# dh_installmenu
# dh_installdebconf
# dh_installlogrotate
# dh_installemacsen
# dh_installpam
# dh_installmime
# dh_installinit
# dh_installcron
# dh_installinfo
dh_installman
dh_link
dh_strip
dh_compress
dh_fixperms
# dh_perl
# dh_python
# dh_makeshlibs
dh_installdeb
dh_shlibdeps
dh_gencontrol
dh_md5sums
dh_builddeb

binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install configure

また, debian/control として下記のようなファイルができます.

Source: test-source
Section: unknown
Priority: optional
Maintainer: Junichi Uekawa <dancer@debian.org>
Build-Depends: debhelper (>= 4.0.0)
Standards-Version: 3.6.1

Package: test-source
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}
Description: <insert up to 60 chars description>
 <insert long description, indented with spaces>

他に必要なファイルとして, debian/changelog などがあります.

2.3 dh-xxxx のオーバビュー

各論に入るまでに dh-xxxx が一般的にどういう動作をするものなのかを説明します. おおざっぱにいうと 二種類の動作形態があります.

Debian パッケージを作成する一連の動作の中で, debian/パッケージ名 というディレクトリ にインストール用のイメージを作成します. そのディレクトリに対して, debian/機能. パッケージ名 というファイルで指定した内容を実施してくれるのが dh-機能スクリプト です.

また, 別の機能として, コマンドラインオプションに指定されたものに対しても操作し ます.

2.4 簡単なところから, dh-installman

man ページをインストールする dh-installman を例にとって, 説明します.

man ページは各パッケージのセクションに応じたディレクトリにインストールします. セクション情報 は, man ページの roff ソースの最初のところに記述してあります.


.TH "pbuilder" 8"2004 Apr 4" "Debian" "pbuilder"

この man ページはセクション 8 のマニュアルなので, FHS に従い, /usr/share/man/man8/という ディレクトリにインストールする必要があります.

下記の実行例は, インストール対象のパッケージ名を指定して, インストールするファイルを指定した 場合です.

 dh_installman -ppbuilder-uml pbuilder-user-mode-linux.1 \
 pbuilder-uml.conf.5 pdebuild-user-mode-linux.1

上記のコマンドを入力すると

debian/pbuilder-uml/usr/share/man/man1/pbuilder-user-mode-linux.1 などにファイルがコ ピーされます.

debhelper の概念で重要なのは, このインストール先のディレクトリがどこであるかと いうことについては debhelper 側で管理しており, たとえポリシーに変更が発生しても, debhelper のみを変更すればよく, パッケージスクリプト側への変更は最小にできる, という点 です.

例えば, マニュアルページの例でいくと, 以前の標準では, /usr/man/man1/などにインストールす ることがポリシーだったのですが, それが変更になり, /usr/share/man/man1 になりま した.

東 京 エ リ ア Debian 勉強会 2005 _________________________________________________________

PIC