%define pkgname wesnoth
%define version 1.4.7
%define release 2%{?_dist_release}

%define with_editor 0
%define with_tools 0
%define with_campaignd 0
%define with_wesnothd 0

%define datadir_name %{pkgname}147

Summary: Fantasy Turn-Based Strategy Game
Summary(ja):  ターンベースのファンタジー戦略シミュレーションゲーム
Name: %{pkgname}147
Version: %{version}
Release: %{release}
Source0: %{pkgname}-%{version}.tar.bz2
Source1: wesnothd.init
Source2: %{pkgname}.sysconfig
Patch0:   %{pkgname}-1.2.8-gcc43.patch

%{?nosrc:NoSource: 0}

License: GPLv2+
Group: Applications/Games
URL: http://www.wesnoth.org/

Requires: xorg-x11-libs SDL SDL_image SDL_mixer SDL_net SDL_ttf
Requires: freetype2 libpng zlib
Requires: libboost-iostreams
%if %{?_dist_release} == "vl5"
Requires: TrueType-vlgothic
%endif
%if %{?_dist_release} == "vl4"
Requires: TrueType-sazanami
%endif
BuildRequires: xorg-x11-devel SDL-devel SDL_image-devel SDL_mixer-devel 
BuildRequires: SDL_net-devel SDL_ttf-devel
BuildRequires: freetype2-devel libpng-devel zlib-devel
BuildRequires: libboost-devel libboost-iostreams
#BuildRequires: fribidi-devel
#BuildRequires: python-devel
BuildRoot: %{_tmppath}/%{pkgname}-%{version}-root
Obsoletes: wesnoth <= 1.4.7

%description
Battle for Wesnoth is a fantasy turn-based strategy game. Battle for
control of villages, using variety of units which have advantages and
disadvantages in different types of terrains and against different
types of attacks. Units gain experience and advance levels, and are
carried over from one scenario to the next campaign.

%description -l ja
Battle for Wesnoth はターンベースの戦略シミュレーションゲームです．
異なる地形や攻撃のタイプに対して，長所と短所をもつ多種のユニットを使用
しながら，村々の支配のために戦います．ユニットは経験を得てレベルアップ
して，シナリオから次のキャンペーンまで連れて行かれます．

%if %{with_editor}
%package editor
Group: Applications/Games
Summary: The Battle of Wesnoth map editor.
Summary(ja): The Battle of Wesnoth マップエディタ
Requires: wesnoth = %{version}-%{release}

%description editor
Battle for Wesnoth is a fantasy turn-based strategy game. 
This package contains the map editor for it.

%description editor -l ja
Battle for Wesnoth はターンベースの戦略シミュレーションゲームです．
このパッケージには，そのマップエディタが入っています．
%endif

%if %{with_tools}
%package tools
Group: Applications/Games
Summary: The Battle of Wesnoth tools.
Summary(ja): The Battle of Wesnoth ツール
Requires: wesnoth = %{version}-%{release}

%description tools
Battle for Wesnoth is a fantasy turn-based strategy game. 
This package includes tools for translators and artists working on
Battle for Wesnoth.

%description tools -l ja
Battle for Wesnoth はターンベースの戦略シミュレーションゲームです．
このパッケージには，Battle for Wesnoth で作業されている
翻訳者やアーティストへのツールが含まれています．
%endif

%if %{with_campaignd}
%package campaign-server
Summary: The Battle of Wesnoth campaign server.
Summary(ja): The Battle of Wesnoth キャンペーンサーバ
Requires: wesnoth = %{version}-%{release}

%description campaign-server
Battle for Wesnoth is a fantasy turn-based strategy game. 
The campaign server acts as a simple download server, much like ftp, to
provide a collection of Wesnoth campaigns to players.

%description campaign-server -l ja
Battle for Wesnoth はターンベースの戦略シミュレーションゲームです．
このキャンペーンサーバーは，プレーヤーたちに Wesnoth キャンペーンの
コレクションを提供するために，FTP のような簡易なダウンロードサーバとして
動作します．
%endif

%if %{with_wesnothd}
%package server
Group: Applications/Games
Summary: The Battle of Wesnoth game server.
Summary(ja): The Battle of Wesnoth ゲームサーバ
Requires: wesnoth = %{version}-%{release}
Requires(post): /sbin/chkconfig
Requires(preun): /sbin/chkconfig
Requires(pre): /usr/sbin/useradd

%description server
Battle for Wesnoth is a fantasy turn-based strategy game. 
This package contains the wesnothd server needed to play networked games.

%description server -l ja
Battle for Wesnoth はターンベースの戦略シミュレーションゲームです．
このパッケージには，ネットワークゲームのプレイに必要とされるwesnothdサー
バが入っています．
%endif


%prep
rm -rf ${RPM_BUILD_ROOT}

%setup -q -n %{pkgname}-%{version}
%patch0 -p1 -b .gcc43

%build
export CFLAGS="%{optflags}" CXXFLAGS="%{optflags}" 
%configure \
    --disable-dependency-tracking \
%if %{with_editor}
    --enable-editor \
%endif
%if %{with_tools}
    --enable-tools \
%endif
%if %{with_campaignd}
    --enable-campaign-server \
%endif
%if %{with_wesnothd}
    --enable-server \
    --with-fifodir=/var/run/wesnothd \
    --with-server-gid=root \
    --with-server-uid=root \
%endif
    --with-datadir-name=%{datadir_name} \
    ;
    
%{__make}


%install
%{__rm} -rf ${RPM_BUILD_ROOT}
%{__make} DESTDIR=${RPM_BUILD_ROOT} install 

### for wesnoth147
# - rename exec binary
# - remove man directory
%{__rm} -rf $RPM_BUILD_ROOT%{_mandir}
%__mv $RPM_BUILD_ROOT%{_bindir}/%{pkgname} \
    $RPM_BUILD_ROOT%{_bindir}/%{pkgname}-%{version}

### link sazanami-gothic.ttf
pushd ${RPM_BUILD_ROOT}%{_datadir}/%{datadir_name}/fonts/
# for 1.2.7 or higher (contains sazanami-gothic.ttf)
%{__rm} -f sazanami-gothic.ttf

%if %{?_dist_release} == "vl5"
#ln -s /usr/share/fonts/TrueType-sazanami-gothic/sazanami-gothic.ttf .
ln -s /usr/share/fonts/TrueType-vlgothic/VL-PGothic-Regular.ttf sazanami-gothic.ttf
%endif
%if %{?_dist_release} == "vl4"
ln -s /usr/X11R6/lib/X11/fonts/TrueType/sazanami-gothic.ttf .
%endif
popd

### for Gnome menu
mkdir -p $RPM_BUILD_ROOT/%{_datadir}/pixmaps
sed -i -e 's/^Version=.*$//' \
       -e 's/^Name=Battle for Wesnoth/Name=Battle for Wesnoth (Version 1.4.7)/' \
       -e 's/^Exec=wesnoth/Exec=wesnoth-1.4.7/' \
       -e 's/Icon=wesnoth-icon\.png/Icon=wesnoth147-icon/' \
    icons/%{pkgname}.desktop
%__mv icons/%{pkgname}.desktop icons/%{datadir_name}.desktop
desktop-file-install \
    --dir $RPM_BUILD_ROOT/%{_datadir}/applications \
    --mode="0644" --vendor vine \
    icons/%{datadir_name}.desktop
install -m 644 images/%{pkgname}-icon.png $RPM_BUILD_ROOT/%{_datadir}/pixmaps/%{datadir_name}-icon.png
%if %{with_editor}
desktop-file-install \
    --dir $RPM_BUILD_ROOT/%{_datadir}/applications \
    --mode="0644" --vendor vine \
    icons/%{pkgname}_editor.desktop
install -m 644 icons/%{pkgname}_editor-icon.png $RPM_BUILD_ROOT/%{_datadir}/pixmaps
%endif

### rename for tools
%if %{with_tools}
pushd ${RPM_BUILD_ROOT}%{_bindir}/
mv cutter %{pkgname}_cutter
mv exploder %{pkgname}_exploder 
popd
%endif

### for wesnothd server
%if %{with_wesnothd} 
mkdir -p ${RPM_BUILD_ROOT}%{_sbindir}
mv ${RPM_BUILD_ROOT}%{_bindir}/wesnothd ${RPM_BUILD_ROOT}%{_sbindir}
mkdir -p ${RPM_BUILD_ROOT}/var/run/wesnothd
touch ${RPM_BUILD_ROOT}/var/run/wesnothd/socket
install -Dpm 755 %{SOURCE1} ${RPM_BUILD_ROOT}%{_initrddir}/wesnothd
install -Dpm 644 %{SOURCE2} ${RPM_BUILD_ROOT}/%{_sysconfdir}/sysconfig/wesnoth
%endif


### remove unpackage files
%if !%{with_editor}
%{__rm} -f ${RPM_BUILD_ROOT}%{_datadir}/wesnoth/translations/*/LC_MESSAGES/wesnoth-editor.mo
%endif

find $RPM_BUILD_ROOT -name ".cvs*" | xargs rm -f
find $RPM_BUILD_ROOT -name "CVS" | xargs rm -rf

%{__rm} -rf $RPM_BUILD_ROOT/usr/share/doc/wesnoth/
%{__rm} -f $RPM_BUILD_ROOT/usr/share/icons/wesnoth-icon.png
%{__rm} -f $RPM_BUILD_ROOT/usr/share/icons/wesnoth_editor-icon.png
%{__rm} -f $RPM_BUILD_ROOT/usr/share/applications/wesnoth*


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


%post
# touch --no-create %{_datadir}/icons/hicolor || :
# if [ -x %{_bindir}/gtk-update-icon-cache ]; then
#    %{_bindir}/gtk-update-icon-cache --quiet %{_datadir}/icons/hicolor || :
# fi

%postun
# touch --no-create %{_datadir}/icons/hicolor || :
# if [ -x %{_bindir}/gtk-update-icon-cache ]; then
#   %{_bindir}/gtk-update-icon-cache --quiet %{_datadir}/icons/hicolor || :
# fi

%if %{with_wesnothd}
%pre server
/usr/sbin/useradd -c "Wesnoth server" -s /sbin/nologin \
	-r -d /var/run/wesnothd wesnothd 2> /dev/null || :

%post server
/sbin/chkconfig --add wesnothd
if [ $1 -gt 1 ]; then
    %{_initrddir}/wesnothd try-restart >/dev/null || :
fi

%preun server
if [ $1 -eq 0 ]; then
    %{_initrddir}/wesnothd stop >/dev/null 2>&1 || :
    /sbin/chkconfig --del wesnothd
fi
%endif


%files
%defattr(-,root,root)
%doc COPYING INSTALL README changelog copyright doc/manual/
%{_bindir}/%{pkgname}-%{version}
#%{_mandir}/man6/wesnoth.*
#%{_mandir}/*/man6/wesnoth.*
%{_datadir}/%{datadir_name}
%{_datadir}/applications/vine-*.desktop
%{_datadir}/pixmaps/*.png

%if %{with_editor}
%files editor
%defattr(-,root,root)
%{_bindir}/wesnoth_editor
%{_mandir}/man6/wesnoth_editor.*
%{_mandir}/*/man6/wesnoth_editor.*
%{_datadir}/wesnoth/translations/*/LC_MESSAGES/wesnoth-editor.mo
%{_datadir}/applications/vine-wesnoth_editor.desktop
%endif

%if %{with_tools}
%files tools
%defattr(-,root,root)
#%{_bindir}/cutter
#%{_bindir}/exploder
%{_bindir}/wesnoth_cutter
%{_bindir}/wesnoth_exploder
%endif

%if %{with_campaignd}
%files campaign-server
%defattr(-,root,root)
%{_bindir}/campaignd
%endif

%if %{with_wesnothd}
%files server
%defattr(-,root,root)
%config %{_initrddir}/wesnothd
%config(noreplace) %{_sysconfdir}/sysconfig/wesnoth
#%{_bindir}/wesnothd
%{_sbindir}/wesnothd
%{_mandir}/man6/wesnothd.*
%{_mandir}/*/man6/wesnothd.*
%attr(0700,wesnothd,wesnothd) %dir /var/run/wesnothd/
%ghost /var/run/wesnothd/socket
%endif


%changelog
* Sat Jan 10 2009 Munehiro Yamamoto <munepi@cg8.so-net.ne.jp> 1.4.7-2
- renamed to wesnoth147 from wesnoth
- added Requires: TrueType-vlgothic for vl5
- dropped BuildRequires: TrueType-sazanami
- added configure options: 
  - --disable-dependency-tracking
  - --with-datadir-name=%%{datadir_name}

* Sat Jan 10 2009 Munehiro Yamamoto <munepi@cg8.so-net.ne.jp> 1.4.7-1
- new upstream release

* Sun Nov 16 2008 Munehiro Yamamoto <munepi@cg8.so-net.ne.jp> 1.4.6-1
- new upstream release

* Sun Nov 02 2008 Munehiro Yamamoto <munepi@cg8.so-net.ne.jp> 1.4.5-1
- new upstream release
- fixed License to GPLv2+
- added BuildRequires: libboost-devel
- added Requires: libboost-iostreams
- dropped wesnoth.desktop, wesnoth.png, wesnoth-editor.desktop

- apply wesnoth-1.2.8-gcc43.patch (from Fedora package)

* Tue Oct 14 2008 Shu KONNO <owa@bg.wakwak.com> 1.2.7-1vl5
- applied new versioning policy, spec in utf-8

* Wed Jan 02 2008 Shu KONNO <owa@bg.wakwak.com> 1.2.7-0vl2
- rebuilt for VineSeed

* Mon Oct 23 2007 Munehiro Yamamoto <myamamoto@g.math.s.chiba-u.ac.jp> 1.2.7-0vl1
- new upstream
 - define with_editor 0, with_tools 0, with_campaignd 0, with_wesnothd 0
 - drop wesnoth-server package 
 - arrange wesnothd server package files
   [HELP] please test wesnoth-server, which change with_wesnothd to TRUE

# * Tue Sep 4 2007 Munehiro Yamamoto <myamamoto@g.math.s.chiba-u.ac.jp> 1.2.6-0vl3
# - provide wesnoth-tools package 
# - drop wesnoth-server package 
# - arrange wesnothd server package files
#   [HELP] please test wesnoth-server and wesnoth-campaign-server, 
#   which change with_wesnothd and with_campaignd to TRUE

* Mon Sep 3 2007 Munehiro Yamamoto <myamamoto@g.math.s.chiba-u.ac.jp> 1.2.6-0vl2
- rebuild for VineSeed

* Mon Sep 3 2007 Munehiro Yamamoto <myamamoto@g.math.s.chiba-u.ac.jp> 1.2.6-0vl1
- initial build for Vine Linux 4.1

* Sun Apr 15 2007 Munehiro Yamamoto <myamamoto@g.math.s.chiba-u.ac.jp> 1.2.3-0vlmp1
- new upstream for Vine Linux 4.1

* Fri Jun 10 2005 Munehiro Yamamoto <myamamoto@g.math.s.chiba-u.ac.jp> 0.9.2-0vlmp1
- initial build for Vine Linux 3.2



# end of file
