%{!?tcl_version: %define tcl_version %( tclsh <<< 'puts "${tcl_version}"; exit 0;' )}

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

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

Name:		    sk1libs
Version:	    0.9.1
Release:	    1%{?dist}
Group:		    Applications/Multimedia
License:	    GPLv2+ and LGPLv2+
URL:		    http://sk1project.org/
Summary:	    Set of Python Non-GUI Extensions for sK1 Project

Source0:	    https://sk1project.net/dc.php?target=%{name}-%{version}.tar.gz#/%{name}-%{version}.tar.gz
# Fix / kludge for Tcl 8.6 (good old interp->result) - AdamW 2008/12
Patch0:         sk1libs-math-fix.diff
Patch1:         sk1libs-0.9.1-freetype-2.1.patch

BuildRequires:  gcc
BuildRequires:  tcl
BuildRequires:  pkgconfig(freetype2)
BuildRequires:  pkgconfig(zlib)
BuildRequires:  libjpeg-turbo-devel
BuildRequires:  lcms-devel
Requires:       lcms
%if 0%{?rhel} && 0%{?rhel} <= 7
BuildRequires:  python-devel
Requires:       python-imaging
%else
BuildRequires:  python2-devel
Requires:       python2-imaging
%endif


%description
sk1libs is a set of python non-GUI extensions for sK1 Project. The package
includes multiplatform non-GUI extensions which are usually native extensions.


%prep
%setup -q
%patch0 -p1 -b .mfix
%patch1 -p1 -b .freetype

sed -i -e 's,tcl8.5,tcl%{tcl_version},g' "setup.py"
sed -i -e 's,tk8.5,tk%{tcl_version},g' "setup.py"

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


%build
CFLAGS="%{optflags}" %{__python2} setup.py "build"


%install
%{__python2} setup.py install --root "%{buildroot}" --compile --optimize=2

%{__chmod} a+x "%{buildroot}%{python2_sitearch}/sk1libs/libpdf/lib"/{randomtext,units,fonts,corp,formatters,pagesizes,normalDate,logger,set_ops,__init__}.py


%files
%doc README
%license COPYRIGHTS GNU_LGPL_v2
%{python2_sitearch}/*


%changelog
* Sun Apr 21 2019 Tomasz Tomasik <scx.mail@gmail.com> - 0.9.1-1
- Initial package