## set Qt4 for make
%define my_make    %__make QTPATH=${QTDIR} QTINCLUDE="-I ${QTDIR}/../include" MOC=%{_libdir}/qt4/bin/moc LDFLAGS="-L $QTDIR"


Name:           fbreader
Version:        0.12.10
Release:        1%{?_dist_release}
Summary:        E-book reader

Group:          Applications/Publishing
License:        GPLv2+
URL:            http://www.fbreader.org/
Source0:        http://www.fbreader.org/fbreader-sources-%{version}.tgz
Source1:        README.Fedora
Patch0:         fbreader-0.12.9-desktop-file.patch
Patch1:         fbreader-optflags.patch
# Use to expose the compiler flags used during build
# Patch2:         fbreader-debug.patch
Patch3:         fbreader-defaults.patch
BuildRoot:      %{_tmppath}/%{name}-%{version}-root

BuildRequires:  expat-devel bzip2-devel liblinebreak-devel
BuildRequires:  gtk2-devel fribidi-devel
BuildRequires:  curl-devel >= 7.17
BuildRequires:  libjpeg-devel desktop-file-utils
BuildRequires:  qt4-devel sqlite3-devel

# needed because sometimes the API change without soname bump
Requires:       zlibrary = %{version}-%{release}


%description
FBReader is an e-book reader, with the following main features:

* Supports several formats: fb2, HTML, CHM, plucker, Palmdoc, zTxt
  (Weasel), TCR (psion), RTF, OEB, OpenReader, mobipocket, plain text.
* Direct reading from tar, zip, gzip and bzip2 archives. (Multiple
  books in one archive are supported.)
* Automatic library building.
* Automatic encoding detection is supported.
* Automatically generated contents table.
* Embedded images support.
* Footnotes/hyperlinks support.
* Position indicator.
* Keeps the last open book and the last read positions for all opened
  books between runs.
* List of last opened books.
* Automatic hyphenations. Liang's algorithm is used. The same
  algorithm is used in TeX, and TeX hyphenation patterns are used in
  FBReader. Patterns for Czech, English, Esperanto, French, German and
  Russian are included in the current version.
* Text search.
* Full-screen mode.
* Screen rotation by 90, 180 and 270 degrees.
#'

%package        gtk
Summary:        E-book reader (GTK+ interface)
Group:          Applications/Publishing
Requires:       %{name} = %{version}-%{release}
Requires:       zlibrary-ui-gtk = %{version}-%{release}

%description    gtk
A virtual package that bundles both the FBreader e-book reader and its
GTK+ user interface.


%package        qt
Summary:        E-book reader (Qt interface)
Group:          Applications/Publishing
Requires:       %{name} = %{version}-%{release}
Requires:       zlibrary-ui-qt = %{version}-%{release}

%description    qt
A virtual package that bundles both the FBreader e-book reader and its
Qt4 user interface.


%package -n     zlibrary
Summary:        Cross-platform GUI library
Group:          System Environment/Libraries
Requires:       zlibrary-ui = %{version}-%{release}

%description -n zlibrary
ZLibrary is a cross-platform library to build applications running on
desktop Linux, Windows, and different Linux-based PDAs.


%package -n     zlibrary-devel
Summary:        Development files for zlibrary
Group:          Development/Libraries
Requires:       zlibrary = %{version}-%{release}

%description -n zlibrary-devel
This package contains the libraries amd header files that are needed
for writing applications with Zlibrary.


%package -n     zlibrary-ui-gtk
Summary:        GTK+ interface module for ZLibrary
Group:          System Environment/Libraries
Provides:       zlibrary-ui = %{version}-%{release}

Requires(posttrans): /sbin/update-alternatives
Requires(postun):    /sbin/update-alternatives

%description -n zlibrary-ui-gtk
ZLibrary is a cross-platform library to build applications running on
desktop Linux, Windows, and different Linux-based PDAs.

This package provides a GTK+-based UI for ZLibrary.


%package -n     zlibrary-ui-qt
Summary:        Qt4 interface module for ZLibrary
Group:          System Environment/Libraries
Provides:       zlibrary-ui = %{version}-%{release}
Provides:       zlibrary-ui-qt4 = %{version}-%{release}
Obsoletes:      zlibrary-ui-qt4 < %{version}-%{release}

Requires(posttrans): /sbin/update-alternatives
Requires(postun):    /sbin/update-alternatives

%description -n zlibrary-ui-qt
ZLibrary is a cross-platform library to build applications running on
desktop Linux, Windows, and different Linux-based PDAs.

This package provides a Qt4-based UI for ZLibrary.

%prep
%setup -q
%patch0 -p1 -b .desktop-file
%patch1 -p0 -b .optflags
#%patch2 -p0 -b .debug
%patch3 -p0 -b .defaults
cp -p %{SOURCE1} .


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

%my_make %{?_smp_mflags} -C zlibrary/core TARGET_ARCH=desktop \
     LIBDIR=%{_libdir} UI_TYPE=dummy
%my_make %{?_smp_mflags} -C zlibrary/text TARGET_ARCH=desktop \
     LIBDIR=%{_libdir} UI_TYPE=dummy
%my_make %{?_smp_mflags} -C zlibrary/ui TARGET_ARCH=desktop \
     LIBDIR=%{_libdir} UI_TYPE=gtk
%my_make %{?_smp_mflags} -C zlibrary/ui TARGET_ARCH=desktop \
     LIBDIR=%{_libdir} UI_TYPE=qt4
%my_make %{?_smp_mflags} -C fbreader TARGET_ARCH=desktop \
     LIBDIR=%{_libdir} UI_TYPE=dummy


%install
%__rm -rf $RPM_BUILD_ROOT
%__make -C zlibrary/core do_install do_install_dev \
     DESTDIR=$RPM_BUILD_ROOT TARGET_ARCH=desktop \
     LIBDIR=%{_libdir} UI_TYPE=dummy
%__make -C zlibrary/text do_install do_install_dev \
     DESTDIR=$RPM_BUILD_ROOT TARGET_ARCH=desktop \
     LIBDIR=%{_libdir} UI_TYPE=dummy
%__make -C zlibrary/ui do_install DESTDIR=$RPM_BUILD_ROOT TARGET_ARCH=desktop \
     LIBDIR=%{_libdir} UI_TYPE=gtk
%__make -C zlibrary/ui do_install DESTDIR=$RPM_BUILD_ROOT TARGET_ARCH=desktop \
     LIBDIR=%{_libdir} UI_TYPE=qt4
%__make -C fbreader do_install DESTDIR=$RPM_BUILD_ROOT TARGET_ARCH=desktop \
     UI_TYPE=dummy

desktop-file-install --vendor="vine" \
    --remove-category="Application" \
    --delete-original \
    --dir=%{buildroot}%{_datadir}/applications \
    %{buildroot}%{_datadir}/applications/FBReader.desktop


%clean
%__rm -rf $RPM_BUILD_ROOT


%post -n zlibrary -p /sbin/ldconfig

%postun -n zlibrary -p /sbin/ldconfig

%posttrans -n zlibrary-ui-gtk
/sbin/update-alternatives \
  --install \
  %{_libdir}/zlibrary/ui/zlui-active.so \
  zlibrary-ui \
  %{_libdir}/zlibrary/ui/zlui-gtk.so \
  2

%posttrans -n zlibrary-ui-qt
/sbin/update-alternatives \
  --install \
  %{_libdir}/zlibrary/ui/zlui-active.so \
  zlibrary-ui \
  %{_libdir}/zlibrary/ui/zlui-qt4.so \
  1

%postun -n zlibrary-ui-gtk
if [ $1 -eq 0 ]; then
    /sbin/update-alternatives --remove zlibrary-ui \
	%{_libdir}/zlibrary/ui/zlui-gtk.so
fi
exit 0

%postun -n zlibrary-ui-qt
if [ $1 -eq 0 ]; then
    /sbin/update-alternatives --remove unison \
	%{_libdir}/zlibrary/ui/zlui-qt4.so
fi
exit 0

%files
%defattr(-,root,root,-)
%doc fbreader/LICENSE README.Fedora
%{_bindir}/FBReader
%{_datadir}/FBReader
%{_datadir}/applications/*-FBReader.desktop
%{_datadir}/pixmaps/FBReader.png
%{_datadir}/pixmaps/FBReader

%files gtk
%files qt

%files -n zlibrary
%defattr(-,root,root,-)
%doc fbreader/LICENSE
%{_libdir}/lib*.so.*
%dir %{_libdir}/zlibrary
%dir %{_libdir}/zlibrary/ui
%exclude %{_datadir}/zlibrary/keynames-*.xml
%{_datadir}/zlibrary

%files -n zlibrary-devel
%defattr(-,root,root,-)
%{_includedir}/*
%{_libdir}/lib*.so

%files -n zlibrary-ui-gtk
%defattr(-,root,root,-)
%{_libdir}/zlibrary/ui/zlui-gtk.so
%{_datadir}/zlibrary/keynames-gtk.xml

%files -n zlibrary-ui-qt
%defattr(-,root,root,-)
%{_libdir}/zlibrary/ui/zlui-qt4.so
%{_datadir}/zlibrary/keynames-qt4.xml



%changelog
* Thu Aug 12 2010 Munehiro Yamamoto <munepi@vinelinux.org> - 0.12.10-1
- initial build based on Fedora development

* Mon Jun  7 2010 Michel Salim <salimma@fedoraproject.org> - 0.12.10-1
- Update to 0.12.10

* Sun Mar 28 2010 Michel Salim <salimma@fedoraproject.org> - 0.12.9-1
- Update to 0.12.9

* Sat Feb 13 2010 Michel Salim <salimma@fedoraproject.org> - 0.12.2-1
- Update to 0.12.2
- Fix overlap between fbreader and zlibrary

* Tue Jan 26 2010 Michel Salim <salimma@fedoraproject.org> - 0.12.1-1
- Update to 0.12.1

* Sat Oct 17 2009 Michel Salim <salimma@fedoraproject.org> - 0.10.7-4
- Provide virtual packages for each available interface
- Use alternatives to select the user interface (see README.Fedora)

* Thu Sep 17 2009 Michel Salim <salimma@fedoraproject.org> - 0.10.7-3
- Split out zlibrary and zlibrary-ui subpackages (fixes bz# 523946)

* Fri Jul 24 2009 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 0.10.7-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_12_Mass_Rebuild

* Tue Mar 31 2009 Michel Salim <salimma@fedoraproject.org> - 0.10.7-1
- Update to 0.10.7

* Tue Feb 24 2009 Michel Salim <salimma@fedoraproject.org> - 0.10.3-3
- Fix for GCC 4.4

* Tue Feb 24 2009 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 0.10.3-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_11_Mass_Rebuild

* Thu Feb  5 2009 Michel Salim <salimma@fedoraproject.org> - 0.10.3-1
- Update to 0.10.3

* Wed Jan 28 2009 Michel Salim <salimma@fedoraproject.org> - 0.10.2-1
- Update to 0.10.2

* Wed Jan 14 2009 Michel Salim <salimma@fedoraproject.org> - 0.10.0-1
- Update to 0.10.0

* Thu Jul 31 2008 Michel Alexandre Salim <salimma@fedoraproject.org> - 0.8.17-1
- Update to 0.8.17

* Tue Feb 19 2008 Fedora Release Engineering <rel-eng@fedoraproject.org> - 0.8.12-2
- Autorebuild for GCC 4.3

* Sun Jan 20 2008 Michel Alexandre Salim <michel.sylvan@gmail.com> - 0.8.12-1
- Update to 0.8.12

* Mon Jan  7 2008 Michel Alexandre Salim <michel.sylvan@gmail.com> - 0.8.10-1
- Update to 0.8.10
- Remove workaround for PDB issues on x86_64; fixed upstream

* Thu Dec 20 2007 Michel Alexandre Salim <michel.sylvan@gmail.com> - 0.8.8a-1
- Update to 0.8.8a
- Workaround for PDB format handler when reading certain files

* Wed Dec 19 2007 Michel Alexandre Salim <michel.sylvan@gmail.com> - 0.8.8-2
- Fix inclusion of debug files where libdir=/usr/lib (bz #411891)

* Sun Dec  2 2007 Michel Alexandre Salim <michel.sylvan@gmail.com> - 0.8.8-1
- Update to 0.8.8

* Thu Oct 18 2007 Michel Alexandre Salim <michel.sylvan@gmail.com> - 0.8.6d-3
- Generate proper -debuginfo subpackage (bz #329841, Ville Skytta)
- Add README.Fedora detailing zTXT bug on x86_64

* Sat Sep 22 2007 Michel Alexandre Salim <michel.sylvan@gmail.com> - 0.8.6d-2
- Fix vendor tag
- Use compiler flags provided by the system

* Sun Sep 16 2007 Michel Alexandre Salim <michel.sylvan@gmail.com> - 0.8.6d-1
- Initial package
