%{!?python_inc:%global python_inc %(%{__python} -c "from distutils.sysconfig import get_python_inc; print get_python_inc(1)")}
%define py_ver %(python -c 'import sys;print(sys.version[0:3])')

%{!?python3_inc:%global python3_inc %(%{__python3} -c "from distutils.sysconfig import get_python_inc; print(get_python_inc(1))")}

%global rpm_macros_dir %(d=%{_rpmconfigdir}/macros.d; [ -d $d ] || d=%{_sysconfdir}/rpm; echo $d)

# trim changelog included in binary rpms
%global _changelog_trimtime %(date +%s -d "1 year ago")

Name:           sip
Summary:        Python/C++ Bindings Generator
Summary(ja):    Python/C++ インターフェイス生成ツール
Version:        4.19.25
Release:        2%{?_dist_release}
Group:          programming
Vendor:         Project Vine
Distribution:   Vine Linux

# sipgen/parser.{c.h} is GPLv3+ with exceptions (bison)
License:        GPLv2 or GPLv3 and (GPLv3+ with exceptions)
URL:            https://www.riverbankcomputing.co.uk/software/sip/intro
Source0:        https://www.riverbankcomputing.com/static/Downloads/sip/%{version}/sip-%{version}%{?snap:.%{snap}}.tar.gz

# extracted from sip.h, SIP_API_MAJOR_NR SIP_API_MINOR_NR defines
Source1: macros.sip
%global _sip_api_major 12
%global _sip_api_minor 7
%global _sip_api %{_sip_api_major}.%{_sip_api_minor}

Source10: sip-wrapper.sh

## upstreamable patches
# make install should not strip (by default), kills -debuginfo
Patch50: sip-4.18-no_strip.patch
# try not to rpath the world
Patch51: sip-4.18-no_rpath.patch
# set sip_bin properly for python3 build (needswork to be upstreamable)
# no longer needed?  keep for a little while before dropping completely -- rex
#Patch52: sip-4.19.3-python3_sip_bin.patch
# Avoid hardcoding sip.so (needed for wxpython's siplib.so)
Patch53: sip-4.19.18-no_hardcode_sip_so.patch
# Recognize the py_ssize_t_clean directive to avoid FTBFS with PyQt 5.15.6
Patch54: sip-4.19.25-py_ssize_t_clean.patch
# Fix error: invalid use of undefined type 'struct _frame' 
Patch55: sip-4.19.25-pyframe_getback.patch

BuildRoot:	%{_tmppath}/%{name}-%{version}-root

Provides: sip-api(%{_sip_api_major}) = %{_sip_api}
Provides: sip-api(%{_sip_api_major})%{?_isa} = %{_sip_api}

BuildRequires:	python-rpm-macros
BuildRequires:	python3-devel
BuildRequires:	python3-rpm-macros
BuildRequires:	python-devel
BuildRequires:	python2-rpm-macros
BuildRequires:	sed

%description
SIP is a tool for generating bindings for C++ classes so that they can be
accessed as normal Python classes. SIP takes many of its ideas from SWIG but,
because it is specifically designed for C++ and Python, is able to generate
tighter bindings. SIP is so called because it is a small SWIG.

SIP was originally designed to generate Python bindings for KDE and so has
explicit support for the signal slot mechanism used by the Qt/KDE class
libraries. However, SIP can be used to generate Python bindings for any C++
class library.


%package devel
Summary: 	Files needed to generate Python bindings for any C++ class library
Summary(ja): 	Python/C++ インタフェース作成に必要なライブラリやヘッダファイル
Group: 		programming
Requires: 	%{name} = %{version}-%{release}
Requires:	%{name}-macros = %{version}-%{release}
Requires: 	python-devel
Provides: 	libsip-devel = %{version}-%{release}

%description devel
This package contains files needed to generate Python bindings for any C++
classes library.


%package pyqt5-sip
Summary: %summary
Group: 		programming
Provides: python-pyqt5-sip-api(%{_sip_api_major}) = %{_sip_api}
Provides: python-pyqt5-sip-api(%{_sip_api_major})%{?_isa} = %{_sip_api}
%{?python_provide:%python_provide python-pyqt5-sip}
%description pyqt5-sip
%{summary}


%package macros
Summary: RPM macros for use when working with SIP
Group:   programming
Requires: rpm
# when arch->noarch happened
Obsoletes: sip-macros < 4.15.5
BuildArch: noarch

%description macros
This package contains RPM macros for use when working with SIP.
It is used by both the sip-devel (python 2) and python3-sip-devel subpackages.


%package -n python3-sip
Summary: SIP - Python 3/C++ Bindings Generator
Group: programming
BuildRequires: python3-devel
Provides: python3-sip-api(%{_sip_api_major}) = %{_sip_api}
Provides: python3-sip-api(%{_sip_api_major})%{?_isa} = %{_sip_api}

%description -n python3-sip
This is the Python 3 build of SIP.

SIP is a tool for generating bindings for C++ classes so that they can be
accessed as normal Python 3 classes. SIP takes many of its ideas from SWIG but,
because it is specifically designed for C++ and Python, is able to generate
tighter bindings. SIP is so called because it is a small SWIG.

SIP was originally designed to generate Python bindings for KDE and so has
explicit support for the signal slot mechanism used by the Qt/KDE class
libraries. However, SIP can be used to generate Python 3 bindings for any C++
class library.


%package -n python3-sip-devel
Summary: Files needed to generate Python 3 bindings for any C++ class library
Group: programming
Requires: %{name}-macros = %{version}-%{release}
Requires: python3-sip%{?_isa} = %{version}-%{release}
Requires: python3-devel

%description -n python3-sip-devel
This package contains files needed to generate Python 3 bindings for any C++
classes library.


%package -n python3-pyqt5-sip
Summary: SIP - Python 3/C++ Bindings Generator for pyqt5
Group: programming
BuildRequires: python3-devel
Provides: python3-pyqt5-sip-api(%{_sip_api_major}) = %{_sip_api}
Provides: python3-pyqt5-sip-api(%{_sip_api_major})%{?_isa} = %{_sip_api}
%description -n python3-pyqt5-sip
This is the Python 3 build of pyqt5-SIP.


%debug_package


%prep
%setup -q

%patch50 -p1 -b .no_strip
%patch51 -p1 -b .no_rpath
%patch53 -p1 -b .no_sip_so
%patch54 -p1 -b .py_ssize_t_clean
%patch55 -p1 -b .pyframe_getback


%build
%ifarch x86_64 ppc
OPT_FLAGS="%{optflags} -fPIC"
%else
OPT_FLAGS="%{optflags}"
%endif

mkdir %{_target_platform}-python3
pushd %{_target_platform}-python3
%{__python3} ../configure.py \
  -d %{python3_sitearch} \
  CXXFLAGS="${OPT_FLAGS}" CFLAGS="${OPT_FLAGS}" LFLAGS="%{?__global_ldflags}"

make %{?_smp_mflags} 
popd

mkdir %{_target_platform}
pushd %{_target_platform}
%{__python} ../configure.py \
  -d %{python_sitearch} \
  CFLAGS="${OPT_FLAGS}" CXXFLAGS="${OPT_FLAGS}" LFLAGS="%{?__global_ldflags}"

make %{?_smp_mflags}
popd

mkdir %{_target_platform}-python2-pyqt5
pushd %{_target_platform}-python2-pyqt5
%{__python} ../configure.py \
  --sip-module=PyQt5.sip \
  -b %{_bindir} -d %{python_sitearch} -e %{_includedir}/python%{python_version} \
  CFLAGS+="%{optflags}" CXXFLAGS+="%{optflags}" LFLAGS+="%{?__global_ldflags}"

make %{?_smp_mflags}
popd

mkdir %{_target_platform}-python3-pyqt5
pushd %{_target_platform}-python3-pyqt5
%{__python3} ../configure.py \
  --sip-module=PyQt5.sip \
  -b %{_bindir} -d %{python3_sitearch} -e %{_includedir}/python%{python3_version} \
  CXXFLAGS+="%{optflags}" CFLAGS+="%{optflags}" LFLAGS+="%{?__global_ldflags}"

make %{?_smp_mflags}
popd


%install
rm -rf %{buildroot}

# Perform the Python 3 installation first, to avoid stomping over the Python 2
# /usr/bin/sip:
make install DESTDIR=%{buildroot} -C %{_target_platform}-python3
make install DESTDIR=%{buildroot} -C %{_target_platform}-python3-pyqt5

mkdir -p %{buildroot}%{_datadir}/python3-sip
mv %{buildroot}%{_bindir}/sip %{buildroot}%{_bindir}/python3-sip

## toplevel __pycache__ creation is ... inconsistent
## rawhide makes one, f23 local builds do not, so let's *make* it consistent
mkdir -p %{buildroot}%{python3_sitearch}/__pycache__/exclude_rpm_hack

# Python 2 installation:
make install DESTDIR=%{buildroot} -C %{_target_platform}
make install DESTDIR=%{buildroot} -C %{_target_platform}-python2-pyqt5

# sip-wrapper
install %{SOURCE10} %{buildroot}%{_bindir}/sip-pyqt5
sed -i -e 's|@SIP_MODULE@|PyQt5.sip|g' %{buildroot}%{_bindir}/sip-pyqt5

mkdir -p %{buildroot}%{_datadir}/sip

# Macros used by -devel subpackages:
install -D -p -m644 %{SOURCE1} %{buildroot}%{rpm_macros_dir}/macros.sip


%clean
rm -rf $RPM_BUILD_ROOT


%files
%defattr(-, root, root, 755)
%doc NEWS README
%license LICENSE LICENSE-GPL2 LICENSE-GPL3
%{python_sitearch}/sip.so
%{_datadir}/sip/
%{python_sitearch}/*.dist-info

%files devel
%{_bindir}/sip
%{_bindir}/sip-pyqt5
%{_bindir}/python3-sip
%defattr(-, root, root, 755)
%{python_inc}/sip.h
%{python_sitearch}/sip*.py*

%files pyqt5-sip
%doc NEWS README
%license LICENSE LICENSE-GPL2 LICENSE-GPL3
%dir %{python_sitearch}/PyQt5/
%{python_sitearch}/PyQt5/sip.*
%{python_sitearch}/PyQt5_sip-%{version}.dist-info/

%files macros
%{rpm_macros_dir}/macros.sip

%files -n python3-sip
%doc NEWS README
%license LICENSE LICENSE-GPL2 LICENSE-GPL3
%{python3_sitearch}/sip.*
%{python3_sitearch}/*.dist-info

%files -n python3-sip-devel
# Note that the "sip" binary is invoked by name in a few places higher up
# in the KDE-Python stack; these will need changing to "python3-sip":
%{python3_inc}/sip.h
%{python3_sitearch}/sip*.py*
%{python3_sitearch}/__pycache__/*
%exclude %{python3_sitearch}/__pycache__/exclude_rpm_hack

%files -n python3-pyqt5-sip
%doc NEWS README
%license LICENSE LICENSE-GPL2 LICENSE-GPL3
%dir %{python3_sitearch}/PyQt5/
%{python3_sitearch}/PyQt5/sip.*
%{python3_sitearch}/PyQt5_sip-%{version}.dist-info/


%changelog
* Sat Oct 29 2022 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 4.19.25-2
- rebuilt with python3-3.11.

* Wed Apr 14 2021 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 4.19.25-1
- new upstream release.

* Sat Aug 15 2020 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 4.19.24-1
- new upstream release.

* Tue Oct 22 2019 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 4.19.19-1
- new upstream release.

* Tue Jul 12 2016 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 4.18-1
- new upstream release.

* Thu Jun 30 2016 Yoji TOYODA <bsyamato@sea.plala.or.jp> 4.16.4-2
- rebuild with gcc-5.4.0

* Sat Nov  8 2014 Ryoichi INAGAKI <ryo1@toki.waseda.jp> 4.16.4-1
- new upstream release

* Mon May 05 2014 Yoji TOYODA <bsyamato@sea.plala.or.jp> 4.15.5-1
- new upstream release

* Sun Dec 08 2013 Yoji TOYODA <bsyamato@sea.plala.or.jp> 4.15.3-1
- new upstream release

* Sun Sep 08 2013 Yoji TOYODA <bsyamato@sea.plala.or.jp> 4.14.7-1
- new upstream release

* Wed Jun 05 2013 Yoji TOYODA <bsyamato@sea.plala.or.jp> 4.14.6-1
- new upstream release

* Sun Jul 29 2012 Yoji TOYODA <bsyamato@sea.plala.or.jp> 4.13.3-1
- new upstream release

* Sat Feb 18 2012 Yoji TOYODA <bsyamato@sea.plala.or.jp> 4.13.1-2
- rebuild with python-2.7.2

* Sat Jan  7 2012 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 4.13.1-1
- new upstream release

* Sun Jul 31 2011 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 4.12.3-1
- new upstream release

* Sun Jan 30 2011 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 4.12.1-1
- new upstream release

* Mon Oct  4 2010 MATSUBAYASHI Kohji <shaolin@vinelinux.org> - 4.10.5-2
- add gcc option "-fPIC" also on ppc

* Sat Jul 24 2010 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 4.10.5-1
- new upstream release

* Sun May 09 2010 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 4.10.2-1
- new upstream release

* Wed Feb 03 2010 Shu KONNO <owa@bg.wakwak.com> 4.10-1
- new upstream release

* Wed Feb 03 2010 Shu KONNO <owa@bg.wakwak.com> 4.9.3-2
- rebuilt with python-2.6.4

* Wed Nov 25 2009 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 4.9.3-1
- new upstream release

* Thu Oct 22 2009 Shu KONNO <owa@bg.wakwak.com> 4.9-1
- new upstream release
- added japanese summary
- changed source url

* Sat Aug 29 2009 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 4.8.2-1
- new upstream release
- remove qt-devel dependency

* Sun Jul 20 2008 Shu KONNO <owa@bg.wakwak.com> 4.7.1-1vl1
- rebuilt with python-2.5.2
- applied new versioning policy and spec in utf-8

* Fri Nov 30 2007 Shu KONNO <owa@bg.wakwak.com> 4.7.1-0vl1
- new upstream release
- added gcc option "-fPIC" (if x86_64)

* Wed Sep  5 2007 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 4.7-0vl1
- new upstream release
- use qt qmake files

* Sun May 27 2007 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 4.4.5-0vl2
- rebuilt with new toolchain

* Sun Jun 11 2006 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 4.4.5-0vl1
- new upstream release
- rebuilt with python 2.4.3
- changed Group to Development/Languages

* Sun Apr 03 2005 Shu KONNO <owa@bg.wakwak.com> 3.11.1-0vl2
- Rebuild for python 2.4.1

* Sat Jan 15 2005 Satoshi MACHINO <machino@vinelinux.org> 3.11.1-0vl1
- built for VineLinux
- new upstream version

* Sat Dec 04 2004 Michael Scherer <misc@mandrake.org> 3.10.2-5mdk
- Rebuild for new python

* Wed Jun  9 2004 Götz Waschk <waschk@linux-mandrake.com> 3.10.2-4mdk
- obsolete libsip10 too

* Mon Jun  7 2004 Götz Waschk <waschk@linux-mandrake.com> 3.10.2-3mdk
- drop library packages

* Mon Jun 07 2004 Per Øyvind Karlsen <peroyvind@linux-mandrake.com> 3.10.2-2mdk
- fix build and install problems
- drop .so.*, they no longer exist
- use %%{py_ver} macro

* Sat Jun 05 2004 Per Øyvind Karlsen <peroyvind@linux-mandrake.com> 3.10.2-1mdk
- 3.10.2

* Fri Apr 23 2004 Götz Waschk <waschk@linux-mandrake.com> 3.10.1-1mdk
- add sipconfig
- major 11
- add source URL
- new version

* Mon Sep  8 2003 Götz Waschk <waschk@linux-mandrake.com> 3.8-3mdk
- fix buildrequires

* Sun Sep  7 2003 Götz Waschk <waschk@linux-mandrake.com> 3.8-2mdk
- fix buildrequires
- move libsip.so to the lib package, as it's required by generated bindings
- move sip to the devel package

* Wed Aug 20 2003 Austin Acton <aacton@yorku.ca> 3.8-1mdk
- 3.8

* Sat Aug 9 2003 Austin Acton <aacton@yorku.ca> 3.6-8mdk
- the one true fix (eat your heart out per oyvind :-) )

* Fri Aug 08 2003 Per Øyvind Karlsen <peroyvind@linux-mandrake.com> 3.6-7mdk
- really rebuild for new python (austin was the sucky one this time;)

* Thu Aug 7 2003 Austin Acton <aacton@yorku.ca> 3.6-6mdk
- python 2.3

* Sat Jul 19 2003 Till Kamppeter <till@mandrakesoft.com> 3.6-5mdk
- Rebuild

* Fri Jun 20 2003 Per Øyvind Karlsen <peroyvind@sintrax.net> 3.6-4mdk
- fix path to qt3 (lib64 issues)
- use %%mklibname macro for -devel package

* Tue May 27 2003 Austin Acton <aacton@yorku.ca> 3.6-3mdk
- rebuild for rpm 4.2

* Tue Apr 29 2003 Per Øyvind Karlsen <peroyvind@sintrax.net> 3.6-2mdk
- added QPL to license

* Tue Apr 29 2003 Per Øyvind Karlsen <peroyvind@sintrax.net> 3.6-1mdk
- 3.6 (lib major 9)
- cleanups
- fix license
- make --short-circuitable
- use %%mklibname macro

* Fri Jan 03 2003 Lenny Cartier <lenny@mandrakesoft.com> 3.5-1mdk
- 3.5

* Sat Aug 17 2002 Christian Belisle <cbelisle@mandrakesoft.com> 3.3.2-2mdk
- fix Provides for libsip9.

* Wed Jul 17 2002 Christian Belisle <cbelisle@mandrakesoft.com> 3.3.2-1mdk
- 3.3.2
- use the new sip's build script

* Sat Jun 29 2002 Olivier Thauvin <thauvin@aerov.jussieu.fr> 3.2.4-1mdk
- 3.2.4

* Tue May 28 2002 Lenny Cartier <lenny@mandrakesoft.com> 3.2.2-2mdk
- rebuild against new libstdc++

* Mon May 13 2002 Lenny Cartier <lenny@mandrakesoft.com> 3.2.2-1mdk
- 3.2.2

* Tue May 07 2002 Lenny Cartier <lenny@mandrakesoft.com> 3.2.1-1mdk
- 3.2.1

* Mon Apr 08 2002 Christian Belisle <cbelisle@mandrakesoft.com> 3.1-1mdk
- version 3.1 (lib major 8).
- update URL.

* Fri Jan 11 2002 Lenny Cartier <lenny@mandrakesoft.com> 3.0-3mdk
- merge with  RA <ralf_ahlbrink@web.de> mods :
	- added BuildRequires: libpython2.2-devel

* Fri Nov 30 2001 Yves Duret <yduret@mandrakesoft.com> 3.0-1mdk
- version 3.0 (lib major 7)

* Fri Nov 30 2001 Yves Duret <yduret@mandrakesoft.com> 2.5-2mdk
- rebuild against libpng3
- %%makeinstall_std
- std %%build step (macros..)
- added %%dir %%{_includedir}/sip in -devel package

* Mon Sep 03 2001 Lenny Cartier <lenny@mandrakesoft.com> 2.5-1mdk
- 2.5

* Mon May 14 2001 Yves BAILLY <ybailly@mandrakesoft.com> 2.4-3mdk
- fixed some errors in spec file (sorry, my first package)

* Mon May 14 2001 Yves BAILLY <ybailly@mandrakesoft.com> 2.4-2mdk
- fixed the Python dependency (>= 2.0 instead of = 2.0)

* Mon May 14 2001 Yves BAILLY <ybailly@mandrakesoft.com> 2.4-1mdk
- upgrade to version 2.4

* Tue Mar 20 2001 David BAUDENS <baudens@mandrakesoft.com> 2.3-2mdk
- Rebuild against Qt 2.3.0

* Wed Feb 21 2001 Lenny Cartier <lenny@mandrakesoft.com> 2.3-1mdk
- updated to 2.3

* Mon Feb 12 2001 Lenny Cartier <lenny@mandrakesoft.com> 2.2-1mdk
- used srpm from Gerard Vermeulen <gvermeul@labs.polycnrs-gre.fr>
        - built on Mandrake-7.2 following Mandrake RPM guidelines


