%global version_major 2
%global version_minor 0
%undefine version_patch
%global version_postfix rc4
%global version_date 20190416

%global srcname uniconvertor

%define version_full %{version_major}%{?version_minor:.%{version_minor}}%{?version_patch:.%{version_patch}}%{?version_postfix:~%{version_postfix}}
%define version_base %{version_major}%{?version_minor:.%{version_minor}}%{?version_patch:.%{version_patch}}%{?version_postfix:%{version_postfix}}
%define version_package %{?version_major:%{version_major}}
%define version_priority %{?version_major:%{version_major}}%{!?version_major:0}%{?version_minor:%{version_minor}}%{!?version_minor:0}%{?version_patch:%{version_patch}}%{!?version_patch:0}
%define version_src %{version_base}_%{version_date}

%{!?python2_sitearch: %define python2_sitearch %(%{__python2} -c "from distutils.sysconfig import get_python_lib; print get_python_lib(1)")}

%{!?_licensedir:%global license %doc}

Name:           %{srcname}%{version_package}
# First Epoch:
# http://uniconvertor.googlecode.com/svn/trunk/
# https://sourceforge.net/p/uniconvertor/code/HEAD/tree/UniConvertor/trunk/uniconvertor-2.x/
Epoch:          1
Version:        %{version_full}
Release:        %{version_date}.3%{?dist}
Group:          Applications/Multimedia
License:        LGPLv2+ and GPLv2+ and MIT
URL:            https://sk1project.net/modules.php?name=Products&product=uniconvertor
Summary:        Universal vector graphics translator

Source0:        https://downloads.sk1project.net/%{srcname}/nightbuilds/%{srcname}-%{version_src}.tar.gz

BuildRequires:  gcc
%if 0%{?rhel} && 0%{?rhel} <= 7
BuildRequires:  python-devel
BuildRequires:  pycairo-devel
%if 0%{?rhel} >= 7
BuildRequires:  python-pillow-devel
%endif
BuildRequires:  lcms2-devel
%else
BuildRequires:  python2-devel
BuildRequires:  python2-cairo-devel
BuildRequires:  python2-pillow-devel
BuildRequires:  lcms2-devel
%endif
BuildRequires:  pkgconfig(pango)
BuildRequires:  potrace-devel
BuildRequires:  ImageMagick-devel ImageMagick-c++-devel
%if 0%{?rhel} && 0%{?rhel} <= 7
Requires:       python-imaging
Requires:       python-reportlab
%if 0%{?rhel} >= 7
Requires:       python-pillow
%endif
Requires:       pycairo
%else
Requires:       python2-imaging
Requires:       python2-reportlab
Requires:       python2-pillow
Requires:       python2-cairo
%endif
Requires:       pango
Requires:       ImageMagick ImageMagick-c++
Requires:       urw-base35-nimbus-mono-ps-fonts
Requires:       urw-base35-nimbus-roman-fonts
Requires:       urw-base35-nimbus-sans-fonts

Provides:       %{srcname} = %{?epoch:%{epoch}:}%{version}-%{release}

Requires(post):         %{_sbindir}/update-alternatives
Requires(postun):       %{_sbindir}/update-alternatives


%description
UniConvertor is a universal vector graphics translator.
It uses sK1 engine to convert one format to another.


%prep
%autosetup -n "%{srcname}-%{version_base}"

find * -xtype f -name '*.py' | xargs -I{} sed -i -re 's;^#! *(/usr)?/bin/(env +)?python *$;#!/usr/bin/env python2;' '{}'


%build
CFLAGS="%{optflags} -I/usr/include/python2.7/Imaging" %{__python2} "setup-uc2.py" "build"


%install
%{__python2} "setup-uc2.py" install --skip-build --root "%{buildroot}"

%{__rm} "%{buildroot}%{_exec_prefix}/lib/%{srcname}-%{version_base}/LICENSE"

%{__mv} "%{buildroot}%{_bindir}/%{srcname}" "%{buildroot}%{_bindir}/%{name}"

touch "%{buildroot}%{_bindir}/%{srcname}"


%post
if [[ -e "%{_bindir}/%{srcname}" && ! -h "%{_bindir}/%{srcname}" ]]; then
  %{__rm} -rf "%{_bindir}/%{srcname}"
fi
"%{_sbindir}/update-alternatives" --install "%{_bindir}/%{srcname}" "%{srcname}" "%{_bindir}/%{name}" "%{version_priority}"


%postun
if [[ "${1}" -eq "0" ]]; then
  "%{_sbindir}/update-alternatives" --remove "%{srcname}" "%{_bindir}/%{name}"
fi


%files
%doc README.txt
%license LICENSE
%ghost %{_bindir}/%{srcname}
%{_bindir}/%{name}
%{_exec_prefix}/lib/%{srcname}-%{version_base}/uc2
%{_exec_prefix}/lib/%{srcname}-%{version_base}/%{srcname}-%{version_base}-py2.?.egg-info


%changelog
* Tue Apr 30 2019 Tomasz Tomasik <scx.mail@gmail.com> - 2.0~rc4-20190416.3
- Fix changelog

* Tue Apr 30 2019 Tomasz Tomasik <scx.mail@gmail.com> - 2.0~rc4-20190416.2
- Improve scripts

* Sun Apr 21 2019 Tomasz Tomasik <scx.mail@gmail.com> - 2.0~rc4-20190416.1
- Update to 2.0-0~rc4-20190416
- Rebuild for EL7
- Rename package

* Sun Feb 03 2019 Fedora Release Engineering <releng@fedoraproject.org> - 2.0-0.18.svn362
- Rebuilt for https://fedoraproject.org/wiki/Fedora_30_Mass_Rebuild

* Sat Jul 14 2018 Fedora Release Engineering <releng@fedoraproject.org> - 2.0-0.17.svn362
- Rebuilt for https://fedoraproject.org/wiki/Fedora_29_Mass_Rebuild

* Fri Feb 09 2018 Iryna Shcherbina <ishcherb@redhat.com> - 2.0-0.16.svn362
- Update Python 2 dependency declarations to new packaging standards
  (See https://fedoraproject.org/wiki/FinalizingFedoraSwitchtoPython3)

* Fri Feb 09 2018 Fedora Release Engineering <releng@fedoraproject.org> - 2.0-0.15.svn362
- Rebuilt for https://fedoraproject.org/wiki/Fedora_28_Mass_Rebuild

* Thu Aug 03 2017 Fedora Release Engineering <releng@fedoraproject.org> - 2.0-0.14.svn362
- Rebuilt for https://fedoraproject.org/wiki/Fedora_27_Binutils_Mass_Rebuild

* Thu Jul 27 2017 Fedora Release Engineering <releng@fedoraproject.org> - 2.0-0.13.svn362
- Rebuilt for https://fedoraproject.org/wiki/Fedora_27_Mass_Rebuild

* Wed May 10 2017 Ville Skyttä <ville.skytta@iki.fi> - 2.0-0.12.svn362
- Fix URL

* Sat Feb 11 2017 Fedora Release Engineering <releng@fedoraproject.org> - 2.0-0.11.svn362
- Rebuilt for https://fedoraproject.org/wiki/Fedora_26_Mass_Rebuild

* Tue Jul 19 2016 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 2.0-0.10.svn362
- https://fedoraproject.org/wiki/Changes/Automatic_Provides_for_Python_RPM_Packages

* Fri Feb 05 2016 Fedora Release Engineering <releng@fedoraproject.org> - 2.0-0.9.svn362
- Rebuilt for https://fedoraproject.org/wiki/Fedora_24_Mass_Rebuild

* Fri Jun 19 2015 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 2.0-0.8.svn362
- Rebuilt for https://fedoraproject.org/wiki/Fedora_23_Mass_Rebuild

* Sat Sep 27 2014 Rex Dieter <rdieter@fedoraproject.org> 2.0-0.7.svn362
- add (optimized) mime scriptlet

* Mon Aug 18 2014 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 2.0-0.6.svn362
- Rebuilt for https://fedoraproject.org/wiki/Fedora_21_22_Mass_Rebuild

* Sun Jun 08 2014 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 2.0-0.5.svn362
- Rebuilt for https://fedoraproject.org/wiki/Fedora_21_Mass_Rebuild

* Fri Mar 21 2014 Pavel Alexeev <Pahan@Hubbitus.info> - 2.0-0.4.svn362
- Add pycairo require (bz#1079342).

* Sat Oct 19 2013 Pavel Alexeev <Pahan@Hubbitus.info> - 2.0-0.3.svn362
- New build to fix bz#1013652
- Add BR potrace-devel

* Tue Sep  3 2013 Tom Callaway <spot@fedoraproject.org> - 2.0-0.2.svn344
- fix tarball generation script to remove non-free sRGB.icm
- update to cleaned svn344 tarball
- use Public Domain sRGB.icm from argyllcms

* Sat Aug 24 2013 Pavel Alexeev <Pahan@Hubbitus.info> - 2.0-0.1.svn340
- First attempt packaging 2.0 version. Igor Novikov said in mail it is almost ready.
- New build with hope to fix compatability with python-pillow instead of PIL (by author mail)
- Add BR lcms2-devel
- Add script to get tarball from svn.
- Replace $RPM_BUILD_ROOT by %%{buildroot}
- Add BR pycairo-devel, python-pillow-devel
- Add require python-pillow
- Drop 1.x branch patches.
- Spec cleanup.

* Sun Aug 04 2013 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 1.1.4-8
- Rebuilt for https://fedoraproject.org/wiki/Fedora_20_Mass_Rebuild

* Fri Feb 15 2013 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 1.1.4-7
- Rebuilt for https://fedoraproject.org/wiki/Fedora_19_Mass_Rebuild

* Sun Jul 22 2012 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 1.1.4-6
- Rebuilt for https://fedoraproject.org/wiki/Fedora_18_Mass_Rebuild

* Sat Jan 14 2012 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 1.1.4-5
- Rebuilt for https://fedoraproject.org/wiki/Fedora_17_Mass_Rebuild

* Mon Feb 07 2011 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 1.1.4-4
- Rebuilt for https://fedoraproject.org/wiki/Fedora_15_Mass_Rebuild

* Thu Jul 22 2010 David Malcolm <dmalcolm@redhat.com> - 1.1.4-3
- Rebuilt for https://fedoraproject.org/wiki/Features/Python_2.7/MassRebuild

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

* Sun Jun 21 2009 Andy Shevchenko <andy@smile.org.ua> - 1.1.4-1
- update to 1.1.4
- remove upstreamed patches
- adjust Fedora related patches

* Sat May 02 2009 Andy Shevchenko <andy@smile.org.ua> - 1.1.3-6
- Fix WMF saver

* Wed Feb 25 2009 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 1.1.3-5
- Rebuilt for https://fedoraproject.org/wiki/Fedora_11_Mass_Rebuild

* Wed Feb 11 2009 Andy Shevchenko <andy@smile.org.ua> - 1.1.3-4
- cover code in __init__.py by function (#484301)

* Sat Nov 29 2008 Ignacio Vazquez-Abrams <ivazqueznet+rpm@gmail.com> - 1.1.3-3
- Rebuild for Python 2.6

* Sun Jul 27 2008 Andy Shevchenko <andy@smile.org.ua> 1.1.3-2
- update to 1.1.3
- new requirement python-reportlab

* Sun May 04 2008 Andy Shevchenko <andy@smile.org.ua> 1.1.2-2
- update to 1.1.2
- apply two useful patches from Debian

* Thu Mar 06 2008 Andy Shevchenko <andy@smile.org.ua> 1.1.1-2
- just fix Source0 URL

* Wed Feb 13 2008 Andy Shevchenko <andy@smile.org.ua> 1.1.1-1
- update to 1.1.1

* Sat Jan 12 2008 Andy Shevchenko <andy@smile.org.ua> 1.1.0-1
- update to 1.1.0

* Thu Nov 29 2007 Andy Shevchenko <andy@smile.org.ua> 1.0.0-5
- fix conflict with netatalk: rename uniconv to uniconvertor (#405011)

* Thu Nov 22 2007 Andy Shevchenko <andy@smile.org.ua> 1.0.0-4
- use python_sitearch and CFLAGS

* Thu Nov 22 2007 Andy Shevchenko <andy@smile.org.ua> 1.0.0-3
- prepare to include to Fedora
  (https://bugzilla.redhat.com/show_bug.cgi?id=393971)

* Tue Nov 20 2007 Andy Shevchenko <andy@smile.org.ua> 1.0.0-2
- adjust License: tag (thanks Tom 'spot' Callaway)

* Thu Nov 15 2007 Andy Shevchenko <andy@smile.org.ua> 1.0.0-1
- initial build