%global with_editor 0
%global with_tools 0
%global with_campaignd 0
%global with_wesnothd 0

#% global svn_rev 41885
%global with_unofficial_po 0
%global po_date		   20100926

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

%{?nosrc:NoSource: 0}

Patch0:         wesnoth-1.2.8-gcc43.patch
Patch8:         wesnoth-1.12.2-CVE-2015-5069.patch
Patch9:         wesnoth-1.12.2-CVE-2015-5070.patch

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 TrueType-dejavu-sans TrueType-droid-sans
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:	libboost-locale libboost-filesystem
BuildRequires:	libvorbis-devel
BuildRequires:	lua-devel
BuildRequires:	dbus-devel
BuildRequires:	fribidi-devel
BuildRequires:	python-devel
BuildRequires:  scons
%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 はターンベースの戦略シミュレーションゲームです．
異なる地形や攻撃のタイプに対して，長所と短所をもつ多種のユニットを使用
しながら，村々の支配のために戦います．ユニットは経験を得てレベルアップ
して，シナリオから次のキャンペーンまで連れて行かれます．


%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 で作業されている
翻訳者やアーティストへのツールが含まれています．

%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サー
バが入っています．


%prep
%__rm -rf ${RPM_BUILD_ROOT}
%setup -q -n %{name}-%{version}%{?svn_rev:-svn%svn_rev}
%patch0 -p1 -b .gcc43
#%patch7 -p0 -b .crash
%patch8 -p0
%patch9 -p0

%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
scons wesnoth exploder cutter wesnothd campaignd \
      prefix=%{_prefix} \
      bindir=%{_bindir} \
      libdir=%{_libdir} \
      python_site_packages_dir=%{python_sitelib}/%{name} \
      extra_flags_release="$RPM_OPT_FLAGS $RPM_LD_FLAGS" \
      %{?_smp_mflags} || exit 1

      # localedirname=locale \

%install
%{__rm} -rf ${RPM_BUILD_ROOT}
scons install install-pytools destdir=$RPM_BUILD_ROOT

### for wesnothd server
## extra files we provide
install -Dpm 755 %{SOURCE1} ${RPM_BUILD_ROOT}%{_initrddir}/wesnothd
install -Dpm 644 %{SOURCE2} ${RPM_BUILD_ROOT}/%{_sysconfdir}/sysconfig/wesnoth

## create this so we can %ghost it
mkdir -p ${RPM_BUILD_ROOT}/var/run/wesnothd
touch ${RPM_BUILD_ROOT}/var/run/wesnothd/socket

## move server stuff into sbindir
mkdir -p ${RPM_BUILD_ROOT}%{_sbindir}
mv $RPM_BUILD_ROOT/%{_bindir}/wesnothd $RPM_BUILD_ROOT/%{_sbindir}
mv $RPM_BUILD_ROOT/%{_bindir}/campaignd $RPM_BUILD_ROOT/%{_sbindir}


### Wesnoth ships its own fonts, replace with Vine Linux packaged versions
## for 1.2.7 or higher (contains sazanami-gothic.ttf)
## for 1.6a or higher (NOT contains sazanami-gothic.ttf)
rm -f $RPM_BUILD_ROOT/%{_datadir}/%{name}/fonts/*
pushd ${RPM_BUILD_ROOT}%{_datadir}/%{name}/fonts/
%__ln_s /usr/share/fonts/TrueType-dejavu/DejaVuSans.ttf           DejaVuSans.ttf || exit 1
%__ln_s /usr/share/fonts/TrueType-vlgothic/VL-Gothic-Regular.ttf  sazanami-gothic.ttf || exit 1
%__ln_s /usr/share/fonts/TrueType-vlgothic/VL-Gothic-Regular.ttf  wqy-zenhei.ttc || exit 1
%__ln_s /usr/share/fonts/TrueType-droid/DroidSansFallbackFull.ttf . || exit 1
%__ln_s /usr/share/fonts/TrueType-droid/DroidSansJapanese.ttf     . || exit 1
popd

### Register as an application to be visible in the software center
##
## NOTE: It would be *awesome* if this file was maintained by the upstream
## project, translated and installed into the right place during `make install`.
##
## See http://www.freedesktop.org/software/appstream/docs/ for more details.
##
mkdir -p $RPM_BUILD_ROOT%{_datadir}/appdata
cp %{SOURCE3} $RPM_BUILD_ROOT%{_datadir}/appdata/%{name}.appdata.xml


# ### 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 256x256 512x512; 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

# 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

### language stuff
%find_lang %{name} --all-name --with-man


%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


%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


%files -f %{name}.lang
%defattr(-,root,root)
%doc COPYING changelog README.md copyright
%docdir %{_docdir}/wesnoth
%{_docdir}/wesnoth
%{_bindir}/%{name}
%{_datadir}/%{name}
%{_datadir}/appdata/%{name}.appdata.xml
%{_datadir}/applications/wesnoth.desktop
%{_datadir}/wesnoth/fonts/*
%{_datadir}/icons/*
%{python_sitelib}/wesnoth
%{_mandir}/man6/wesnoth*.6.gz
%{_mandir}/*/man6/wesnoth*.6.gz

%files tools
%defattr(-,root,root)
%{_bindir}/wesnoth_addon_manager
%{_bindir}/exploder
%{_bindir}/cutter
%{_bindir}/wml*

%files server
%defattr(-,root,root)
%{_initrddir}/wesnothd
%config(noreplace) %{_sysconfdir}/sysconfig/wesnoth
%{_sbindir}/wesnothd
%{_sbindir}/campaignd
%attr(0700,wesnothd,wesnothd) %dir /var/run/wesnothd/
%ghost /var/run/wesnothd/socket


%changelog
* Thu Jan 21 2016 Munehiro Yamamoto <munepi@vinelinux.org> 1.12.5
- new upstream release
- Wesnoth ships its own fonts, replace with Vine Linux packaged versions
  - Requires: TrueType-vlgothic TrueType-dejavu-sans TrueType-droid-sans
- supported server, tools packages

* 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
