LoginSignup
9
8

More than 5 years have passed since last update.

debian package作成方法

Posted at

debian package

sourceを使ったpackageの再buildにはいろいろな要因が想定される。特定のfixをbackportしたい場合、また、defaultでは配布されていない特定のversionを使用したい場合など、など。scratchからdebian packageを作る場合や、sourceをdownloadしてdebian packageを再buildする方法をまとめておく。その中で、debian package固有の情報などもメモしておく。

debian package tools

sudo apt-get install devscripts

sourceの取得

# apt-get source <package>
apt-get source stress

sourceを取得すると以下のファイルも同時にdownloadされる。
・stress_1.0.4-1.debian.tar.xz: packageのdebian情報をzipしたもの
・stress_1.0.4-1.dsc: Debian Source Control ファイル
・stress_1.0.4.orig.tar.gz: packageのsource code

packageの作成① (source base update)

・dch commandを使用して、version番号(changelog)を更新する。
・build optionなどの修正が必要な場合は、debian/rulesを修正する。debian/rules はpackage build作業の各段階を動作させるもので、最も単純に書かれている場合、初期設定 (./configure …) や実際のbuild ($(MAKE) … や make …) を実行するcommandが記載されているだけ。

#!/usr/bin/make -f
#export DH_VERBOSE=1

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

%:
    dh $@ --with autoreconf

・修正内容によっては、debian/controlファイルの修正も必要。debian/control ファイルには生成されるpackageの説明が含まれでいる。特に、debian/control ファイルにはpackageのbuild時点で満足されなければいけない依存関係のリストを制御する Build-Depends 行が含まれます。

Source: stress
Section: devel
Priority: optional
Maintainer: Joao Eriberto Mota Filho <eriberto@debian.org>
Build-Depends: debhelper (>= 9), dh-autoreconf
Standards-Version: 3.9.6
Homepage: http://people.seas.harvard.edu/~apw/stress
Vcs-Browser: http://anonscm.debian.org/cgit/collab-maint/stress.git
Vcs-Git: git://anonscm.debian.org/collab-maint/stress.git

Package: stress
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}
Description: tool to impose load on and stress test a computer system
 'stress' is a tool that imposes a configurable amount of CPU, memory, I/O,
 or disk stress on a POSIX-compliant operating system and reports any errors
 it detects.
 .
 'stress' is not a benchmark.  It is a tool used by system administrators to
 evaluate how well their systems will scale, by kernel programmers to evaluate
 perceived performance characteristics, and by systems programmers to expose
 the classes of bugs which only or more frequently manifest themselves when
 the system is under heavy load.

・Build-Dependsのinstall
apt-getを使うことで、あるpackageの Build-Depends フィールドに指定されているすべてのpackageをinstallすることが可能です。apt-get は /etc/apt/sources.list ファイルの deb-src 行で指定されているdistributionに含まれるpackageの Build-Depends フィールドに指定されているpackageをinstallします。これを行うには、apt-get build-dep source-package commandを実行するだけです。

・packageのbuild

dpkg-buildpackage -us -uc

packageの作成② (from scratch)

ここでは例として、direnvをdebian packageにしてみます。

・direnvのsource取得とbuildを実行

git clone https://github.com/direnv/direnv
cd direnv
git checkout refs/tags/v2.13.1
make
tomoyafujita-Inspiron-620s@~/DVT/debian/usr/bin/direnv >pwd
/home/tomoyafujita/DVT/debian/usr/bin/direnv
# debian packageを作成するためのWORKは、/home/tomoyafujita/DVT/debian

・DEBIAN/conrtol作成

Package: direnv
Maintainer: Tomoya Fujita <tomoya.fujita@example.com>
Architecture: amd64
Version: 2.13.1
Description: Environment switcher for the shell
 direnv hooks into the shell to load or unload environment variables
 depending on the current directory.

Category Comments
Package パッケージ名
Maintainer deb パッケージのメンテナの名前とメールアドレス
Arch インストール可能なアーキテクチャ
Version バージョン
Descript パッケージの説明

・packageの作成

fakeroot dpkg-deb --build ~/DVT/debian/usr/bin/direnv .

dpkg -c direnv_2.13.1_amd64.deb

Tips

・debian/rules ファイル

Category Comments
clean ビルド時に生成されるファイルをクリアする
build ソースコードをビルドする
build-arch アーキテクチャに依存するビルドをおこなう
build-indep アーキテクチャに依存しないビルドをおこなう
install ビルドしたバイナリや作業用ディレクトリにインストールする
binary バイナリパッケージ作成
binary-arch アーキテクチャに依存するバイナリパッケージ作成
binary-indep アーキテクチャに依存しないバイナリパッケージ作成
get-orig-source オリジナルの最新ソースアーカイブをダウンロード
patch パッチを実行する
9
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
8