%{!?use_system_mysql:%define use_system_mysql 0}

%define mysql_base_version %{__mariadb_base_version}
%define mysql_version %{__mariadb_version}
%define mysql_release %{__mariadb_release}

%define groonga_required_version 4.0.6

Name:		mariadb-mroonga
Version:	4.06
Release:	1%{?_dist_release}
Summary:	A fast fulltext searchable storage engine for MariaDB.

Group:		Applications/Databases
License:	LGPLv2.1
URL:		http://mroonga.github.com/
Source0:	http://github.com/downloads/mroonga/mroonga/mroonga-%{version}.tar.gz
### the next release may include the follwing patches.
#Patch0:		4a3d6c77a9.patch
#Patch1:		171fa019d4.patch

BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-%(%{__id_u} -n)
BuildRequires:	groonga-devel >= %{groonga_required_version}
BuildRequires:	groonga-normalizer-mysql-devel pcre-devel
BuildRequires:	mariadb-source
%if "%{?mysql_version}" != ""
Requires:	mariadbserver-%{mysql_base_version}
Requires:	mariadbclient-%{mysql_base_version}
%endif
Requires:	groonga-libs >= %{groonga_required_version}
Requires:	groonga-normalizer-mysql
Obsoletes: MySQL-mroonga < 4.00

Vendor: Project Vine
Distribution: Vine Linux
Packager: tomop

%description
Mroonga is a fast fulltext searchable storage plugin for MariaDB.
It is based on groonga that is a fast fulltext search engine and
column store. Groonga is good at real-time update.

%package doc
Summary:	Documentation for mroonga
Group:		Documentation
License:	LGPLv2.1

%description doc
Documentation for mroonga


%prep
%setup -q -n mroonga-%{version}
#%patch0 -p1 -b .private
#%patch1 -p1 -b .LOCK_open

%build
mysql_source=%{_datadir}/mariadb-source/mariadb-%{mysql_version}
%configure --disable-static --with-mysql-source=${mysql_source} \
    %{?mroonga_configure_options}
make %{?_smp_mflags}


%install
rm -rf %{buildroot}
make install DESTDIR=%{buildroot}
rm -f %{buildroot}%{_libdir}/mysql/plugin/*.la
mv -f %{buildroot}%{_datadir}/doc/mroonga/ mysql-mroonga-doc/

%clean
rm -rf %{buildroot}

%post
if [ "$1" = 1 ] ; then
	/usr/bin/mysql -u root < %{_datadir}/mroonga/install.sql || cat <<EOF
An error occured when to register plugin.
Please run a command below:

  /usr/bin/mysql -u root < %{_datadir}/mroonga/install.sql

EOF
fi

%preun
/usr/bin/mysql -u root < %{_datadir}/mroonga/uninstall.sql || cat <<EOF
An error occured when to register plugin.
Please run a command below:

  /usr/bin/mysql -u root < %{_datadir}/mroonga/uninstall.sql

EOF

if [ "$1" != 0 ]; then

    /usr/bin/mysql -u root < %{_datadir}/mroonga/install.sql || cat <<EOF
An error occured when to register plugin.
Please run a command below:

  /usr/bin/mysql -u root < %{_datadir}/mroonga/install.sql

EOF
fi

%files
%defattr(-,root,root,-)
%{_libdir}/mysql/plugin/*
%{_datadir}/man/man1/*
%{_datadir}/man/*/man1/*
%{_datadir}/mroonga

%files doc
%defattr(-,root,root,-)
%doc README COPYING
%doc mysql-mroonga-doc/*

%changelog
* Mon Sep 29 2014 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 4.06-1
- new upstream release.

* Sat May 31 2014 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 4.03-1
- new upstream release.
- removed Patch0 and Patch1.

* Sun Apr 13 2014 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 4.01-2
- fixed %%post and %%preun scripts.

* Fri Apr 11 2014 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 4.01-1
- new upstream release.
- added Patch0 and Patch1.

* Mon Mar 24 2014 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 4.00-2
- rebuilt with mariadb-10.0.9.

* Tue Feb 11 2014 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 4.00-1
- new upstream release.

* Wed Dec 18 2013 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 3.10-2
- added "BR: groonga-normalizer-mysql-devel".

* Wed Dec 04 2013 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 3.10-1
- new upstream release.
- built with MariaDB.

* Wed Feb 20 2013 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 3.00-1
- new upstream release.
- fixed dates of old %%changelog.

* Fri Nov 16 2012 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 2.08-1
- new upstream release.

* Sat Sep 15 2012 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 2.06-1
- initial build for Vine Linux.

* Wed Aug 29 2012 Kouhei Sutou <kou@clear-code.com> - 2.06-0
- new upstream release.
- make MySQL spec file name customizable.
- make mroonga configure options customizable.
- add missing mysql-devel BuildRequires. Reported by wing. Thanks!!!
- use MySQL 5.5.27.

* Sun Jul 29 2012 HAYASHI Kentaro <hayashi@clear-code.com> - 2.05-0
- new upstream release.
- use MySQL 5.5.25a.

* Fri Jun 29 2012 Kouhei Sutou <kou@clear-code.com> - 2.04-0
- new upstream release.
- ensure deleting mroonga plugin before install.
  Suggested by Kazuhiro Isobe. Thanks!!!
- use MySQL 5.5.25.

* Tue May 29 2012 Kouhei Sutou <kou@clear-code.com> - 2.03-0
- new upstream release.
- use MySQL 5.5.24.
- make mysql_* variables customizable
- require groonga 2.0.3 or later.

* Sun Apr 29 2012 Kouhei Sutou <kou@clear-code.com> - 2.02-0
- new upstream release.
- use MySQL 5.5.23.
- require groonga 2.0.2 or later.

* Thu Mar 29 2012 Kouhei Sutou <kou@clear-code.com> - 2.01-0
- new upstream release.
- ensure plugin is uninstalled by closing all tables use mroonga.

* Wed Feb 29 2012 Kouhei Sutou <kou@clear-code.com> - 2.00-0
- new upstream release.
- always install/uninstall plugin.
- use MySQL 5.1.61 and 5.5.21.
- require groonga 2.0.0 or later.

* Sun Jan 29 2012 Kouhei Sutou <kou@clear-code.com> - 1.20-0
- new upstream release.
- require groonga 1.3.0.
- groonga -> mroonga.
- use MySQL 5.5.20.

* Thu Dec 29 2011 Kouhei Sutou <kou@clear-code.com> - 1.11-0
- new upstream release.

* Sat Oct 29 2011 Kouhei Sutou <kou@clear-code.com> - 1.10-0
- new upstream release.
- groonga storage engine -> mroonga.

* Thu Sep 29 2011 Kouhei Sutou <kou@clear-code.com> - 1.0.0-0
- new upstream release.

* Mon Aug 29 2011 Kouhei Sutou <kou@clear-code.com> - 0.9-0
- new upstream release.

* Fri Jul 29 2011 Kouhei Sutou <kou@clear-code.com> - 0.8-0
- new upstream release.

* Wed Jun 29 2011 Kouhei Sutou <kou@clear-code.com> - 0.7-0
- new upstream release.

* Sun May 29 2011 Kouhei Sutou <kou@clear-code.com> - 0.6-0
- new upstream release.

* Tue May 17 2011 Kouhei Sutou <kou@clear-code.com> - 0.5-2
- use MySQL 5.5.12.

* Tue Mar 29 2011 Kouhei Sutou <kou@clear-code.com> - 0.5-1
- new upstream release.

* Sat Jan 29 2011 Kouhei Sutou <kou@clear-code.com> - 0.4-4
- do not remove plugin on upgrade.

* Wed Jan 12 2011 Kouhei Sutou <kou@clear-code.com> - 0.4-3
- rebuild without debug symbol.

* Thu Dec 30 2010 Kouhei Sutou <kou@clear-code.com> - 0.4-2
- use MySQL 5.5.8-1.
- fix SQL literal notation.

* Mon Nov 29 2010 Kouhei Sutou <kou@clear-code.com> - 0.4-1
- use the latest MySQL.
- new upstream release.

* Sun Nov 21 2010 Kouhei Sutou <kou@clear-code.com> - 0.3-2
- install user define function.

* Fri Oct 29 2010 Kouhei Sutou <kou@clear-code.com> - 0.3-1
- new upstream release.

* Fri Oct 08 2010 Kouhei Sutou <kou@clear-code.com> - 0.2-2
- specify target MySQL version.
- use %{version}.

* Wed Sep 29 2010 Kouhei Sutou <kou@clear-code.com> - 0.2-1
- new upstream release.

* Sun Sep 12 2010 Kouhei Sutou <kou@clear-code.com> - 0.1-3
- require MySQL-client-community.

* Fri Sep 10 2010 Kouhei Sutou <kou@clear-code.com> - 0.1-2
- use MySQL-devel-community.

* Fri Sep 03 2010 Kouhei Sutou <kou@clear-code.com> - 0.1-1
- initial packaging for CentOS.
