JNetHackをビルドする

昨日、りぬーめも Arch Linux on S101: ABSでjnethackを参考にJNetHackをArchLinuxでビルドしてみた。バージョンは3.4.3-0.10。extraのnethackとはコンフリクトしない。

ABSでnethackのPKGBUILDをもらってきて、JNetHack Projectからパッチをダウンロードしてきて、PKGBUILDを修正してやるという手順を踏む。

作業はどこでもいいのだけど、今回はホームフォルダ内にbuildsディレクトリを作ってその中でやる。

$ sudo abs
$ mkdir ~/builds/jnethack
$ cd ~/builds/jnethack
$ cp -r /var/abs/community/nethack/* .
$ cd nethack

で、このjnethackディレクトリの中にJNetHack Projectからソースパッチ( jnethack-3.4.3-0.10.diff.gz )をもらってきて入れる。

次にPKGBUILDを冒頭のリンクを参考に次のように修正する。

# $Id: PKGBUILD 54248 2011-08-15 09:38:17Z schuay $
# Maintainer : schuay 
# Contributor : kevin 
# Contributor : Christian Schmidt 
# Contributor : Markus Meissner 
# Contributor : Nick Erdmann 

# http://nekolinux.blogspot.jp/2009/06/absjnethack.html

pkgname=jnethack
pkgver=3.4.3_0.10
pkgrel=1

orgpkgname=nethack
orgpkgver=3.4.3

pkgdesc='A single player dungeon exploration game'
arch=('i686' 'x86_64')
url="http://www.nethack.org/index.html"
license=('custom')
depends=('ncurses' 'gzip')
install=nethack.install
source=("http://downloads.sourceforge.net/$orgpkgname/$orgpkgname-${orgpkgver//.}-src.tgz")
md5sums=('21479c95990eefe7650df582426457f9')

build(){
  cd $startdir/src/$orgpkgname-$orgpkgver/
  zcat $startdir/jnethack-3.4.3-0.10.diff.gz | patch -p1

  cd $srcdir/$orgpkgname-$orgpkgver/
  sh sys/unix/setup.sh

  sed -e '/define HACKDIR/ s|/usr/games/lib/jnethackdir|/var/games/jnethack/|' \
      -e '/^#define COMPRESS\s/ s|/usr/bin/compress|/bin/gzip|' \
      -e '/^#define COMPRESS_EXTENSION/ s|".Z"|".gz"|' \
      -e 's|^/\* \(#define DLB\) \*/|\1|' -i include/config.h

  sed -e 's|^/\* \(#define LINUX\) \*/|\1|' \
      -e 's|^/\* \(#define TIMED_DELAY\) \*/|\1|' -i include/unixconf.h

  sed -e 's|^# \(WINTTYLIB = -lncurses\)|\1|' \
      -e 's|^WINTTYLIB = -ltermlib|#&|' -i src/Makefile

  # we are setting up for setgid games, so modify all necessary permissions
  # to allow full access for groups

  sed -e '/^GAMEDIR\s*=/ s|/games/.*$|/var/games/$(GAME)|' \
      -e '/^GAMEUID\s*=/ s|games|root|' \
      -e '/^GAMEGRP\s*=/ s|bin|games|' \
      -e '/^GAMEPERM\s*=/ s|04755|02755|' \
      -e '/^FILEPERM\s*=/ s|0644|0664|' \
      -e '/^DIRPERM\s*=/ s|0755|0775|' \
      -e '/^SHELLDIR\s*=/ s|/games|/usr/bin|' -i Makefile

  sed -e "/^MANDIR\s*=/s|/usr/man/man6|$pkgdir/usr/share/man/man6|" -i doc/Makefile

  make
}
  
package() {
  cd $srcdir/$orgpkgname-$orgpkgver/

  install -dm755 $pkgdir/usr/share/{man/man6,doc/jnethack}
  install -dm775 $pkgdir/var/games/
  make PREFIX=$pkgdir install manpages
  sed -e "s|HACKDIR=$pkgdir/|HACKDIR=/|" \
      -e 's|HACK=$HACKDIR|HACK=/usr/lib/jnethack|' \
      -i $pkgdir/usr/bin/jnethack

  install -dm755 $pkgdir/usr/lib/jnethack
  mv $pkgdir/var/games/jnethack/{jnethack,recover} $pkgdir/usr/lib/jnethack/

  install -Dm644 doc/Guidebook.txt $pkgdir/usr/share/doc/jnethack/Guidebook.txt
      
  install -Dm644 dat/license $pkgdir/usr/share/licenses/$pkgname/LICENSE
}

これでmakepkg -sをすると(マニュアルが見つからないと怒られるけどそれを無視すれば)パッケージができる。pacman -U jnethack-3.4.3_0.10-1-i686.pkg.tar.xzとかすればインストール完了。

ただしjnethack文字コードEUCなので、ターミナルの文字コードeuc-jpにしないといけない。それは面倒なので、ターミナル間の文字コード変換を取り持ってくれるcocotもインストールする*1

こういうgitリポジトリのものをビルドするのにはVCS package guidelines - ArchWikiを読むと良い。
以下を~/builds/cocot-gitディレクトリを作って、その中に以下をPKGBUILDとして作成する:
PKGBUILD

# This is an example PKGBUILD file. Use this as a start to creating your own,
# and remove these comments. For more information, see 'man PKGBUILD'.
# NOTE: Please fill out the license field for your package! If it is unknown,
# then please put 'unknown'.

# See http://wiki.archlinux.org/index.php/VCS_PKGBUILD_Guidelines
# for more information on packaging from GIT sources.

# Maintainer: Your Name 
pkgname=cocot-git
pkgver=20120521
pkgrel=1
pkgdesc=""
arch=('i686' 'xf86_64')
url=""
license=('new BSD Licence')
groups=()
depends=()
makedepends=('git')
provides=('cocot')
conflicts=()
replaces=()
backup=()
options=()
install=
source=()
noextract=()
md5sums=() #generate with 'makepkg -g'

_gitroot=git://github.com/vmi/cocot.git
_gitname=cocot

build() {
  cd "$srcdir"
  msg "Connecting to GIT server...."

  if  -d "$_gitname" ; then
    cd "$_gitname" && git pull origin
    msg "The local files are updated."
  else
    git clone "$_gitroot" "$_gitname"
  fi

  msg "GIT checkout done or server timeout"
  msg "Starting build..."

  rm -rf "$srcdir/$_gitname-build"
  git clone "$srcdir/$_gitname" "$srcdir/$_gitname-build"
  cd "$srcdir/$_gitname-build"

  #
  # BUILD HERE
  #

  #./autogen.sh
  ./configure --prefix=/usr
  make
}

package() {
  cd "$srcdir/$_gitname-build"
  make DESTDIR="$pkgdir/" install
}

# vim:set ts=2 sw=2 et:

でmakepkg -sしてやるとパッケージができるので、先と同じようにpacmanでインストールする。

alias jnethack='cocot -t UTF-8 -p EUC-JP -- jnethack'

とかしてやるとよい。