%define pkgname Sigil

%define _qt4_qmake		%{_libdir}/qt4/bin/qmake

Name:		sigil
Version:	0.3.4
Release:	2%{?_dist_release}
Summary:	A WYSIWYG ebook editor
Summary(ja):	WYSIWYG 電子書籍エディタ
License:	GPLv3
Group:          Applications/Publishing
Url:		http://sigil.googlecode.com/
Source0:	http://sigil.googlecode.com/files/%{pkgname}-%{version}-Code.zip

## Vine
Source10:	sigil.desktop

Patch0:		sigil-0.2.2-fix-format-string.patch
# from Anssi: this makes it use system libs instead of bundled ones. Except for
# libtidy which has some local hacks not present in system-provided libtidy.
Patch1:		sigil-0.3.4-use-system-libs-vine.patch
Patch2:		sigil-0.3.4-add-msse2-only-on-x86-archs.patch

BuildRequires:  desktop-file-utils
BuildRequires:	unzip
BuildRequires:	zlib-devel
BuildRequires:	bzip2-devel
BuildRequires:	cmake >= 2.6.0
BuildRequires:	qt4-devel >= 4.7.0
BuildRequires:	libboost-devel
BuildRequires:	libboost-thread
BuildRequires:	libboost-date-time
BuildRequires:	libboost-filesystem
BuildRequires:	libboost-regex
#BuildRequires:	xerces-c-devel

BuildRoot: 	%{_tmppath}/%{name}-%{version}-root

Distribution:	Vine
Vendor:		Project Vine
Packager:	munepi

%description
Sigil is a free, open source WYSIWYG ebook editor.
It is designed to edit books in ePub format.

%description -l ja
Sigil はオープンソース WYSIWYG 電子書籍エディタです。
ePub 形式の電子書籍を編集するように設計されています。


%prep
%setup -q -n %{pkgname}-%{version}-Code
%patch0 -p0 -b .format-string
%patch1 -p1 -b .system-libs
%patch2 -p1 -b .x86-archs-only

#%__rm -fr src/BoostParts
# fix end of line encoding for the docs:
%__sed -i 's/\r//' ChangeLog.txt README.txt COPYING.txt

%build
unset QTDIR || : ; . /etc/profile.d/qt4.sh

## from sigil-0.3.4-1mdv2011.0
# there are only internal helper libs, and they need to be static as build
# fails otherwise (they contain undefined symbols), and making them shared
# libs wouldn't make sense anyway (they are not shared by anything else)
# - Anssi 06/2010
%__cmake -G "Unix Makefiles" \
    -DBUILD_SHARED_LIBS:BOOL=OFF -DBUILD_STATIC_LIBS:BOOL=ON \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=%{_prefix} \
    -DLIB_INSTALL_DIR:PATH=%{_libdir} \
    -DQT_QMAKE_EXECUTABLE=%_qt4_qmake \
    ;

%__make %{?_smp_mflags}


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

# remove unused files
%__rm %{buildroot}%{_datadir}/pixmaps/sigil.png || exit 1
%__rm %{buildroot}%{_datadir}/applications/sigil.desktop || exit 1

# install icons for the .desktop file
for i in 16 32 48 128 256 512; do
    [ -f src/Sigil/Resource_Files/icon/app_icon_${i}.png ] || exit 1
    %__install -m644 -D src/Sigil/Resource_Files/icon/app_icon_${i}.png \
	%{buildroot}%{_datadir}/icons/hicolor/${i}x${i}/apps/sigil.png || exit 1
done

# create a .desktop file:
%__mkdir_p %{buildroot}%{_datadir}/applications

desktop-file-install --vendor="vine" \
    --dir=%{buildroot}%{_datadir}/applications \
    %{SOURCE10}

%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 
update-desktop-database &> /dev/null || :

%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 
update-desktop-database &> /dev/null || :


%files
%defattr(-,root,root)
%doc ChangeLog.txt README.txt COPYING.txt INSTALL.txt
%{_bindir}/%{name}
%{_datadir}/applications/*-%{name}.desktop
%{_datadir}/icons/hicolor/*/apps/*.png

%changelog
* Sat Jun 11 2011 MATSUBAYASHI Kohji <shaolin@vinelinux.org> - 0.3.4-2
- add Patch2 to fix build failure on ppc

* Sun Feb 20 2011 Munehiro Yamamoto <munepi@vinelinux.org> 0.3.4-1
- new upstream release
- added BuildRequires: libboost-filesystem, libboost-regex

* Fri Jan 21 2011 Munehiro Yamamoto <munepi@vinelinux.org> 0.2.4-2
- rebuilt with current libboost

* Sat Aug 21 2010 Munehiro Yamamoto <munepi@vinelinux.org> 0.2.4-1
- initial build