東京エリア Debian 勉強会 - Debian Package ハンズ …...東京エリアDebian 勉強会...

Preview:

Citation preview

. . . . . .

.

.. ..

.

.

東京エリア Debian勉強会Debian Packageハンズオン

岩松信洋 iwamatsu@debian.or.jpIRC nick: iwamatsu

2008年 03月 01日

. . . . . .

Agenda

. . . . . .

Agenda

今回の目的発表Debian Packageを作成する前の準備今回の生贄プログラムが動作を確認するDebian Packageの雛形を作るdebian/controlファイルの編集debian/changelogファイルの編集debian/copyrightファイルの編集debian/rulesファイルを編集するDebian Package の作成Debian Packageのテスト本日のまとめ終わりに質疑応答

. . . . . .

今 回 の 目的

. . . . . .

 シングルバイナリの DebianPackageが作成できるようになること。

. . . . . .

DebianPackageを作成する前の準備

. . . . . .

以下の環境変数を設定しておくと便利。

DEBFULLNAMEの設定Debian Packageのメンテナ名DEBEMAILの設定Debain Packageメンテナンス用のメールアドレス

. . . . . .

$ cat ˜/.bashrc--略--export DEBFULLNAME="Nobuhiro Iwamatsu"export DEBEMAIL=iwamatsu@nigauri.org--略--$ source ˜/.bashrc

. . . . . .

必要なパッケージ

最低限必要な必要なパッケージは以下の通り。

devscriptsdebhelperlintian/lindagccbinutilslibc6-devdh-make

あると便利なパッケージ

apt-filepbuilder

. . . . . .

今 回 の 生贄

. . . . . .

sl

==== ________ ____________D _| |_______/ \__I_I_____===__|_________||(_)--- | H\________/ | | =|___ ___| _________________/ | | H | | | | ||_| |_|| _| \_____A| | | H |__--------------------| [___] | =| || ________|___H__/__|_____/[][]˜\_______| | -| ||/ | |-----------I_____I [][] [] D |=======|____|________________________|_

__/ =| o |=-˜˜\ /˜˜\ /˜˜\ /˜˜\ ____Y___________|__|__________________________|_|/-=|___|| || || || |_____/˜\___/ |_D__D__D_| |_D__D__D_|\_/ \__/ \__/ \__/ \__/ \_/ \_/ \_/ \_/ \_/

. . . . . .

プログラムが動作を確認する

. . . . . .

まず、プログラムが動作するか確認しましょう。

$ tar -xf sl.tar$ cd sl$ make

. . . . . .

curses.hがないため、コンパイルに失敗しました。

$ tar -xf sl.tar$ cd sl$ makemakecc -O -o sl sl.c -lcurses -ltermcapsl.c:30:20: error: curses.h: No such file or directorysl.c: In function ’my_mvaddstr’:sl.c:42: error: ’ERR’ undeclared (first use in this function)sl.c:42: error: (Each undeclared identifier is reported only once........

. . . . . .

curses.hを持った Debian Packageが必要です。どのファイルがどのパッケージじよってインストールされるのか、調べるには apt-fileを使うと便利です。

# sudo apt-file update$ apt-file search /usr/include/curses.hlibncurses5-dev: usr/include/curses.h

. . . . . .

libncueses5-devパッケージをインストールして再度コンパイルしましょう。

# apt-get update# apt-get install libncurses5-dev$ makemakecc -O -o sl sl.c -lcurses -ltermcap.......

. . . . . .

コンパイルが通ったので、動作テストをしましょう。

% ./sl

. . . . . .

DebianPackageの 雛 形 を作る

. . . . . .

ディレクトリにバージョンがない場合はバージョンが付いたディレクトリ名に変更します。Debian Packageの雛形を作成するには、dh makeコマンドを使います。

$ tar -xf sl.tar$ mv sl sl-0.0.0$ cd sl-0.0.0$ dh_make

. . . . . .

iwamatsu@chimagu:˜/sl-0.0.0$ dh_make

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

. . . . . .

s: 一つの実行バイナリを提供するパッケージm: 2つ以上の実行バイナリを提供するパッケージl: ライブラリ用パッケージk: カーネルモジュール用パッケージb: cdbsを使ったパッケージ

. . . . . .

$ dh_make

Type of package: single binary, multiple binary,library, kernel module or cdbs?[s/m/l/k/b] sMaintainer name : Nobuhiro IwamatsuEmail-Address : iwamatsu@nigauri.orgDate : Thu, 21 Feb 2008 15:46:57 +0900Package Name : slVersion : 0.0.0License : blankType of Package : SingleHit <enter> to confirm:

. . . . . .

$ dh_make

Type of package: single binary, multiple binary,library, kernel module or cdbs?[s/m/l/k/b] sMaintainer name : Nobuhiro IwamatsuEmail-Address : iwamatsu@nigauri.orgDate : Thu, 21 Feb 2008 15:46:57 +0900Package Name : slVersion : 0.0.0License : blankType of Package : SingleHit <enter> to confirm:

Could not find sl_0.0.0.orig.tar.gzEither specify an alternate file to use with -f,or add --createorig to create one.

. . . . . .

xxx.orig.tar.gzがないと、エラーになります。–createorigオプションを加えて  dh makeを実行しましょう。

$ dh_make --createorig

. . . . . .

dh make実行後、debianディレクトリが作成されます。

$ ls ./debian/README.Debian control dirs emacsen-remove.exinit.d.lsb.ex manpage.xml.ex mogeri.doc-base.EXpreinst.ex watch.ex   changelog copyrightdocs emacsen-startup.ex manpage.1.exmenu.ex postinst.ex prerm.excompat cron.d.ex emacsen-install.exinit.d.ex manpage.sgml.ex sl-default.expostrm.ex rules

. . . . . .

*.ex / *.EXはサンプルなので削除します。

$ rm -rf ./debian/*.ex$ rm -rf ./debian/*.EX

. . . . . .

最低限必要な debianディレクトリ以下にあるファイルは以下の通りです。。

README.Debian –  PackageのREADMEcontrol – Packageの説明、ビルドに必要な情報などdirs – Packageで利用するディレクトリを記述changelog – Packageの変更履歴copyright – Packageのコピーライトdocs –ドキュメントファイル一覧rules – Package作成用のスクリプト (Makefile)compat – debhelperのバージョン

. . . . . .

debian/controlファイルの編集

. . . . . .

Source: slSection: gamePriority: extraMaintainer: Nobuhiro Iwamatsu <iwamatsu@nigauri.org>Build-Depends: debhelper (>= 5),libncurses5-devStandards-Version: 3.7.2

Package: slArchitecture: anyDepends: ${shlibs:Depends}, ${misc:Depends}Description: Key type correction softwareKey type correction software for ’ls’ command.

. . . . . .

debian/changelogファイルの編集

. . . . . .

次に Debianの Changelogを編集しましょう。編集するには、dchコマンドを使います。

$ dchsl (0.0.0-1) unstable; urgency=low

* Initial release

-- Nobuhiro Iwamatsu <iwamatsu@nigauri.org> \Sun, 24 Feb 2008 01:01:53 +0900

. . . . . .

debian/copyrightファイルの編集

. . . . . .

This package was debianized by \Nobuhiro Iwamatsu <iwamatsu@nigauri.org> onThu, 21 Feb 2008 16:13:47 +0900.

It was downloaded from http://www.is.titech.ac.jp/˜toyoda/

Upstream Author:Toyoda Masashi <toyoda@is.titech.ac.jp>

Copyright:

Copyright 1993,1998 Toyoda Masashi (toyoda@is.titech.ac.jp)

License:Everyone is permitted to do anything on this programincluding copying,modifying, and improving, unless you try to pretend thatyou wrote it.i.e., the above copyright notice has to appear in all copies.THE AUTHOR DISCLAIMS ANY RESPONSIBILITY WITH REGARD TOTHIS SOFTWARE.

The Debian packaging is \(C) 2008, Nobuhiro Iwamatsu <iwamatsu@nigauri.org> andis licensed under the GPL, see ‘/usr/share/common-licenses/GPL’.

# Please also look if there are files or directories which have a# different copyright/license attached and list them here.

. . . . . .

めんどくさいので、コピー。

. . . . . .

実際は、ソフトウェアの著作権を持っている人に連絡をとり、ライセンスを確認する必要があります。

. . . . . .

debian/rulesファイルを編集する

. . . . . .

debian/rulesは Debian Packageを作成する Makefileです。

configureターゲットbuildターゲットcleanターゲットinstallターゲット

. . . . . .

今回はシンプルなプログラムなので、変更する必要はありません。

. . . . . .

とりあえずPackageを作成する

. . . . . .

Debian Packageを作る時は、debuildコマンドを使います。

$ debuild -us -uc

-usソースパッケージにGPGサインをしない-uc *.changesファイルに GPGサインをしない

. . . . . .

$ debuild -us -ucfakeroot debian/rules cleandh_testdirdh_testrootrm -f build-stamp configure-stamp# Add here commands to clean up after the \build process./usr/bin/make cleanmake[1]: ディレクトリ ‘/tmp/sl-0.0.0’ に入りますmake[1]: *** ターゲット ‘clean’ を make するルール \がありません. 中止.make[1]: ディレクトリ ‘/tmp/sl-0.0.0’ から出ますmake: *** [clean] エラー 2debuild: fatal error at line 1239:fakeroot debian/rules clean failed

. . . . . .

Makefile の修正

. . . . . .

図 rulesファイルとMakefileの関係図今のMakefile

CC=ccCFLAGS=-O

sl: sl.c sl.h$(CC) $(CFLAGS) -o sl sl.c -lcurses -ltermcap

# $(CC) $(CFLAGS) -o sl sl.c -lcurses

. . . . . .

修正後

CC=ccCFLAGS=-OBINDIR?=/usr/games/ <--- インストール先を追加

BINDIR :実行バイナリがインストールされるディレクトリ

. . . . . .

修正後

install: <-- install ターゲットを追加install -d ${DESTDIR}${BINDIR}install -m 755 sl ${DESTDIR}${BINDIR}

clean: <-- clean ターゲットを追加rm -rf sl

DESTDIR: Debian Packageのインストールされる TOPディレクトリ

. . . . . .

再 度 De-bian Pack-ageを作成

. . . . . .

$ debuild -us -uc......dh_shlibdepsdh_gencontroldpkg-gencontrol: warning: unknown substitution variable ${misc:Depends}dh_md5sumsdh_builddebdpkg-deb: building package ‘sl’ in ‘../sl_0.0.0-1_i386.deb’.dpkg-genchangesdpkg-genchanges: including full source code in uploaddpkg-buildpackage (debuild emulation): full upload (original source is included)Now running lintian...W: sl: binary-without-manpage slFinished running lintian.

. . . . . .

DebianPackageのテスト

. . . . . .

pbuilder最低限のDebian systemから、パッケージを作成するためのツール。   

$ sudo /usr/sbin/pbuilder build sl_0.0.0-1.dsc

piupartsDebian Packageのインストール/アンインストールのチェックをするためのツール。

. . . . . .

本日のまとめ

. . . . . .

まずは、ソフトウェアが動作するか確認する

dh makeコマンドでパッケージの雛形を作成するdebuildコマンドでパッケージ作成ライセンスやコピーライトの確認をすること

lintian/lindaでパッケージのチェックインストールして動作確認まで行う

アンインストールの確認も忘れずに

. . . . . .

情報源

. . . . . .

Debian Project / Debian JP Project Websitehttp://www.debain.org

http://www.debain.or.jp

東京エリアDebian勉強会http://tokyodebian.alioth.debian.org

Debian Policyhttp://www.debian.org/doc/debian-policy/

Debian新メンテナガイドhttp://www.debian.org/doc/manuals/

maint-guide/index.ja.html

. . . . . .

終わりに

. . . . . .

今年のDebian勉強会では、毎月様々なDebian Pakcageの作成方法をみなさんに伝授します。

データだけのDebianPackage作成方法VCSを使ったDebian Packageの作成方法ライブラリのDebian Package作成方法などなど

. . . . . .

質疑応答

Recommended