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

%define ver 1.10.7
%define src_ver %{ver}
%define rel 1

%define with_svn 0
%if %{with_svn}
%define svn_rev 41885
%endif

%define with_unofficial_po 0
%define po_date		   20100926

Summary: Fantasy Turn-Based Strategy Game
Summary(ja):  ターンベースのファンタジー戦略シミュレーションゲーム
Name: wesnoth
Version: %{ver}
%if %{with_svn}
Release: %{rel}.svn%{svn_rev}%{?_dist_release}
Source0: %{name}-%{version}-svn%{svn_rev}.tar.bz2
%else
Release: %{rel}%{?_dist_release}
Source0: %{name}-%{src_ver}.tar.bz2
%endif
Source1: wesnothd.init
Source2: %{name}.sysconfig
# http://sourceforge.jp/projects/wesnoth-ja/releases/?package_id=11460
Source12: wesnoth-1.8.5_ja-catalogs-%{po_date}.zip

%{?nosrc:NoSource: 0}

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

Distribution: Vine Linux
Vendor:       Project Vine
Packager:     munepi, iwaim

Requires: SDL SDL_image SDL_mixer SDL_net SDL_ttf
Requires: freetype2 libpng zlib pango fontconfig
Requires: libboost-iostreams libboost-regex
Requires: TrueType-vlgothic
BuildRequires: cmake >= 2.6.0
BuildRequires: desktop-file-utils
BuildRequires: ImageMagick
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 pango-devel
BuildRequires: fontconfig-devel
BuildRequires: libboost-devel >= 1.36
BuildRequires: libboost-iostreams libboost-regex
BuildRequires: libboost-serialization
BuildRequires: libboost-program-options
BuildRequires: libboost-system
BuildRequires: libboost-thread
BuildRequires: lua-devel
#BuildRequires: fribidi-devel
#BuildRequires: python-devel
%if %{with_unofficial_po}
BuildRequires: unzip
%endif
BuildRoot: %{_tmppath}/%{name}-%{version}-root

Conflicts: wesnoth165

%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}

%if %{with_svn}
%setup -q -n %{name}-%{version}-svn%{svn_rev}
%else
%setup -q -n %{name}-%{src_ver}
%endif

%if %{with_unofficial_po}
%define japo_dir wesnoth-1.8.5ja-catalogs-%{po_date}
%__unzip %{SOURCE12}

pushd %{japo_dir}
target=(
	httt
)
for n in "${target[@]}"
do
%{__cp} -f wesnoth-%{version}_$n-%{po_date}_ja.po ../po/wesnoth-$n/ja.po
done
popd
%endif

%build
export CFLAGS="%{optflags}" CXXFLAGS="%{optflags}" 

%__mkdir build
pushd build
%{cmake} \
    -DLOCALEDIR=%{_localedir} \
    -DENABLE_FRIBIDI:BOOL=OFF \
    -DENABLE_GAME:BOOL=ON \
    -DENABLE_DESKTOP_ENTRY:BOOL=ON \
    -DENABLE_NOTIFICATIONS:BOOL=ON \
%if %{with_editor}
    --enable-editor \ # FIXME
%endif
%if %{with_tools}
    -DENABLE_TOOLS:BOOL=ON
%endif
%if %{with_campaignd}
    -DENABLE_CAMPAIGN_SERVER:BOOL=ON \
%endif
%if %{with_wesnothd}
    -DENABLE_SERVER:BOOL=ON \
    -DFIFO_DIR=/var/run/wesnothd \
    -DSERVER_GID=root \
    -DSERVER_UID=root \
%else
    -DENABLE_SERVER:BOOL=OFF \
%endif
    ..
    
%{__make}
popd

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

### link sazanami-gothic.ttf
pushd ${RPM_BUILD_ROOT}%{_datadir}/%{name}/fonts/
## for 1.2.7 or higher (contains sazanami-gothic.ttf)
#%{__rm} -f sazanami-gothic.ttf
## for 1.6a or higher (NOT contains sazanami-gothic.ttf)
%{__rm} -f wqy-zenhei.ttc

ln -s /usr/share/fonts/TrueType-vlgothic/VL-PGothic-Regular.ttf sazanami-gothic.ttf
ln -s /usr/share/fonts/TrueType-vlgothic/VL-Gothic-Regular.ttf wqy-zenhei.ttc
popd

### for Gnome menu
%__mkdir_p $RPM_BUILD_ROOT/%{_datadir}/pixmaps

desktop-file-install \
    --dir $RPM_BUILD_ROOT/%{_datadir}/applications \
    --mode="0644" --vendor vine \
    ../icons/%{name}.desktop
#%__install -m 644 icons/%{name}-icon.png $RPM_BUILD_ROOT/%{_datadir}/pixmaps
for size in 16x16 20x20 22x22 24x24 32x32 36x36 64x64 48x48 64x64 72x72 96x96 128x128 192x192 ; do
    %__mkdir_p $RPM_BUILD_ROOT%{_datadir}/icons/hicolor/${size}/apps
    convert ../icons/%{name}-icon.png -size ${size} \
	$RPM_BUILD_ROOT%{_datadir}/icons/hicolor/${size}/apps/%{name}-icon.png
done
%if %{with_editor}
desktop-file-install \
    --dir $RPM_BUILD_ROOT/%{_datadir}/applications \
    --mode="0644" --vendor vine \
    ../icons/%{name}_editor.desktop
%__install -m 644 icons/%{name}_editor-icon.png $RPM_BUILD_ROOT/%{_datadir}/pixmaps
%endif

### rename for tools
%if %{with_tools}
pushd ${RPM_BUILD_ROOT}%{_bindir}/
mv cutter %{name}_cutter
mv exploder %{name}_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}%{_localedir}/*/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 \
    $RPM_BUILD_ROOT/usr/share/pixmaps/wesnoth-icon.png \
    $RPM_BUILD_ROOT/usr/share/icons/wesnoth_editor-icon.png
%{__rm} -f $RPM_BUILD_ROOT/usr/share/applications/wesnoth*.desktop
%if !%{with_wesnothd}
%{__rm} -f $RPM_BUILD_ROOT/%{_mandir}/man6/wesnothd.*
%{__rm} -f $RPM_BUILD_ROOT/%{_mandir}/*/man6/wesnothd.*
%endif

%find_lang %{name} --all-name

popd

%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
%{_bindir}/update-desktop-database %{_datadir}/applications || :

%postun
%{_bindir}/update-desktop-database %{_datadir}/applications || :
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 -f build/%{name}.lang
%defattr(-,root,root)
%doc COPYING INSTALL README changelog copyright doc/manual/
%{_bindir}/%{name}
%{_mandir}/man6/wesnoth.*
%{_mandir}/*/man6/wesnoth.*
%{_datadir}/%{name}
%{_datadir}/applications/vine-wesnoth.desktop
#%{_datadir}/pixmaps/wesnoth-icon.png
%{_datadir}/icons/hicolor/*/apps/*.png

%if %{with_editor}
%files editor
%defattr(-,root,root)
%{_bindir}/wesnoth_editor
%{_mandir}/man6/wesnoth_editor.*
%{_mandir}/*/man6/wesnoth_editor.*
%{_localedir}/*/LC_MESSAGES/wesnoth-editor.mo
%{_datadir}/applications/vine-wesnoth_editor.desktop
%{_datadir}/pixmaps/wesnoth_editor-icon.png
%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
* Fri Dec 20 2013 IWAI, Masaharu <iwaim.sub@gmail.com> 1.10.7-1
- update to 1.10.7

* Mon Dec 09 2013 Yoji TOYODA <bsyamato@sea.plala.or.jp> 1.10.5-2
- rebuild with libboost-1.54.0

* Fri Jan 11 2013 IWAI, Masaharu <iwai@alib.jp> 1.10.5-1
- update to 1.10.5
- update BR libboost version: 1.35 -> 1.36
- add BuildRequires:
  - libboost-serialization
  - libboost-program-options
  - libboost-system
  - libboost-thread
- using cmake
- drop unnecessary script in install section
  - fix desktop file script

* Mon Sep  5 2011 IWAI, Masaharu <iwai@alib.jp> 1.8.6-2
- drop Requires: xorg-x11-libs
- drop unnecessary routine for Vine Linux 4

* Sun May 15 2011 IWAI, Masaharu <iwai@alib.jp> 1.8.6-1
- new upstream release

* Tue Jan 18 2011 Shu KONNO <owa@bg.wakwak.com> 1.8.5-2
- rebuilt with libboost-1.45.0

* Wed Oct 20 2010 IWAI, Masaharu <iwai@alib.jp> 1.8.5-1
- new upstream release
- add Japanese po files version 20100926 (Source12)
- add BuildRequires: unzip for Japanese po files

* Thu Aug 12 2010 IWAI, Masaharu <iwai@alib.jp> 1.8.4-1
- new upstream release
- drop Japanese po files version 20100710 (Source12)

* Sat Jul 10 2010 IWAI, Masaharu <iwai@alib.jp> 1.8.3-1
- new upstream release
- add Japanese po files version 20100710 (Source12)

* Thu Jun  3 2010 IWAI, Masaharu <iwai@alib.jp> 1.8.2-1
- new upstream release
- add required Boost Library version

* Mon May  3 2010 IWAI, Masaharu <iwai@alib.jp> 1.8.1-1
- new upstream release
- fix typo for Conflicts tag: wesnoth165

* Fri Apr  2 2010 IWAI, Masaharu <iwai@alib.jp> 1.8.0-2
- new upstream release
- running autogen.sh: missing configure script in 1.8 tarball

* Tue Mar 30 2010 IWAI, Masaharu <iwai@alib.jp> 1.8.0-1.svn41885
- update to 1.8.0+svn41885
- add Conflicts: wesnoth165
- without unofficial po files (Source10): unstream merged
- symbolic link: VL-Gothic-Regular.ttf to wqy-zenhei.ttc
- add BuildRequires: lua-devel
- fix changelog: 1.6.5-3

* Mon Mar 29 2010 IWAI, Masaharu <iwai@alib.jp> 1.6.5-3
- add unofficial Japanese po files
  - add wesnoth-1.6.5-japanese-po.tar.gz (Source10)
  - add wesnoth-1.6.5-sotbe-ja.po (Source11)
  - add Japanese translators patch (Patch10)
- update Packager: assign iwaim

* Mon Feb 08 2010 Shu KONNO <owa@bg.wakwak.com> 1.6.5-2vl6
- rebuilt with new toolchain and libboost-1.42.0

* Fri Sep 11 2009 Munehiro Yamamoto <munepi@vinelinux.org> 1.6.5-1
- new upstream release
- added BuildRequires: 
  - desktop-file-utils 
  - ImageMagick

* Wed Jul 22 2009 Munehiro Yamamoto <munepi@vinelinux.org> 1.6.4-1
- new upstream release

* Wed Jul  8 2009 MATSUBAYASHI Kohji <shaolin@vinelinux.org> - 1.6.3-2
- fix enable-server bits
  - specify --enable-server=no when with_wesnothd is NOT set)
  - fix install section

* Fri Jul 03 2009 Munehiro Yamamoto <munepi@cg8.so-net.ne.jp> 1.6.3-1
- new upstream release

* Sun May 17 2009 Munehiro Yamamoto <munepi@cg8.so-net.ne.jp> 1.6.2-1
- new upstream release

* Fri May 08 2009 Munehiro Yamamoto <munepi@cg8.so-net.ne.jp> 1.6.1-1
- new upstream release

* Mon Mar 23 2009 Munehiro Yamamoto <munepi@cg8.so-net.ne.jp> 1.6a-1
- new upstream release
- added BuildRequires: libboost-regex
- added Requires: 
  - libboost-regex
  - TrueType-vlgothic for vl5
- dropped BuildRequires: TrueType-sazanami
- dropped wesnoth-1.2.8-gcc43.patch
- added configure options: 
  - --disable-dependency-tracking
  - --with-localedir=%%{_datadir}/locale
- removed wqy-zenhei.ttc
  because wqy-zenhei.ttc affected sazanami-gothic.ttf badly
- added update-desktop-database process in %%post and %%postun

* 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

* Tue 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
