%define ver 0.3.5
%define rel 3
%define dataver 0.2.7
%define datarel 7

%define from_git 0
%if %{from_git}
%define githash ccfd5c6d
%endif

%if "%{?_dist_release}" == "vl6"
%define with_vala 0
%else
%define with_vala 1
%endif

Summary: Japanese Kana Kanji conversion library (libkkc)
Name: libkkc
Version: %{ver}
%if %{from_git}
Release: %{rel}.git%{githash}%{_dist_release}
%else
Release: %{rel}%{_dist_release}
%endif
License: GPLv3+
Group: System Environment/Libraries
URL: https://bitbucket.org/libkkc/libkkc/
%if %{from_git}
Source0: libkkc-%{githash}.tar.gz
%else
Source0: https://github.com/ueno/libkkc/releases/download/v%{version}/%{name}-%{version}.tar.gz
%endif
Source1: https://bitbucket.org/libkkc/libkkc-data/downloads/%{name}-data-%{dataver}.tar.xz
Patch0: https://github.com/ueno/libkkc/commit/1f512da81a71287b13eb0a1f9b31830b16db2107.patch
Patch1: https://github.com/ueno/libkkc/commit/46b02adf1fe806e99f8d896f770591480165f90a.patch
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot
BuildRequires: pkgconfig(gee-0.8)
BuildRequires: libgee-vala
BuildRequires: json-glib-devel
BuildRequires: marisa-trie-devel
# for libkkc-data
BuildRequires: marisa-trie-python
%if %{with_vala}
BuildRequires: vala-devel
BuildRequires: vala-tools
%endif

Requires: libkkc-data = %{dataver}-%{datarel}%{_dist_release}
Requires: libkkc-common = %{version}-%{release}

Vendor: Project Vine
Distribution: Vine Linux
Packager: iwaim

%description
libkkc provides a converter from Kana-string to
Kana-Kanji-mixed-string.  It was named after kkc.el in GNU Emacs, a
simple Kana Kanji converter, while libkkc tries to convert sentences
in a bit more complex way using N-gram language models.

%package devel
Summary: Header files and libraries for developing apps which will use libkkc
Group: Development/Libraries
Requires: %{name} = %{version}-%{release}

%description devel
The libkkc-devel package contains the header files and libraries.

%package tools
Summary: Tools for %{name}
Group: Applications/Accessories
Requires: %{name} = %{version}-%{release}

%description tools
The %{name}-tools package contains tools for developing applications
that use %{name}.

%package common
Summary: Common data files for %{name}

%description common
The %{name}-common package contains the arch-independent data that
%{name} uses at run time.

%package data
Summary: Data files for %{name}
Version: %{dataver}
Release: %{datarel}%{_dist_release}

%description data
The %{name}-data package contains the language model data that %{name}
uses at run time.

%prep
%if %{from_git}
%setup -q -n %{name}-%{githash}
%else
%setup -q
%endif
%patch0 -p1

# for libkkc-data
tar xf %{SOURCE1}

%build
%if %{from_git}
./autogen.sh
%endif
%configure --enable-shared --disable-static \
           --disable-silent-rules \
%if %{with_vala}
           --enable-vala=yes \
%else
           --enable-vala=no \
%endif

%__make

# for libkkc-data
pushd %{name}-data-%{dataver}
%configure
%__make
popd

%install
%__rm -rf $RPM_BUILD_ROOT
%makeinstall

# for libkkc-data
pushd %{name}-data-%{dataver}
%makeinstall
popd

%find_lang %{name}

# remove files
%__rm -f $RPM_BUILD_ROOT%{_libdir}/libkkc.la

%clean
%__rm -rf $RPM_BUILD_ROOT

%post -p /sbin/ldconfig

%postun -p /sbin/ldconfig

%files -f %{name}.lang
%defattr(-,root,root,-)
%doc README ChangeLog COPYING AUTHORS NEWS
%doc data/rules/README.rules
%{_libdir}/libkkc.so.*
%{_libdir}/girepository-1.0/Kkc-1.0.typelib
%dir %{_datadir}/libkkc
%{_datadir}/libkkc/rules

%files devel
%defattr(-,root,root,-)
%doc COPYING AUTHORS
%dir %{_includedir}/libkkc
%{_includedir}/libkkc/libkkc.h
%{_libdir}/libkkc.so
%{_libdir}/pkgconfig/kkc-1.0.pc
%{_datadir}/gir-1.0/Kkc-1.0.gir
%{_datadir}/vala/vapi/kkc-1.0.deps
%{_datadir}/vala/vapi/kkc-1.0.vapi

%files tools
%defattr(-,root,root,-)
%doc COPYING AUTHORS
%{_bindir}/kkc
%{_bindir}/kkc-package-data

%files common
%defattr(-,root,root,-)
%doc COPYING AUTHORS
%dir %{_datadir}/libkkc
%dir %{_datadir}/libkkc/templates
%{_datadir}/libkkc/templates/libkkc-data

%files data
%defattr(-,root,root,-)
%doc COPYING AUTHORS
%dir %{_libdir}/libkkc
%dir %{_libdir}/libkkc/models
%{_libdir}/libkkc/models/sorted3

%changelog
* Fri Apr 29 2016 WAI, Masaharu <iwaim.sub@gmail.com> 0.3.5-3
- add 'Modify Kana rules for ignoring moored shift key.' patch (Patch1)

* Thu Apr 30 2015 IWAI, Masaharu <iwaim.sub@gmail.com> 0.3.5-2
- add 'Try all possible okuri-gana combinations' patch (Patch0)
- add BuildRequires: libgee-vala

* Mon Dec 29 2014 IWAI, Masaharu <iwaim.sub@gmail.com> 0.3.5-1
- update to libkkc 0.3.5
- switch upstream source location to GitHub

* Mon Jul  7 2014 IWAI, Masaharu <iwaim.sub@gmail.com> 0.3.4-1
- update to libkkc 0.3.4
- update BuildRequires for libgee

* Sun Jun 15 2014 IWAI, Masaharu <iwaim.sub@gmail.com> 0.3.3-1
- update to libkkc 0.3.3

* Wed Dec 18 2013 IWAI, Masaharu <iwaim.sub@gmail.com> 0.3.2-1
- update to libkkc 0.3.2

* Thu Nov  7 2013 IWAI, Masaharu <iwaim.sub@gmail.com> 0.3.1-1
- update to libkkc 0.3.1
- update to libkkc-data 0.2.7
- fix changelog for 0.2.6-1

* Sat Jul 27 2013 IWAI, Masaharu <iwaim.sub@gmail.com> 0.2.6-1
- update to libkkc 0.2.6
- update to libkkc-data 0.2.5

* Tue Jun 18 2013 IWAI, Masaharu <iwaim.sub@gmail.com> 0.2.4-1
- update to libkkc 0.2.4
- update to libkkc-data 0.2.0
- add Version tag for libkkc-data sub package

* Tue Mar 26 2013 IWAI, Masaharu <iwai@alib.jp> 0.1.10-1
- update to libkkc 0.1.10

* Sat Mar 16 2013 IWAI, Masaharu <iwai@alib.jp> 0.1.9-1
- update to libkkc 0.1.9

* Sun Mar  3 2013 IWAI, Masaharu <iwai@alib.jp> 0.1.8-1
- update to libkkc 0.1.8

* Sat Feb 23 2013 IWAI, Masaharu <iwai@alib.jp> 0.1.7-1
- update to libkkc 0.1.7

* Fri Feb 15 2013 IWAI, Masaharu <iwai@alib.jp> 0.1.6-1
- update to libkkc 0.1.6
- update to libkkc-data 0.1.6

* Mon Feb 11 2013 IWAI, Masaharu <iwai@alib.jp> 0.1.5-1
- update to libkkc 0.1.5

* Fri Feb  8 2013 IWAI, Masaharu <iwai@alib.jp> 0.1.3-1
- update to 0.1.3
- update License value: GPLv3 -> GPLv3+
- add BuildRequires: marisa-trie-python for libkkc-data
- sync upstream spec: http://ueno.fedorapeople.org/libkkc/libkkc.spec 0.1.3-2
 - create tools sub package
  - move %%{_bindir}/kkc
  - add %%{_bindir}/kkc-package-data
 - create common sub package
  - add template for generating libkkc-data
 - merge libkkc-data SRPM file
  - add libkkc-data source file (Source1)
  - create data sub package
 - add '--disable-silent-rules' option for configure
 - add Requires libkkc-data and libkkc-common
 - add document: data/rules/README.rules

* Wed Feb  6 2013 IWAI, Masaharu <iwai@alib.jp> 0.1.2-1
- update to 0.1.2

* Tue Feb  5 2013 IWAI, Masaharu <iwai@alib.jp> 0.1.1-1
- update to 0.1.1

* Fri Feb  1 2013 IWAI, Masaharu <iwai@alib.jp> 0.1.0-1
- update to 0.1.0
- rename libkkc.pc to kkc-1.0.pc by upstream

* Fri Feb  1 2013 IWAI, Masaharu <iwai@alib.jp> 0.0.3-3.gitccfd5c6d
- update to git ccfd5c6d9f913e0a413fe5d0c45bb70032382f68
- add post and postun script
- add translate file

* Tue Jan 29 2013 IWAI, Masaharu <iwai@alib.jp> 0.0.3-2
- support Vine Linux 6
 - without Vala
 - BR: libgee-devel

* Mon Jan 28 2013 IWAI, Masaharu <iwai@alib.jp> 0.0.3-1
- initial build for Vine Linux

