%define _qt4_ver 4.8.0
%define _qt4_version %(pkg-config --modversion --silence-errors Qt 2>/dev/null || echo %{qt4_ver})
%define _qt4_prefix %(pkg-config --variable prefix --silence-errors Qt 2>/dev/null || echo %{_libdir}/qt4)
%define _qt4_plugindir %(pkg-config --variable plugindir --silence-errors Qt 2>/dev/null || echo %{_qt4_prefix}/plugins)

## Can be either MYSQL(uptsream default), SQLITE, or POSTGRES(untested)
%global database_backend SQLITE 

Name:    akonadi
Summary: PIM Storage Service
Summary(ja): PIM ストレージサービス
Version: 1.8.1
Release: 1%{?_dist_release}

Group:   System Environment/Libraries
License: LGPLv2+
URL:     http://download.akonadi-project.org/

Source0: http://download.akonadi-project.org/akonadi-%{version}.tar.bz2

%define mysql_conf_timestamp 20110629
# shrink default initial db size a bit (approx 140mb->28mb)
Patch1: akonadi-mysql_conf.patch

## upstream patches

BuildRoot: %{_tmppath}/%{name}-%{version}-root
BuildRequires: cmake >= 2.6.0
BuildRequires: qt4-devel >= 4.4
BuildRequires: automoc4
BuildRequires: MySQL-devel
BuildRequires: MySQL-server
# for xsltproc
BuildRequires: libxslt
BuildRequires: shared-mime-info
BuildRequires: libboost-devel libboost-program-options
BuildRequires: soprano-devel >= 2.5.0
BuildRequires: sqlite3-devel
BuildRequires: libICE-devel libXext-devel

Requires: qt4 >= %{_qt4_version}

%if "%{?database_backend}" == "MYSQL"
Requires: qt4-MySQL
# not *strictly* required, but we need a functional default configuration
Requires: MySQL-server
%endif

Obsoletes: akonadi-sqlite < %{version}-%{release}

Requires(post): /sbin/ldconfig
Requires(postun): /sbin/ldconfig

%description
%{summary}.
%if "%{?database_backend}" == "MYSQL"
Requires an available instance of mysql server at runtime.  
Akonadi can spawn a per-user one automatically if the mysql-server 
package is installed on the machine.
See also: %{_sysconfdir}/akonadi/mysql-global.conf
%endif

%package devel
Summary: Developer files for %{name}
Summary(ja): %{name} の開発用ファイル
Group:   Development/Libraries
Requires: %{name} = %{version}-%{release}
Requires: qt4-devel

%description devel
%{summary}.


%prep
%setup -q 
#%patch1 -p1 -b .mysql_conf
#touch -d %{mysql_conf_timestamp} server/src/storage/mysql-global.conf

%build
%ifarch x86_64
PATH="$PATH:`/usr/bin/pkg-config --variable=bindir Qt`"
%endif

mkdir -p %{_target_platform}
pushd %{_target_platform}
%cmake \
    -DCONFIG_INSTALL_DIR=%{_sysconfdir} \
    -DINSTALL_QSQLITE_IN_QT_PREFIX:PATH=%{_qt4_plugindir} \
    %{?database_backend:-DDATABASE_BACKEND=%{database_backend}} \
    ..
popd

make %{?_smp_mflags} -C %{_target_platform}


%install
rm -rf $RPM_BUILD_ROOT
make install DESTDIR=$RPM_BUILD_ROOT -C %{_target_platform}

mkdir -p $RPM_BUILD_ROOT%{_datadir}/akonadi/agents

# create "big" config (analog to -mobile.conf)
install -p \
    $RPM_BUILD_ROOT%{_sysconfdir}/akonadi/mysql-global.conf \
    $RPM_BUILD_ROOT%{_sysconfdir}/akonadi/mysql-global-big.conf

# default to small/mobile config
install -p \
    $RPM_BUILD_ROOT%{_sysconfdir}/akonadi/mysql-global-mobile.conf \
    $RPM_BUILD_ROOT%{_sysconfdir}/akonadi/mysql-global.conf

touch -d %{mysql_conf_timestamp} \
    $RPM_BUILD_ROOT%{_sysconfdir}/akonadi/mysql-global*.conf \
    $RPM_BUILD_ROOT%{_sysconfdir}/akonadi/mysql-local.conf

# create/own %{_libdir}/akondi
mkdir -p $RPM_BUILD_ROOT%{_libdir}/akonadi

#%check
#make test -C %{_target_platform}
#export PKG_CONFIG_PATH=$RPM_BUILD_ROOT%{_datadir}/pkgconfig:$RPM_BUILD_ROOT%{_libdir}/pkgconfig
#test "$(pkg-config --modversion akonadi)" = "%{version}"

%clean
rm -rf $RPM_BUILD_ROOT

%post -p /sbin/ldconfig

%posttrans
update-mime-database %{_datadir}/mime &> /dev/null || :

%postun
/sbin/ldconfig ||:
if [ $1 -eq 0 ] ; then
    update-mime-database %{_datadir}/mime &> /dev/null ||:
fi


%files
%defattr(-,root,root,-)
%doc AUTHORS lgpl-license
%dir %{_sysconfdir}/akonadi
# example conf's
%{_sysconfdir}/akonadi/mysql-global-big.conf
%{_sysconfdir}/akonadi/mysql-global-mobile.conf
%config(noreplace) %{_sysconfdir}/akonadi/mysql-global.conf
%config(noreplace) %{_sysconfdir}/akonadi/mysql-local.conf
%{_bindir}/akonadi_agent_launcher
%{_bindir}/akonadi_agent_server
%{_bindir}/akonadi_control
%{_bindir}/akonadi_rds
%{_bindir}/akonadictl
%{_bindir}/akonadiserver
%{_libdir}/libakonadi*.so.1*
%{_datadir}/dbus-1/interfaces/org.freedesktop.Akonadi.*.xml
%{_datadir}/dbus-1/services/org.freedesktop.Akonadi.*.service
%{_datadir}/mime/packages/akonadi-mime.xml
%{_datadir}/akonadi
%{_qt4_plugindir}/sqldrivers/libqsqlite3.so

%files devel
%defattr(-,root,root,-)
%{_includedir}/akonadi
%{_libdir}/pkgconfig/akonadi.pc
%{_libdir}/libakonadi*.so
%{_libdir}/cmake/Akonadi


%changelog
* Sun Nov 04 2012 Yoji TOYODA <bsyamato@sea.plala.or.jp> - 1.8.1-1
- new upstream release

* Sun Jul 29 2012 Yoji TOYODA <bsyamato@sea.plala.or.jp> - 1.8.0-1
- new upstream release

* Mon Jan  9 2012 Ryoichi INAGAKI <ryo1@bc.wakwak.com> - 1.6.2-2
- rebuilt with qt-4.8.0

* Sun Oct 16 2011 Ryoichi INAGAKI <ryo1@bc.wakwak.com> - 1.6.2-1
- new upstream release

* Sun Sep 25 2011 Ryoichi INAGAKI <ryo1@bc.wakwak.com> - 1.6.1-1
- new upstream release

* Sat Aug 20 2011 Ryoichi INAGAKI <ryo1@bc.wakwak.com> - 1.6.0-2
- rebuilt with soprano-2.7.0-2

* Sat Jul 30 2011 Ryoichi INAGAKI <ryo1@bc.wakwak.com> - 1.6.0-1
- new upstream release

* Thu Mar 10 2011 Ryoichi INAGAKI <ryo1@bc.wakwak.com> - 1.5.0-2
- rebuilt with qt4-4.7.2

* Mon Jan 31 2011 Ryoichi INAGAKI <ryo1@bc.wakwak.com> - 1.5.0-1
- new upstream release

* Mon Sep 20 2010 Ryoichi INAGAKI <ryo1@bc.wakwak.com> - 1.4.0-2
- rebuilt with rpm-4.8.1

* Sun Aug 15 2010 Ryoichi INAGAKI <ryo1@bc.wakwak.com> - 1.4.0-1
- new upstream release
- added BR: sqlite3-devel
- added sqlite subpackage

* Sun Apr 11 2010 Ryoichi INAGAKI <ryo1@bc.wakwak.com> - 1.3.1-3
- new upstream release

* Sun Apr 11 2010 Ryoichi INAGAKI <ryo1@bc.wakwak.com> - 1.3.1-3
- updated Patch1
- added BR: MySQL-server

* Sun Feb 14 2010 Shu KONNO <owa@bg.wakwak.com> - 1.3.1-2
- added qmake path to PATH (if x86_64)

* Sat Feb 13 2010 Ryoichi INAGAKI <ryo1@bc.wakwak.com> - 1.3.1-1
- new upstream release
- built with new toolchain

* Thu Sep 10 2009 Ryoichi INAGAKI <ryo1@bc.wakwak.com> - 1.2.1-1
- new upstream release

* Wed Sep 02 2009 NAKAMURA Kenta <kenta@vinelinux.org> - 1.2.0-4
- use %%cmake macro
- removed MySQL-server from BuildRequires:

* Sat Aug 29 2009 Ryoichi INAGAKI <ryo1@bc.wakwak.com> - 1.2.0-3
- fixed Requires

* Sat Aug 15 2009 Ryoichi INAGAKI <ryo1@bc.wakwak.com> - 1.2.0-2
- Initial build for Vine

* Thu Jul 30 2009 Lukáš Tinkl <ltinkl@redhat.com> - 1.2.0-1
- Akonadi 1.2.0

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

* Thu Jun 25 2009 Than Ngo <than@redhat.com> - 1.1.95-1
- 1.1.95

* Wed Jun 03 2009 Rex Dieter <rdieter@fedoraproject.org> 1.1.90-1
- akonadi-1.1.90

* Tue May 26 2009 Rex Dieter <rdieter@fedoraproject.org> 1.1.85-3
- akonadi.pc.cmake: s/AKONADI_LIB_VERSION_STRING/AKONADI_VERSION_STRING/

* Tue May 12 2009 Than Ngo <than@redhat.com> 1.1.85-2
- fix rpm file list

* Wed May 06 2009 Rex Dieter <rdieter@fedoraproject.org> - 1.1.85-1
- akonadi-1.1.85

* Thu Apr 30 2009 Rex Dieter <rdieter@fedoraproject.org> - 1.1.2-1
- akonadi-1.1.2
- optimize scriptlets a bit

* Wed Feb 25 2009 Rex Dieter <rdieter@fedoraproject.org> - 1.1.1-6
- rev startup patch
- BR: cmake >= 2.6.0
- preserve timestamp's on mysql*.conf's

* Tue Feb 24 2009 Rex Dieter <rdieter@fedoraproject.org> - 1.1.1-5
- own %%_sysconfig/akonadi/mysql-local.conf
- startup patch: reset conf only when needed, and clear mysql log file on update

* Mon Feb 23 2009 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 1.1.1-4
- Rebuilt for https://fedoraproject.org/wiki/Fedora_11_Mass_Rebuild

* Fri Feb 20 2009 Rex Dieter <rdieter@fedoraproject.org> - 1.1.1-3
- shrink default db initial size a bit (approx 140mb->28mb)
- drop extraneous RPATH-cmake baggage

* Wed Jan 21 2009 Rex Dieter <rdieter@fedoraproject.org> - 1.1.1-1
- 1.1.1

* Sun Jan 04 2009 Rex Dieter <rdieter@fedoraproject.org> - 1.1.0-1
- 1.1.0

* Tue Dec 16 2008 Rex Dieter <rdieter@fedoraproject.org> - 1.0.81-1
- 1.0.81

* Mon Dec 08 2008 Rex Dieter <rdieter@fedoraproject.org> - 1.0.80-3
- restore Requires: mysql-server

* Mon Dec 01 2008 Kevin Kofler <Kevin@tigcc.ticalc.org> - 1.0.80-2
- own /usr/share/akonadi and /usr/share/akonadi/agents (#473595)

* Wed Nov 26 2008 Than Ngo <than@redhat.com> -  1.0.80-1
- 1.0.80

* Wed Oct 22 2008 Rex Dieter <rdieter@fedoraproject.org> 1.0.0-4
- drop Requires: mysql-server (for now), mention in %%description

* Wed Jul 30 2008 Rex Dieter <rdieter@fedoraproject.org> 1.0.0-3
- Requires: mysql-server

* Wed Jul 30 2008 Rex Dieter <rdieter@fedoraproject.org> 1.0.0-2
- BR: mysql-server
- Requires: qt4-mysql
- cleanup spec

* Wed Jul 23 2008 Than Ngo <than@redhat.com> -  1.0.0-1
- 1.0.0

* Wed Jun 18 2008 Rex Dieter <rdieter@fedoraproject.org> 0.82.0-1
- akonadi-0.82.0

* Tue Jun  3 2008 Kevin Kofler <Kevin@tigcc.ticalc.org> 0.81.0-0.2.20080526svn812787
- BR automoc, drop automoc hack

* Mon May 26 2008 Kevin Kofler <Kevin@tigcc.ticalc.org> 0.81.0-0.1.20080526svn812787
- update to revision 812787 from KDE SVN (to match KDE 4.1 Beta 1)
- restore builtin automoc4 for now
- update file list, require pkgconfig in -devel (.pc file now included)

* Mon May  5 2008 Kevin Kofler <Kevin@tigcc.ticalc.org> 0.80.0-2
- -devel: remove bogus Requires: pkgconfig

* Sat May  3 2008 Kevin Kofler <Kevin@tigcc.ticalc.org> 0.80.0-1
- first Fedora package
