%{!?python_sitearch:%global python_sitearch %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib(1)")}
%global pyqt4_version 4.9

%define ver 2.29

%define _qt4_version 4.8.0
%define _qt4_prefix %(pkg-config --variable prefix --silence-errors Qt 2>/dev/null || echo %{_libdir}/qt4)
%define _qt4_libdir %(pkg-config --variable libdir --silence-errors Qt 2>/dev/null || echo %{_libdir})
%define _qt4_headerdir %(pkg-config --variable headerdir --silence-errors Qt 2>/dev/null || echo %{_includedir})
%define _qt4_translationdir %(pkg-config --variable translationdir --silence-errors Qt 2>/dev/null || echo %{_datadir}/qt4/translations)

Summary:	A Scintilla port to Qt
Name:		qscintilla
Version:	2.6
Release:	1%{?_dist_release}

# matches up (pretty much) with qt4
License:	GPLv3 or GPLv2 with exceptions
Group:		Development/Tools
URL:		http://www.riverbankcomputing.co.uk/qscintilla

Source:		QScintilla-gpl-%{version}.tar.gz
# TODO: upstream this
Patch1:         QScintilla-2-gpl-Qt4-incpath.patch

BuildRoot:	%{_tmppath}/%{name}-%{version}-root
BuildRequires:	qt4-devel
BuildRequires:  PyQt4-devel >= %{pyqt4_version} 
Requires:	qt4 >= %{_qt4_version}

%description
QScintilla is a port of Scintilla to the Qt GUI toolkit.

This version of QScintilla is based on Scintilla v%{ver}.

%package designer
Summary:  QScintilla designer plugin 
Group:    Development/Tools
Requires: %{name} = %{version}-%{release}
Requires: qt4-designer

%description designer
%{summary}.

%package devel
Summary: QScintilla Development Files
Group: Development/Libraries
Requires: %{name} = %{version}-%{release}
Requires: qt4-devel >= %{_qt4_version}

%description  devel
This packages contains the libraries, include and other files
you can use to develop applications with QScintilla.

%package python
Summary:  QScintilla PyQt4 bindings
Group:    Development/Libraries
Requires: %{name} = %{version}-%{release}
Requires: PyQt4 >= %{pyqt4_version}

%description python
%{summary}.

%package python-devel
Summary:  Development files for QScintilla PyQt4 bindings 
Group:    Development/Libraries
Requires: %{name}-python = %{version}-%{release}
Requires: PyQt4-devel >= %{pyqt4_version}

%description python-devel
%{summary}.

%prep 
%setup -q -n QScintilla-gpl-%{version}
%patch1 -p1 -b .designer-incpath-qt4

# fix permissions on doc files
find doc example-Qt4  -type f -exec chmod 0644 {} ';'
find src include -type f -exec chmod 0644 {} ';'

# fix line endings in license file(s)
sed -i 's/\r//' LICENSE.GPL2 GPL_EXCEPTION_ADDENDUM.TXT

%build
export QTDIR=%{_qt4_prefix}
%ifarch x86_64
export QMAKESPEC=$QTDIR/mkspecs/linux-g++-64/
%else
export QMAKESPEC=$QTDIR/mkspecs/linux-g++/
%endif

pushd Qt4
$QTDIR/bin/qmake -o Makefile qscintilla.pro
make %{?_smp_mflags}
popd

pushd designer-Qt4
$QTDIR/bin/qmake -o Makefile designer.pro
make %{?_smp_mflags}
popd

pushd Python
%{__python} configure.py \
            -c -j 3 \
            -n ../Qt4 \
            -o ../Qt4
make %{?_smp_mflags}
popd

%install
rm -rf $RPM_BUILD_ROOT

make install INSTALL_ROOT=$RPM_BUILD_ROOT -C Qt4
make install INSTALL_ROOT=$RPM_BUILD_ROOT -C designer-Qt4
make install DESTDIR=$RPM_BUILD_ROOT -C Python


%clean
rm -rf $RPM_BUILD_ROOT

%post  -p /sbin/ldconfig

%postun -p /sbin/ldconfig

%files 
%defattr(-, root, root, 755)
%doc NEWS README
%doc LICENSE.GPL3 LICENSE.GPL2 GPL_EXCEPTION.TXT GPL_EXCEPTION_ADDENDUM.TXT
%{_qt4_libdir}/libqscintilla2.so.*
%{_qt4_prefix}/qsci/*
%{_qt4_translationdir}/*

%files designer
%defattr(-,root,root,-)
%{_qt4_prefix}/plugins/designer/libqscintillaplugin.so

%files devel
%defattr(-, root, root, -)
%{_qt4_headerdir}/*
%{_qt4_libdir}/libqscintilla2.so

%files python
%defattr(-,root,root,-)
%{python_sitearch}/PyQt4/Qsci.so

%files python-devel
%defattr(-,root,root,-)
%{_datadir}/sip/PyQt4/Qsci

%changelog
* Sat Jan  7 2012 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 2.6-1
- new upstream release
- built with qt-4.8.0, PyQt4-4.9

* Sun Mar 13 2011 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 2.4.6-2
- rebuilt with qt-4.7.2

* Sun Feb 20 2011 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 2.4.6-1
- new upstream release
- fix qt4_ver from 4.6.3 to 4.7.1

* Wed Aug 25 2010 Yoji TOYODA <bsyamato@sea.plala.or.jp> 2.4.4-2
- rebuild with qt4-4.6.3
- fix qt4_ver from 4.6.1 to 4.6.3
- fix BuildRequires: qt4-devel = %{qt4_ver} (add version)

* Sun Jul 25 2010 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 2.4.4-1
- new upstream release
- updated qt4 macros

* Sat Feb 06 2010 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 2.4.2-1
- new upstream release

* Fri Feb 05 2010 Shu KONNO <owa@bg.wakwak.com> 2.4-3
- rebuilt with qt4-4.6.1, python-2.6
- installed translation to %%{_datadir}/qt4/translations now

* Thu Oct 22 2009 Shu KONNO <owa@bg.wakwak.com> 2.4-2
- updated macro pyqt4_version to 4.6
- fixed changelog year below (2008 -> 2009)

* Sat Aug 29 2009 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 2.4-1
- new upstream release
- added designer, python and python-devel sub-packages

* Sun Aug 17 2008 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 1.7.1-1
- appiled new versioning policy

* Fri Nov 30 2007 Shu KONNO <owa@bg.wakwak.com> 1.7.1-0vl2
- updated macro QMAKESPEC to linux-g++-64 (if x86_64)

* Thu Sep 13 2007 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 1.7.1-0vl1
- new upstream release (1.71)

* Mon Jun  4 2006 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 1.6-0vl1
- new upstream release (1.65)
- changed Group to System Environment/Libraries

* Sat Jan 15 2005 Satoshi MACHINO <machino@vinelinux.org> 1.4-0vl1
- initial built for VineLinux