%define srcversion %(echo "%{version}src" | %{__sed} 's/\\.//')
%define interversion %(echo %{version} | %{__sed} 's/\\./_/')

Summary: Super Nintendo Enter System(SNES) emulator
Summary(ja): スーパーファミコン(SNES)のエミュレーター
Name: zsnes
Version: 1.51
Release: 3%{?_dist_release}
License: GPLv2
Group: Applications/Emulators
URL: http://www.zsnes.com/
Source0: http://prdownloads.sourceforge.net/%{name}/%{name}%{srcversion}.tar.bz2
# Source Mage
Patch1: zsnes-1.51-Makefile.in.FIX.BROKENESS.patch
# Hans de Goede
Patch2: zsnes-1.51-FORTIFY_SOURCE.patch
# Paul Bender (minimyth)
Patch3: zsnes-1.51-gcc43.patch
# Upstream CVS
Patch4: zsnes-1.51-pulseaudio.patch

Requires: SDL >= 1.2.0 
Requires: hicolor-icon-theme
BuildRequires: automake
BuildRequires: nasm >= 0.98 
BuildRequires: zlib >= 1.1.0 
BuildRequires: libpng >= 1.2.0
BuildRequires: SDL-devel >= 1.2.0 
BuildRequires: zlib-devel >= 1.1.0 
BuildRequires: libpng-devel >= 1.2.0 
BuildRequires: ncurses-devel
BuildRequires: libao-devel
BuildRequires: desktop-file-utils
%if %{?_dist_release} != "vl4"
Requires: mesa-libGL
BuildRequires: xorg-x11-devel 
BuildRequires: mesa-libGL-devel
%else
Requires: XOrg-gl
BuildRequires: XOrg-devel 
BuildRequires: XOrg-gl-devel
%endif
BuildRoot: %{_tmppath}/%{name}-%{version}-root
ExclusiveArch: %{ix86}

%description
ZSNES is one of Super Nintendo Entertainment System (SNES) emulators. 

%desctiption -l ja
ZSNESはスーパーファミコンエミュレーターの1つです。

%prep
%{__rm} -rf %{buildroot}

%setup -q -n %{name}_%{interversion}/src
%patch1 -p2
%patch2 -p2
%patch3 -p2
%patch4 -p2

# Remove hardcoded CFLAGS and LDFLAGS
%{__sed} -i \
  -e 's:^\s*CFLAGS=.* -D__RELEASE__.*$:CFLAGS="$CFLAGS -D__RELEASE__":' \
  -e 's:^\s*CFLAGS=.* -I\/usr\/local\/include .*$:CFLAGS="${CFLAGS} -I.":' \
  -e '/^\s*LDFLAGS=.* -L\/usr\/local\/lib /d' \
  configure.in

# Fix line encodings in docs/readme.txt/*
%{__sed} -i 's/\r//' ../docs/readme.txt/*.txt

# Fix char encondigs
iconv --from=ISO-8859-1 --to=UTF-8 ../docs/readme.txt/games.txt > \
    ../docs/readme.txt/games.txt.utf8
%__mv ../docs/readme.txt/games.txt.utf8 ../docs/readme.txt/games.txt
iconv --from=ISO-8859-1 --to=UTF-8 ../docs/readme.txt/support.txt > \
    ../docs/readme.txt/support.txt.utf8
%__mv ../docs/readme.txt/support.txt.utf8 ../docs/readme.txt/support.txt

# Remove icon extension from desktop file
%{__sed} -i -e 's/^Icon=%{name}.png$/Icon=%{name}/g' \
    linux/%{name}.desktop

%build
aclocal
autoconf

%configure \
  --enable-libao \
  --enable-release \
  --disable-cpucheck force_arch="%{_arch}"
%{__make} %{?_smp_mflags}

%install
%__rm -rf %{buildroot}
%__make DESTDIR=%{buildroot} install

# install desktop file
%__mkdir_p %{buildroot}%{_datadir}/applications
desktop-file-install \
  --vendor vine \
  --remove-category Application \
  --dir %{buildroot}%{_datadir}/applications \
  linux/%{name}.desktop

# install icons
for px in 16 32 48 64; do 
    size=${px}x${px}
    %__mkdir_p %{buildroot}%{_datadir}/icons/hicolor/${size}/apps
    %__install -m 644 icons/${size}x32.png \
        %{buildroot}%{_datadir}/icons/hicolor/16x16/apps/zsnes.png || exit 1
done

%clean
%{__rm} -rf %{buildroot}

%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


%files
%defattr(-,root,root)
%doc ../docs/authors.txt ../docs/license.txt ../docs/README.LINUX
%doc ../docs/support.txt ../docs/thanks.txt ../docs/todo.txt
%doc ../docs/readme.htm/ ../docs/readme.txt/
%{_bindir}/zsnes
%{_mandir}/man1/zsnes.1*
%{_datadir}/applications/vine-%{name}.desktop
%{_datadir}/icons/hicolor/*/apps/%{name}.png


%changelog
* Sun Jun 19 2011 Munehiro Yamamoto <munepi@vinelinux.org> 1.51-3
- applied zsnes-1.51-gcc43.patch, zsnes-1.51-pulseaudio.patch

* Tue May 26 2009 Munehiro Yamamoto <munepi@cg8.so-net.ne.jp> 1.51-2
- change release to sync with self-build-zsnes

* Mon Nov 02 2008 Munehiro Yamamoto <munepi@cg8.so-net.ne.jp> 1.51-1
- applied new versioning policy 
- spec in utf8
- dropped NoSource: 0
- applied zsnes-1.51-Makefile.in.FIX.BROKENESS.patch, 
  zsnes-1.51-FORTIFY_SOURCE.patch
#, zsnes-1.51-gcc43.patch
- added Requires: hicolor-icon-theme
  BuildRequires: automake ncurses-devel libao-devel desktop-file-utils
- For vl5, added Requires: mesa-libGL
  BuildRequires: xorg-x11-devel mesa-libGL-devel
- fixed ExclusiveArch: %{ix86}

* Thu Jun 28 2007 1.51-0vl2
- Set NoSource: 0

* Sat Jun 9 2007 1.51-0vlmp1
- Rename 0vl1 to 0vlmp1

* Tue Mar 9 2007 1.51-0vl1
- initial build for Vine Linux

* Sun Feb 25 2007 1.51-0vlmp1
- updated 1.51 for Vine Linux 4.x

* Mon May 9 2005 1.42-0vl1
- initial build for Vine Linux

# end of file
