Scroll to navigation

DH(1) Debhelper DH(1)

名前

dh - debhelper コマンドシーケンサー

書式

dh sequence [--with addon[,addon ...]] [--list] [debhelper オプション]

説明

dh は一連の debhelper コマンドを実行します。debian/rules ファイルに記載されたターゲットに対応する sequenceをサポートします。サポートするターゲット: build-arch, build-indep, build, clean, install-indep, install-arch, install, binary-arch, binary-indep, binary です。

override ターゲット

dh が利用する debian/rules にて、override ターゲットを指定することで、呼び出される一連の処理途中で動作を変更できます。

ターゲット dh_command を変更するためには、override_dh_command というターゲットを rule ファイルに記載します。こちらが指定されていると、dh_command が動作する代わりに override_dh_command ターゲットを呼び出します。override ターゲットでは、コマンドにオプションを追加したり、コマンド全てを置き換えたりできます。後に例を挙げます。

アーキテクチャ依存パッケージを作るときのみ、あるいはアーキテクチャ非依存パッケージを作るときのみ動作するように override ターゲットを定義することもできます。その場合、override_dh_command-arch や、override_dh_command-indep を使ってください (なお、この機能を使うには、Build-Depends 行で debhelper バージョン 8.9.7 以上を指定する必要があります)。

オプション

一連のコマンド中の適切な位置で実行するアドオンを、debhelper コマンドへ指定します。このオプションは繰り返し指定することもできますし、複数のアドオンをカンマ区切りで列挙して指定できます。このオプションは debhelper コマンドを提供するサードパーティ製パッケージと共に利用する時に使います。PROGRAMMING ファイルに、一連のアドオン用インターフェースについてのドキュメントがあります。

A Build-Depends relation on the package dh-sequence-addon implies a --with addon. This avoids the need for an explicit --with in debian/rules that only duplicates what is already declared via the build dependencies in debian/control. The relation can (since 12.5) be made optional via e.g. build-profiles. This enables you to easily disable an addon that is only useful with certain profiles (e.g. to facilitate bootstrapping).

Since debhelper 12.5, addons can also be activated in indep-only mode (via Build-Depends-Indep) or arch-only mode (via Build-Depends-Arch). Such addons are only active in the particular sequence (e.g. binary-indep) which simplifies dependency management for cross-builds.

Please note that addons activated via Build-Depends-Indep or Build-Depends-Arch are subject to additional limitations to ensure the result is deterministic even when the addon is unavailable (e.g. during clean). This implies that some addons are incompatible with these restrictions and can only be used via Build-Depends (or manually via debian/rules). Currently, such addons can only add commands to sequences.

--with とは逆に、指定されたアドオンを無効にします。このオプションは繰り返し指定することもできますし、アドオン名をカンマ区切りで指定もできます。
利用可能なアドオン一覧を表示する。

When called only with this option, dh can be called from any directory (i.e. it does not need access to files from a source package).

指定された一連の処理でのコマンドを表示しますが、表示だけして実際にはコマンドは実行しません。

通常、dh は何も実行しないであろうとわかっている動作コマンドをスキップすることに注意してください。--no-act を指定すると、一連の動作内でのコマンド一覧をすべて出力します。

dh に渡された他のオプションは、実行される各コマンドにも渡されます。これは、-v, -X, -N のようなオプションをセットするのに利用できます。また、他の特別なオプションについても同様となります。

使用例

コマンドを実際には動作させず、一連の動作でどのコマンドが実行されるかを見る:

        dh binary-arch --no-act

以下は非常にシンプルな rules ファイルです。ここではパッケージに対して追加オプション無しでデフォルトのコマンド群が呼び出されます。

        #!/usr/bin/make -f
        %:
                dh $@

特定の debhelper コマンドへオプションを渡したい事がよくあります。これを簡単に行う方法は、そのコマンドへ override を追加することです。

        #!/usr/bin/make -f
        %:
                dh $@
        override_dh_strip:
                dh_strip -Xfoo
        override_dh_auto_configure:
                dh_auto_configure -- --with-foo --disable-bar

dh_auto_configure(1)dh_auto_build(1) が処理をする際、何を処理すればよいか判断できないような変わったパッケージがたまに存在します。ここでは、dh_auto_configure(1)dh_auto_build(1) を実行せずに、代わりのコマンドを実行させる方法を示します。

        #!/usr/bin/make -f
        %:
                dh $@
        override_dh_auto_configure:
                ./mondoconfig
        override_dh_auto_build:
                make universe-explode-in-delight

別のよくある例として、特定の debhelper コマンドが実行される前後で手動で何かをしたい場合があります。

        #!/usr/bin/make -f
        %:
                dh $@
        # Example assumes debhelper/12.8 and compat 10+
        execute_after_dh_fixperms:
                chmod 4755 debian/foo/usr/bin/foo

If you are on an older debhelper or compatibility level, the above example would have to be written as.

        #!/usr/bin/make -f
        %:
                dh $@
        # Older debhelper versions or using compat 9 or lower.
        override_dh_fixperms:
                dh_fixperms
                chmod 4755 debian/foo/usr/bin/foo

Python tools are not run by dh by default, due to the continual change in that area. Here is how to use dh_python2.

        #!/usr/bin/make -f
        %:
                dh $@ --with python2

こちらは Perl による Module::Build ビルドシステムを強制的に使う方法です。これは、debhelper が誤ってパッケージが MakeMaker を使っていると認識する場合に必要となります。

        #!/usr/bin/make -f
        %:
                dh $@ --buildsystem=perl_build

以下に dh_auto_* コマンドがどこにパッケージソースがあるかを変更する例を載せます。これはサブディレクトリにソースが存在するようなパッケージで使います。

        #!/usr/bin/make -f
        %:
                dh $@ --sourcedirectory=src

dh_auto_* にサブディレクトリでビルドするように指定する方法を以下に示します。こちらを指定すると、clean 処理でこれらディレクトリが取り除かれるようになります:

        #!/usr/bin/make -f
        %:
                dh $@ --builddirectory=build

パッケージが並列ビルド可能であれば、互換性レベル 10 を使うか dh に --parallel を指定して下さい。すると dpkg-buildpackage -j が有効になります。

        #!/usr/bin/make -f
        %:
                dh $@ --parallel

パッケージが複数スレッドを使うと安定してビルド出来ない場合は、dh (あるいは関連する dh_auto_* コマンド)に --no-parallel を指定して下さい。

        #!/usr/bin/make -f
        %:
                dh $@ --no-parallel

ここでは、dh に、実行してほしくないコマンドを実行させないようにする方法を示します。その場合、それらのコマンドに対する override ターゲットを空にすることにより行います。

        #!/usr/bin/make -f
        %:
                dh $@
        # 実行させたくないコマンド:
        override_dh_auto_test override_dh_compress override_dh_fixperms:

ドキュメントパッケージを作成するのに時間がかかる場合があります。この場合、アーキテクチャ非依存用の override ターゲットを使ってビルドを分離することができます。こうすると、build-arch や binary-arch を実行するとき、ドキュメントパッケージのビルドが省略されます。

        #!/usr/bin/make -f
        %:
                dh $@
        override_dh_auto_build-indep:
                $(MAKE) -C docs
        # doc ターゲット実行時はテストは不要
        override_dh_auto_test-indep:
        override_dh_auto_install-indep:
                $(MAKE) -C docs install

上の例に加え、ファイルに chmod を実行しなければならないがそれはアーキテクチャ依存パッケージをビルドする際のみ必要で、ドキュメントのみをビルドする時には実行しないとしたらどうなるでしょうか。

        # Example assumes debhelper/12.8 and compat 10+
        execute_after_dh_fixperms-arch:
                chmod 4755 debian/foo/usr/bin/foo

内部動作

dh の内部動作に興味がある人向けに、以下に内部でどのように動作しているのかを記載します。

In compat 10 (or later), dh creates a stamp file debian/debhelper-build-stamp after the build step(s) are complete to avoid re-running them. It is possible to avoid the stamp file by passing --without=build-stamp to dh. This makes "no clean" builds behave more like what some people expect at the expense of possibly running the build and test twice (the second time as root or under fakeroot(1)).

Inside an override target, dh_* commands will create a log file debian/package.debhelper.log to keep track of which packages the command(s) have been run for. These log files are then removed once the override target is complete.

互換性レベル 9 とそれ以前では、各 debhelper コマンドは debian/package.debhelper.log に実行がうまく行ったものを記録します (これは dh_clean が消去します)。これにより、dh は既にどのコマンドが実行されたか、あるいはどのパッケージに対して実行されたか、何のコマンドを再びスキップすればよいのかがわかります。

Each time dh is run (in compat 9 or earlier), it examines the log, and finds the last logged command that is in the specified sequence. It then continues with the next command in the sequence.

dh に処理の流れの名前を指定することにより、debian/rules に記載した依存関係にあるターゲットも実行されます。例えば、"binary" という処理の流れを指定すると、"install" ターゲットも実行されます。

dh は、DH_INTERNAL_OPTIONS 環境変数をチェックし、override ターゲットの中で実行される debhelper コマンドに情報を渡します。この環境変数に記載されている内容は (実際には環境変数が存在していると) 、その環境変数の名前が示唆するとおり、どの時点でも debhelper コマンドの動作に影響を与えます。

build-indep, install-indep, binary-indep の一連の処理に記載されているコマンドには、アーキテクチャ非依存パッケージをビルドする時にだけ確実に作用するように -i オプションを使って情報が引き渡されます。build-arch, install-arch, binary-arch の一連の処理に対しては、-a にて引き渡され、アーキテクチャ依存パッケージにのみ確実に作用するように動作します。

参照

debhelper(7)

このプログラムは debhelper の一部です。

作者

Joey Hess <joeyh@debian.org>

2020-01-19 12.8