%define original_version 3.4.3
%define jp_patch_version 0.9

Summary: JNetHack
Summary(ja): JNetHack
Name: jnethack
Version: %{original_version}_%{jp_patch_version}
Release: 0vl3
License: NETHACK GENERAL PUBLIC LICENSE
Group: Applications/Games
URL: http://www.nethack.org/
Source0: ftp://ftp.sourceforge.net/n/ne/nethack/nethack-343-src.tgz
Source1: jnethack.desktop
Patch0: http://osdn.dl.sourceforge.jp/jnethack/15876/jnethack-3.4.3-0.9.diff.gz
# Patch1 is for Linux tty and X11
Patch1: jnethack-343-vine-setup.patch
Buildroot: %{_tmppath}/%{name}-%{version}-root
BuildRequires: XOrg-devel, sed, ncurses-devel, bison, flex
BuildRequires: desktop-file-utils
Requires: XOrg, ncurses
Requires: desktop-file-utils
Vendor: Project Vine
Distribution: Vine Linux
Packager: IKEDA Katsumi <ikeda@webmasters.gr.jp>

%define _gamedir %{_prefix}/games

%description
JNetHack is Japanized NetHack.
NetHack is a single player dungeon exploration game that runs on
a wide variety of computer systems, with a variety of graphical
and text interfaces all using the same game engine.

%description -l ja
JNetHack は、日本語に対応した NetHack です。
NetHack はシングルプレイヤーのダンジョン探検ゲームで、非常に多様な
コンピュータシステムで動作し、グラフィックやテキストといった種類の
インタフェースで同じゲームエンジンを使用します。

%prep
%{__rm} -rf ${RPM_BUILD_ROOT}

%setup -q -n nethack-%{original_version}
%patch0 -p1 -b .jpatch
%patch1 -p1 -b .vine-setup

%build
(cd sys/unix && sh setup.sh)
%{__make} \
	LFLAGS="-L%{_libdir} -L/usr/X11R6/%{_lib}" \
	WINTTYLIB=%{_libdir}/libncurses.a

%install
%{__rm} -rf ${RPM_BUILD_ROOT}
make PREFIX="${RPM_BUILD_ROOT}/usr" HACKDIR="%{__gamedir}/lib/nethackdir" install
(cd ${RPM_BUILD_ROOT}/%{_gamedir} && %{__mv} jnethack jnethack.tmp &&
    %{__sed} -e "s;${RPM_BUILD_ROOT};;" < jnethack.tmp > jnethack &&
    %{__rm} -f jnethack.tmp)
%{__install} -d ${RPM_BUILD_ROOT}/%{_prefix}/X11R6/lib/X11/app-defaults
%{__install} -m 644 win/X11/JNetHack.ad ${RPM_BUILD_ROOT}/%{_prefix}/X11R6/lib/X11/app-defaults/JNetHack
%{__install} -d ${RPM_BUILD_ROOT}/%{_mandir}/man6
%{__install} -m 644 doc/dgn_comp.6 ${RPM_BUILD_ROOT}/%{_mandir}/man6/dgn_comp.6
%{__install} -m 644 doc/dlb.6 ${RPM_BUILD_ROOT}/%{_mandir}/man6/dlb.6
%{__install} -m 644 doc/lev_comp.6 ${RPM_BUILD_ROOT}/%{_mandir}/man6/lev_comp.6
%{__install} -m 644 doc/nethack.6 ${RPM_BUILD_ROOT}/%{_mandir}/man6/nethack.6
%{__install} -m 644 doc/recover.6 ${RPM_BUILD_ROOT}/%{_mandir}/man6/recover.6

%{__install} -d ${RPM_BUILD_ROOT}%{_datadir}/applications
%{__install} -m 644 %{SOURCE1} ${RPM_BUILD_ROOT}%{_datadir}/applications/jnethack.desktop

%{__cat} << EOF > ${RPM_BUILD_ROOT}%{_gamedir}/jnethack-tty
#!/bin/sh
NETHACKOPTIONS=windowtype:tty jnethack
EOF
%{__cat} << EOF > ${RPM_BUILD_ROOT}%{_gamedir}/jnethack-x11
#!/bin/sh
NETHACKOPTIONS=windowtype:X11 jnethack
EOF
%{__chmod} 755 ${RPM_BUILD_ROOT}%{_gamedir}/jnethack-tty
%{__chmod} 755 ${RPM_BUILD_ROOT}%{_gamedir}/jnethack-x11
%{__install} -d ${RPM_BUILD_ROOT}%{_bindir}
%{__ln_s} %{_gamedir}/jnethack ${RPM_BUILD_ROOT}%{_bindir}/jnethack
%{__ln_s} %{_gamedir}/jnethack-tty ${RPM_BUILD_ROOT}%{_bindir}/jnethack-tty
%{__ln_s} %{_gamedir}/jnethack-x11 ${RPM_BUILD_ROOT}%{_bindir}/jnethack-x11

desktop-file-install --delete-original --vendor= \
  --dir=${RPM_BUILD_ROOT}%{_datadir}/applications \
  ${RPM_BUILD_ROOT}%{_datadir}/applications/*


%clean
%{__rm} -rf ${RPM_BUILD_ROOT}

#----------------------------------------------------------------

%post
update-desktop-database %{_datadir}/applications

%postun
update-desktop-database %{_datadir}/applications

%preun
%{__rm} -f %{_gamedir}/lib/jnethackdir/*lock.0

%files
%defattr(-, games, games)
%doc Files Porting README ChangeLog.j INSTALL.j README.j
%doc doc/Guidebook.txt doc/Guidebook.mn doc/Guidebook.tex
%doc doc/jGuidebook.txt doc/jGuidebook.mn doc/window.doc
%doc dat/license dat/help dat/hh dat/history dat/opthelp
%doc dat/jhelp dat/jhh dat/jhistory dat/jopthelp japanese/Install.lnx
%attr (755, games, games) %{_gamedir}/jnethack
%attr (755, games, games) %{_gamedir}/jnethack-tty
%attr (755, games, games) %{_gamedir}/jnethack-x11
%{_bindir}/jnethack
%{_bindir}/jnethack-tty
%{_bindir}/jnethack-x11
%dir %{_gamedir}/lib
%attr (775, games, games) %dir %{_gamedir}/lib/jnethackdir
%dir %{_gamedir}/lib/jnethackdir/save
%{_gamedir}/lib/jnethackdir/nhdat
%{_gamedir}/lib/jnethackdir/x11tiles
%{_gamedir}/lib/jnethackdir/NetHack.ad
%{_gamedir}/lib/jnethackdir/pet_mark.xbm
%{_gamedir}/lib/jnethackdir/rip.xpm
%{_gamedir}/lib/jnethackdir/license
%{_gamedir}/lib/jnethackdir/recover
%{_gamedir}/lib/jnethackdir/perm
%attr (2755, games, games) %{_gamedir}/lib/jnethackdir/jnethack
%config %attr (664, games, games) %{_gamedir}/lib/jnethackdir/record
%config %attr (664, games, games) %{_gamedir}/lib/jnethackdir/logfile
%{_mandir}/man6/dgn_comp.6*
%{_mandir}/man6/dlb.6*
%{_mandir}/man6/lev_comp.6*
%{_mandir}/man6/nethack.6*
%{_mandir}/man6/recover.6*
%{_prefix}/X11R6/lib/X11/app-defaults/JNetHack
%{_datadir}/applications/jnethack.desktop

%changelog
* Sun Dec 30 2007 Shu KONNO <owa@bg.wakwak.com> 3.4.3_0.9-0vl3
- added LFLAGS and WINTTYLIB to make

* Sat Sep 15 2007 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 3.4.3_0.9-0vl2
- rebuilt for VineSeed

* Sat Sep 15 2007 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 3.4.3_0.9-0vl1
- new upstream release (jnethack-3.4.3-0.9)

* Sat Jan 20 2007 IKEDA Katsumi <ikeda@webmasters.gr.jp> 3.4.3_0.7-0vl1
- new upstream release (jnethack-3.4.3-0.7)
- add a symbolic link to /usr/games/jnethack in /usr/bin/
- add jnethack.desktop

* Mon Sep 25 2006 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 3.4.3-0vl5
- changed Group to Applications/Games

* Sun Jan 09 2005 IKEDA Katsumi <ikeda@webmasters.gr.jp> 3.4.3-0vl4
- new upstream version (jnethack-3.4.3-0.5)

* Mon Aug 16 2004 IKEDA Katsumi <ikeda@webmasters.gr.jp> 3.4.3-0vl3
- Modified BuildRequires and Requires
- Rebuild for Vine Linux 3.0.

* Fri Aug  6 2004 IKEDA Katsumi <ikeda@webmasters.gr.jp> 3.4.3-0vl2
- upstream update: jnethack-3.4.3-0.4.diff.gz

* Tue Jun 23 2004 IKEDA Katsumi <ikeda@webmasters.gr.jp> 3.4.3-0vl1
- Initial specfile
