%define csharp 1
%define falcon 0
%define php 1
%define ruby 1
%define smoke 1
%define java 0

%define pykde4_akonadi 1
%define pyqt4_version 4.7
# Qt4 version auto-detection -- inagaki
%define _qt4_version %(pkg-config --modversion --silence-errors Qt 2>/dev/null ||
 echo 4.6.1)
%define mono_dir %{_prefix}/lib/mono

#if 0%{?ruby}%{?smoke}
#define devel 1
#endif

%global ruby_lib %(ruby -rrbconfig -e 'puts Config::CONFIG["rubylibdir"]')
%global ruby_arch %(ruby -rrbconfig -e 'puts Config::CONFIG["archdir"]')
%global ruby_sitelib %(ruby -rrbconfig -e 'puts Config::CONFIG["sitelibdir"]')
%global ruby_sitearch %(ruby -rrbconfig -e 'puts Config::CONFIG["sitearchdir"]')
%global python_ver %(%{__python} -c "import sys ; print sys.version[:3]")
%global python_sitelib  %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")
%global python_sitearch %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib(1)")

Name: kdebindings
Version: 4.4.2
Release: 1%{?_dist_release}
Summary: KDE bindings to non-C++ languages.
Source: ftp://ftp.kde.org/pub/kde/stable/%{version}/src/%{name}-%{version}.tar.bz2

# http://techbase.kde.org/Policies/Licensing_Policy
License: LGPLv2+
Group: System Environment/Libraries
URL: http://www.kde.org/

# fix build with CMAKE_SKIP_RPATH - also needs sed line below
# WARNING: This is a bunch of quick hacks to get this to build. Please do not
#          commit this upstream without further discussion.
Patch1:  kdebindings-4.3.75-no-rpath.patch

BuildRoot: %{_tmppath}/%{name}-%{version}-root
BuildRequires:  akonadi-devel >= 1.3.0
BuildRequires:  kdebase-workspace-devel >= %{version}
# okular bindings
BuildRequires:  kdegraphics-devel >= %{version}
BuildRequires:  kdelibs4-devel >= %{version}
BuildRequires:  kdepimlibs-devel >= %{version}
# kdebindings does not support polkit-qt-1 yet
#BuildRequires:  polkit-qt-devel
BuildRequires:  python-devel
BuildRequires:  PyQt4-devel >= %{pyqt4_version}
BuildRequires:  qimageblitz-devel
BuildRequires:  qscintilla-devel >= 2.4
BuildRequires:  soprano-devel
%if %{csharp}
BuildRequires:  mono-core
BuildRequires:  mono-devel
%endif
%if %{falcon}
BuildRequires:  Falcon-devel >= 0.8.12
%endif
%if %{php}
BuildRequires:  php5-devel
%endif
%if %{ruby}
BuildRequires:  ruby-devel
BuildRequires:  ruby
%endif
%if %{java}
# TODO: kross-java is a mess, not sure what it needs to build
# CMakeLists.txt is also not portable (only gcj and i486 hardcoded)
# -- mathstuf
BuildRequires:  java-1.6.0-openjdk-devel
%endif

Requires: kdelibs4 >= %{version}

%description
KDE bindings to non-C++ languages

%package devel
Summary: Development files for kdebindings.
Group: Development/Libraries
Requires: %{name} = %{version}-%{release}
Requires: kdelibs4-devel

%description devel
Development files for the KDE bindings.

Install kdebindings-devel if you want to develop non-KDE applications
that talk to KDE.

%package -n PyKDE4
Summary:  Python bindings for KDE4
Summary(ja): KDE4 の Python バインディング
Group:    Development/Languages
Requires: kdelibs4 >= %{version}
Requires: PyQt4 >= %{pyqt4_version}

%description -n PyKDE4
%{summary}.

%package -n PyKDE4-akonadi
Summary: Akonadi runtime support for PyKDE4 
Group: Development/Languages 
Requires: PyKDE4 = %{version}-%{release}
Requires: kdepimlibs-akonadi >= %{version} 

%description -n PyKDE4-akonadi 
%{summary}.

%package -n PyKDE4-devel
Group:    Development/Libraries
Summary:  Files needed to build PyKDE4-based applications
Requires: PyQt4-devel
Requires: PyKDE4 = %{version}-%{release}
Requires: PyKDE4-akonadi = %{version}-%{release}

%description -n PyKDE4-devel
%{summary}.

# C# bindings
%if %{csharp}
%package -n kimono
Group:    Development/Languages
Summary:  C# bindings for KDE4
Summary(ja): KDE4 の C# バインディング
Requires: kdelibs4 >= %{version}
Requires: qyoto = %{version}-%{release}
Provides: kimono4 = %{version}-%{release}

%description -n kimono
%{summary}.

%package -n qyoto
Group:    Development/Languages
Summary:  C# bindings for Qt4
Summary(ja): Qt4 の C# バインディング
Requires: qt4 >= %{qt4_version} 
Provides: qyoto4 = %{version}-%{release}

%description -n qyoto
%{summary}.

%package -n qyoto-devel
Group:    Development/Libraries
Summary:  Development files for qyoto
Requires: qyoto = %{version}-%{release}
Requires: mono-devel
Provides: qyoto4-devel = %{version}-%{release}

%description -n qyoto-devel
%{summary}.
%endif

# Ruby
%if %{ruby}
%package -n korundum
Group:    Development/Languages
Summary:  Ruby bindings for KDE4
Summary(ja): KDE4 の Ruby バインディング
Requires: kdelibs4 >= %{version}
Requires: QtRuby = %{version}-%{release}
Provides: korundum4 = %{version}-%{release}

%description -n korundum
%{summary}.

%package -n korundum-devel
Group:    Development/Libraries
Summary:  Development files for korundum
Requires: QtRuby-devel
Requires: korundum = %{version}-%{release}
Provides: korundum4-devel = %{version}-%{release}

%description -n korundum-devel
%{summary}.

%package -n QtRuby
Group:    Development/Languages
Summary:  Ruby bindings for Qt4
Summary(ja): Qt4 の Ruby バインディング
Requires: qt4 >= %{qt4_version} 
Provides: QtRuby4 = %{version}-%{release}

%description -n QtRuby
%{summary}.

%package -n QtRuby-devel
Group:    Development/Libraries
Summary:  Development files for QtRuby
Requires: QtRuby = %{version}-%{release}
Provides: QtRuby4-devel = %{version}-%{release}
%description -n QtRuby-devel
%{summary}.
%endif

%if %{php}
%package -n php-qt
Group:    Development/Languages
Summary:  PHP bindings for Qt4
Summary(ja): Qt4 の PHP バインディング
Requires: qt4 >= %{qt4_version} 
Provides: php-qt4 = %{version}-%{release}

%description -n php-qt
%{summary}.

%package -n php-qt-devel
Group:    Development/Libraries
Summary:  Development files for php-qt
Requires: php-qt = %{version}-%{release}
Provides: php-qt4-devel = %{version}-%{release}

%description -n php-qt-devel
%{summary}.
%endif

%package -n kross-python
Group:    Development/Languages
Summary:  Kross plugin for python
Requires: kdelibs4 >= %{version}
Provides: kross(python) = %{version}-%{release}

%description -n kross-python
Python plugin for the Kross archtecture in KDE4.

%if %{ruby}
%package -n kross-ruby
Group:    Development/Languages
Summary:  Kross plugin for ruby
Requires: ruby
Requires: kdelibs4 >= %{version}
Provides: kross(ruby) = %{version}-%{release}

%description -n kross-ruby
Ruby plugin for the Kross archtecture in KDE4.
%endif

%if %{falcon}
%package -n kross-falcon
Group:    Development/Languages
Summary:  Kross plugin for falcon
Requires: Falcon >= 0.8.12
Requires: kdelibs4 >= %{version}
Provides: kross(falcon) = %{version}-%{release}

%description -n kross-falcon
Falcon plugin for the Kross archtecture in KDE4.
%endif


%prep
%setup -q

# do the no-rpath hack last, after the upstream backports (if any)
#patch1 -p1 -b .no-rpath
#sed -i -e 's!COMMAND generator!COMMAND ${PROJECT_BINARY_DIR}/generator/bin/generator${CMAKE_EXECUTABLE_SUFFIX}.shell!g' -e 's/WORKING_DIRECTORY/DEPENDS generator WORKING_DIRECTORY/g' smoke/*/CMakeLists.txt

%build
mkdir -p %{_target_platform}
pushd %{_target_platform}
unset QTDIR || : ; . /etc/profile.d/qt4.sh
%cmake \
    -DCMAKE_BUILD_TYPE=release \
    -DDATA_INSTALL_DIR:PATH=%{_datadir}/kde4/apps \
    -DINCLUDE_INSTALL_DIR:PATH=%{_includedir}/kde4 \
    -DLIBEXEC_INSTALL_DIR:PATH=%{_libexecdir}/kde4 \
    -DPYTHON_LIBRARY=%{_libdir}/libpython%{python_ver}.so.1.0 \
    -DPYTHON_LIBRARIES=%{_libdir}/libpython%{python_ver}.so.1.0 \
    -DPYTHON_INCLUDE_PATH=%{_includedir}/python%{python_ver} \
  %if %{csharp}
    -DENABLE_QYOTO=ON \
  %else
    -DBUILD_csharp=OFF \
  %endif
  %if %{falcon}
    -DENABLE_KROSSFALCON=ON \
  %else
    -DBUILD_falcon=OFF \
  %endif
  %if %{php}
    -DENABLE_PHP-QT=ON \
  %else
    -DBUILD_php=OFF \
  %endif
  %if %{ruby}
    -DRUBY_SITE_LIB_DIR:PATH=%{ruby_sitelib} \
    -DRUBY_SITE_ARCH_DIR:PATH=%{ruby_sitearch} \
    -DCUSTOM_RUBY_SITE_LIB_DIR:PATH=%{ruby_lib} \
    -DCUSTOM_RUBY_SITE_ARCH_DIR:PATH=%{ruby_arch} \
  %else
    -DBUILD_ruby=OFF \
  %endif
  %if %{smoke}
    -DENABLE_SMOKE=ON \
  %else
    -DBUILD_smoke=OFF \
  %endif
  %if %{java}
    -DENABLE_KROSSJAVA=ON \
  %else
    -DBUILD_java=OFF \
  %endif
    -DCMAKE_SKIP_RPATH:BOOL=OFF \
    ..
popd
#    -DRUBY_INCLUDE_PATH:PATH=%{ruby_arch} \

# smp build not recommended (upstream)
make -C %{_target_platform}

%install
rm -rf $RPM_BUILD_ROOT
make install/fast DESTDIR=$RPM_BUILD_ROOT -C %{_target_platform}

# HACK: fix multilb conflict, similar to PyQt4's http://bugzilla.redhat.com/509415
rm -fv $RPM_BUILD_ROOT%{_bindir}/pykdeuic4
mv $RPM_BUILD_ROOT%{python_sitearch}/PyQt4/uic/pykdeuic4.py \
   $RPM_BUILD_ROOT%{_bindir}/pykdeuic4
ln -s %{_bindir}/pykdeuic4 \
      $RPM_BUILD_ROOT%{python_sitearch}/PyQt4/uic/pykdeuic4.py

# install pykde4 examples under correct dir
#mkdir -p %{buildroot}%{_docdir}
#rm -f %{buildroot}%{_datadir}/kde4/apps/pykde4/examples/*.py?
#mv %{buildroot}%{_datadir}/kde4/apps/pykde4 %{buildroot}%{_docdir}/

# bz#551534 - qyoto doesn't pull mono in
%if %{csharp}
find %{buildroot} -name \*.dll -not -type l | xargs chmod ugo+x
%endif


%clean
rm -rf $RPM_BUILD_ROOT 

%post -p /sbin/ldconfig

%postun -p /sbin/ldconfig

%pre -n PyKDE4-devel
if [ -d %{_bindir}/pykdeuic4 ]; then
    rm -rf %{_bindir}/pykdeuic4/
fi


%files
%defattr(-,root,root)
%doc AUTHORS ChangeLog COPYING NEWS README
%if %{smoke}
%{_libdir}/libsmoke*.so.*
%endif

%files devel
%defattr(-,root,root)
%if %{smoke}
%{_bindir}/smoke*
%{_includedir}/smoke.h
%{_includedir}/smoke
%{_libdir}/libcppparser.so
%{_libdir}/libsmoke*.so
%dir %{_libdir}/smokegen
%{_libdir}/smokegen/*.so
%{_datadir}/smokegen
%endif

%files -n PyKDE4
%defattr(-,root,root,-)
%doc COPYING
%{python_sitearch}/PyKDE4
%{python_sitearch}/PyQt4/uic/widget-plugins/kde4.py*
%dir %{_datadir}/kde4/apps/pykde4
%{_libdir}/kde4/kpythonpluginfactory.so
%exclude %{python_sitearch}/PyKDE4/akonadi.so

%files -n PyKDE4-akonadi
%defattr(-,root,root,-)
%{python_sitearch}/PyKDE4/akonadi.so

%files -n PyKDE4-devel
%defattr(-,root,root,-)
%{_bindir}/pykdeuic4
%{python_sitearch}/PyQt4/uic/pykdeuic4.py*
%{_datadir}/kde4/apps/pykde4/examples/
%{_datadir}/sip/PyKDE4

%if %{csharp}
%files -n kimono
%defattr(-,root,root,-)
%{_libdir}/kde4/kimonopluginfactory.so
%{_libdir}/libakonadi-sharp.so
%{_libdir}/libkhtml-sharp.so
%{_libdir}/libkimono.so
%{_libdir}/libktexteditor-sharp.so
%{_libdir}/libnepomuk-sharp.so
%{_libdir}/libplasma-sharp.so
%{_libdir}/libsoprano-sharp.so
%{_libdir}/libqimageblitz-sharp.so
%{mono_dir}/qyoto/qimageblitz.dll
%{mono_dir}/qyoto/akonadi.dll
%{mono_dir}/qyoto/kde-dotnet.dll
%{mono_dir}/qyoto/khtml-dll.dll
%{mono_dir}/qyoto/ktexteditor-dotnet.dll
%{mono_dir}/qyoto/nepomuk-dll.dll
%{mono_dir}/qyoto/plasma-dll.dll
%{mono_dir}/qyoto/soprano.dll
%{mono_dir}/gac/akonadi
%{mono_dir}/gac/kde-dotnet
%{mono_dir}/gac/khtml-dll
%{mono_dir}/gac/ktexteditor-dotnet
%{mono_dir}/gac/nepomuk-dll
%{mono_dir}/gac/plasma-dll
%{mono_dir}/gac/soprano
%{mono_dir}/gac/qimageblitz
%{_datadir}/kde4/apps/plasma_scriptengine_kimono
%{_datadir}/kde4/services/plasma-scriptengine-kimono-applet.desktop
%{_datadir}/kde4/services/plasma-scriptengine-kimono-dataengine.desktop

%files -n qyoto
%defattr(-,root,root,-)
%{_libdir}/libqtscript-sharp.so
%{_libdir}/libqttest-sharp.so
%{_libdir}/libqtuitools-sharp.so
%{_libdir}/libqtwebkit-sharp.so
%{_libdir}/libqyoto.so
%{_libdir}/libqyotoshared.so.1
%{_libdir}/libqyotoshared.so.1.0.0
%{mono_dir}/qyoto/qt-dotnet.dll
%{mono_dir}/qyoto/qtscript.dll
%{mono_dir}/qyoto/qttest.dll
%{mono_dir}/qyoto/qtuitools.dll
%{mono_dir}/qyoto/qtwebkit.dll
%{mono_dir}/gac/qt-dotnet
%{mono_dir}/gac/qtscript
%{mono_dir}/gac/qttest
%{mono_dir}/gac/qtuitools
%{mono_dir}/gac/qtwebkit

%files -n qyoto-devel
%defattr(-,root,root,-)
%{_bindir}/csrcc
%{_bindir}/uics
%{_includedir}/qyoto
%{_libdir}/libqyotoshared.so
%{_libdir}/pkgconfig/*
%endif

%if %{ruby}
%files -n korundum
%defattr(-,root,root,-)
%{_bindir}/krubyapplication
%{ruby_lib}/KDE/
%{ruby_lib}/akonadi/
%{ruby_lib}/khtml/
%{ruby_lib}/ktexteditor/
%{ruby_lib}/okular/
%{ruby_lib}/solid/
%{ruby_lib}/soprano/
%{ruby_lib}/nepomuk/
%{ruby_arch}/akonadi.so
%{ruby_arch}/khtml.so
%{ruby_arch}/korundum4.so
%{ruby_arch}/ktexteditor.so
%{ruby_arch}/okular.so
%{ruby_arch}/plasma_applet.so
%{ruby_arch}/solid.so
%{ruby_arch}/soprano.so
%{ruby_arch}/nepomuk.so
%{_libdir}/kde4/krubypluginfactory.so
%{_datadir}/applications/kde4/dbpedia_references.desktop
%{_datadir}/kde4/apps/dbpedia_references

%files -n korundum-devel
%defattr(-,root,root,-)
%{_bindir}/rbkconfig_compiler4
%{_includedir}/qtruby/
%exclude %{_libdir}/libqtruby4shared.so

%files -n QtRuby
%defattr(-,root,root,-)
%{ruby_lib}/Qt/
%{ruby_lib}/Qt*.rb
%{ruby_lib}/qtscript/
%{ruby_lib}/qttest/
%{ruby_lib}/qtuitools/
%{ruby_lib}/qtwebkit/
%{ruby_arch}/qt*.so
%{_libdir}/libqtruby4shared.so.2
%{_libdir}/libqtruby4shared.so.2.0.0

%files -n QtRuby-devel
%defattr(-,root,root,-)
%{_bindir}/rbqtapi
%{_bindir}/rbrcc
%{_bindir}/rbuic4
%{_libdir}/libqtruby4shared.so
%endif

%if %{php}
%files -n php-qt
%defattr(-,root,root,-)
%{_libdir}/php5/php_qt.so

%files -n php-qt-devel
%defattr(-,root,root,-)
%{_bindir}/phpuic
%endif

%files -n kross-python
%defattr(-,root,root,-)
# unversioned library
%{_libdir}/kde4/krosspython.so

%if %{ruby}
%files -n kross-ruby
%defattr(-,root,root,-)
%{_libdir}/kde4/krossruby.so
%endif

%if %{falcon}
%files -n kross-falcon
%defattr(-,root,root,-)
%{_libdir}/kde4/krossfalcon.so
%endif

%changelog
* Thu Apr 15 2010 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 4.4.2-1
- new upstream release

* Tue Mar  9 2010 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 4.4.1-1
- new upstream release
- added -DCMAKE_SKIP_RPATH:BOOL=OFF option to cmake
  (see https://bugs.kde.org/show_bug.cgi?id=214824)
- built with new toolchain

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

* Thu Oct 29 2009 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 4.3.2-4
- merged 4.3.1-2 %changelog 
- re-define %%{mono_dir} to %{_prefix}/lib/mono (again)

* Tue Oct 27 2009 Shu KONNO <owa@bg.wakwak.com> 4.3.2-3
- use %%{_prefix}/lib for mono-dll (for x86_64)

* Tue Oct 27 2009 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 4.3.2-2
- new upstream release
- built with PyQt4-4.6

* Sun Sep 06 2009 NAKAMURA Kenta <kenta@vinelinux.org> 4.3.1-2
- define %%{mono_dir} to specify mono library install path

* Sun Sep  6 2009 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 4.3.1-1
- new upstream release
- fixed ruby modules installation path

* Thu Aug 20 2009 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 4.3.0-1
- new upstream release
- spilt sub package based on Fedora

* Mon May 11 2009 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 3.5.8-1
- applied new versioning policy
- added Patch1 
  (http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=484191)

* Fri Nov 23 2007 NAKAMURA Kenta <kenta@vinelinux.org> 3.5.8-0vl3
- added --with-qt-libraries option

* Mon Oct 29 2007 AKIYAMA Kazuhito <akiyama@yb3.so-net.ne.jp> 3.5.8-0vl2
- rebuild for VineSeed

* Mon Oct 29 2007 AKIYAMA Kazuhito <akiyama@yb3.so-net.ne.jp> 3.5.8-0vl1
- new upstream release

* Mon Jun 25 2007 AKIYAMA Kazuhito <akiyama@yb3.so-net.ne.jp> 3.5.7-0vl2
- rebuild for VineSeed

* Thu May 31 2007 AKIYAMA Kazuhito <akiyama@yb3.so-net.ne.jp> 3.5.7-0vl1
- new upstream release
- update Patch0
- drop Patch1

* Mon Jan 29 2007 AKIYAMA Kazuhito <akiyama@yb3.so-net.ne.jp> 3.5.6-0vl1
- new upstream release
- add Patch1
- add --enable-libsuffix option

* Tue Oct  3 2006 AKIYAMA Kazuhito <akiyama@yb3.so-net.ne.jp> 3.5.5-0vl2
- rebuild for VineSeed

* Tue Oct  3 2006 AKIYAMA Kazuhito <akiyama@yb3.so-net.ne.jp> 3.5.5-0vl1
- new upstream release

* Wed Aug  2 2006 AKIYAMA Kazuhito <akiyama@yb3.so-net.ne.jp> 3.5.4-0vl2
- rebuild for VineSeed

* Wed Aug  2 2006 AKIYAMA Kazuhito <akiyama@yb3.so-net.ne.jp> 3.5.4-0vl1
- new upstream release

* Thu Jun  1 2006 AKIYAMA Kazuhito <akiyama@yb3.so-net.ne.jp> 3.5.3-0vl2
- rebuild for VineSeed

* Thu Jun  1 2006 AKIYAMA Kazuhito <akiyama@yb3.so-net.ne.jp> 3.5.3-0vl1
- new upstream release

* Wed Mar 22 2006 AKIYAMA Kazuhito <akiyama@yb3.so-net.ne.jp> 3.5.2-0vl2
- rebuild for VineSeed

* Wed Mar 22 2006 AKIYAMA Kazuhito <akiyama@yb3.so-net.ne.jp> 3.5.2-0vl1
- new upstream release

* Wed Feb  1 2006 AKIYAMA Kazuhito <akiyama@yb3.so-net.ne.jp> 3.5.1-0vl2
- rebuild for VineSeed

* Wed Feb  1 2006 AKIYAMA Kazuhito <akiyama@yb3.so-net.ne.jp> 3.5.1-0vl1
- new upstream release
- renew BuildPrereq and build section
- renew %%files
- enable python
- change spec to make main and devel package
- add BuildPrereq: ruby ruby-devel
- add Patch0 to install ruby-bindings under /usr/lib/ruby

* Sun Mar 17 2002 AKIYAMA Kazuhito <akiyama@karen.servepics.com> 2.2.2-1vl1
- build for VineSeed
- disable python and mozilla
- objprelink (i386 only)

* Wed Nov 21 2001 Than Ngo <than@redhat.com> <bero@redhat.com> 2.2.2-1
- 2.2.2
- build kmozilla binding only on x86/alpha

* Thu Aug  9 2001 Bernhard Rosenkraenzer <bero@redhat.com> 2.2-2
- Make sure %%{name}-kmozilla isn't built on ia64

* Mon Jul 23 2001 Bernhard Rosenkraenzer <bero@redhat.com> 2.2-0.cvs20010723.2
- Move python bindings to separate package
- Add perl bindings
- Shut up rpmlint

* Wed Feb 21 2001 Bernhard Rosenkraenzer <bero@redhat.com>
- 2.1

* Sun Jan 28 2001 Bernhard Rosenkraenzer <bero@redhat.com>
- initial RPM
