ksaitoの日記

日々試したことの覚え書き

debパッケージにパッチを当てる

移転しました。

自動的にリダイレクトします。

debパッケージにパッチを当てます。
libapache2-mod-auth-mysqlにパッチを当ててみます。

事前準備

ビルドに必要なコマンドが含まれたパッケージを事前にインストールしておきます。
build-essentialパッケージは毎回入れる必要はありません。

$ sudo apt-get install build-essential

パッケージのコンパイルに必要なパッケージをインストール

パッケージをコンパイルするためには、依存関係があるパッケージやリンクする必要のあるライブラリが入ったパッケージをインストールする必要があります。
apt-getのbuild-depで必要なパッケージをインストールできます。

$ sudo apt-get build-dep libapache2-mod-auth-mysql 
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています                
状態情報を読み取っています... 完了
'libapache2-mod-auth-mysql' の代わりに 'mod-auth-mysql' をソースパッケージとして選出しています
以下のパッケージが新たにインストールされます:
  apache2-threaded-dev libapr1-dev libaprutil1-dev libpq-dev libpq5 uuid-dev
アップグレード: 0 個、新規インストール: 6 個、削除: 0 個、保留: 3 個。
2,068 kB のアーカイブを取得する必要があります。
この操作後に追加で 13.5 MB のディスク容量が消費されます。
続行しますか [Y/n]? 

ソースの取得

apt-get sourceで適当なディレクトリにソース一式を取得します。

$ apt-get source libapache2-mod-auth-mysql 

パッチの適用

パッケージにもともとあるパッチを適用します。
debian/rulesのpatchターゲットを使う

$ cd mod-auth-mysql-4.3.9/
$ debian/rules patch
test -d debian/patched || install -d debian/patched
dpatch  apply-all  
applying patch 001-usage to ./ ... ok.
applying patch 003-ftbfs_apache2.2 to ./ ... ok.
applying patch 004-reconnect to ./ ... ok.
applying patch 005-directives to ./ ... ok.
applying patch 006-options to ./ ... ok.
applying patch 007-unify_namespace to ./ ... ok.
applying patch 008-make_scrambled_password to ./ ... ok.
applying patch 009-port-int to ./ ... ok.
applying patch 010-enctype-apache to ./ ... ok.
applying patch 011-auth_basic to ./ ... ok.
applying patch 012-charset to ./ ... ok.
applying patch 013-CVE-2008-2384_charset to ./ ... ok.
applying patch 014-default-password to ./ ... ok.
applying patch 015-empty-passwords to ./ ... ok.
applying patch 016-apr_pstrcat to ./ ... ok.
applying patch 017-doc_persistent_conn to ./ ... ok.
dpatch  cat-all  >>patch-stampT
mv -f patch-stampT patch-stamp
$ 

パッケージには、17個のパッチがありました。
全部当てたあとに、必要なパッチを当てます。

$ patch < ../../mod_auth_mysql.patch 
patching file mod_auth_mysql.c
$ 

コンパイル

debian/rules buildでコンパイルできるか確認します。

$ debian/rules build
dh_testdir
./configure --disable-apache13 --enable-apache2 --with-mysql-libs=`mysql_config --variable=pkglibdir`
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ANSI C... none needed
checking for mysql_init in -lmysqlclient... yes
checking how to run the C preprocessor... gcc -E
checking for egrep... grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking crypt.h usability... yes
checking crypt.h presence... yes
checking for crypt.h... yes
checking for crypt in -lcrypt... yes
checking for an ANSI C-conforming const... yes
checking return type of signal handlers... void
configure: creating ./config.status
config.status: creating Makefile
config.status: creating config.h
touch configure-stamp
dh_testdir
/usr/bin/make
make[1]: ディレクトリ `~/apt/auth-mysql/mod-auth-mysql-4.3.9' に入ります
/usr/bin/apxs2  -o apache2_mod_auth_mysql.la -I/usr/include/mysql -L/usr/lib/x86_64-linux-gnu -lmysqlclient -DAPACHE2 -c mod_auth_mysql.c
/usr/share/apr-1.0/build/libtool --silent --mode=compile --tag=disable-static x86_64-linux-gnu-gcc -prefer-pic -DLINUX=2 -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -D_REENTRANT -I/usr/include/apr-1.0 -I/usr/include/openssl -I/usr/include/xmltok -pthread     -I/usr/include/apache2  -I/usr/include/apr-1.0   -I/usr/include/apr-1.0  -I/usr/include/mysql -DAPACHE2  -c -o mod_auth_mysql.lo mod_auth_mysql.c && touch mod_auth_mysql.slo
/usr/share/apr-1.0/build/libtool --silent --mode=link --tag=disable-static x86_64-linux-gnu-gcc -o apache2_mod_auth_mysql.la  -L/usr/lib/x86_64-linux-gnu -lmysqlclient -rpath /usr/lib/apache2/modules -module -avoid-version    mod_auth_mysql.lo
cp .libs/apache2_mod_auth_mysql.so .
make[1]: ディレクトリ `~/apt/auth-mysql/mod-auth-mysql-4.3.9' から出ます
touch build-stamp
$ 

あとは、パッケージ化ですがdpatchの使い方が、まだよくわからないので、後日...

元に戻す

もとに戻すには、debian/rules cleanを実行するのですが、一連の処理でパッチをリバースするため、手動で当てたパッチを当てたままだとエラーになります。
まずは、手動で当てたパッチを戻します。

$ patch -R < ../../mod_auth_mysql.patch 
patching file mod_auth_mysql.c
$ 

あとは、debian/rules cleanで元に戻ります。
dh_testrootが実行されるのでfakerootで実行します。

$ fakeroot debian/rules clean

これでソースを取得してきた時と同じ状態に戻ります。