File libkolab.spec of Package libkolab

#
# spec file for package libkolab
#
# Copyright (c) 2025 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via https://bugs.opensuse.org/
#


%define php_name %(php -r "print 'php' . PHP_MAJOR_VERSION;")
%define php_major %(php -r "print PHP_MAJOR_VERSION;")

%global php_extdir %{_libdir}/%{php_name}/extensions
%global php_confdir %{_sysconfdir}/%{php_name}/conf.d
%define libname %{name}3

%bcond_without php
%bcond_without python
%bcond_without tests

Name:           libkolab
Version:        3.0.2
Release:        0
Summary:        Conversions from/to KDE containers
License:        LGPL-2.0-or-later and LGPL-3.0-or-later
Group:          Development/Libraries/C and C++
Url:            https://git.kolab.org/source/libkolab/
Source:         %{name}-%{version}.tar.gz
# PATCH-FIX-SUSE: add PHP7 bindings support
Patch1:         libkolab-3.0.2-PHP7+8.patch
BuildRequires:  cmake >= 3.0
BuildRequires:  gcc-c++
BuildRequires:  kcalendarcore-devel > 5.12
BuildRequires:  kmime-devel > 4.84
BuildRequires:  libcurl-devel
BuildRequires:  libboost_atomic-devel
BuildRequires:  libboost_chrono-devel
BuildRequires:  libboost_date_time-devel
BuildRequires:  libboost_system-devel
BuildRequires:  libboost_thread-devel
BuildRequires:  libkolabxml-devel >= 1.1.6
BuildRequires:  libQt5Core-devel
BuildRequires:  libQt5Xml-devel
BuildRequires:  libxerces-c-devel
BuildRequires:  swig >= 3.0.11
BuildRequires:  pkgconfig

%if %{with php}
BuildRequires:  php-devel >= 8.0
%endif

%if %{with python}
BuildRequires:  python3-devel
%endif

%if %{with tests}
BuildRequires:  libQt5Test-devel
%endif

%description
libkolab provides conversions from/to KDE containers, mime message handling and facilities
to read and write kolabv2 and kolabv3.
The Akonadi-Kolab-Resource as well as the upgradetool are based on this code.

%package -n %{libname}
Summary:        Conversions from/to KDE containers
Group:          Development/Libraries/C and C++

%description -n %{libname}
libkolab provides conversions from/to KDE containers, mime message handling and facilities
to read and write kolabv2 and kolabv3.
The Akonadi-Kolab-Resource as well as the upgradetool are based on this code.

%package devel
Summary:        Conversions from/to KDE containers
Group:          Development/Libraries/C and C++
Requires:       %{libname} = %{version}
Requires:       libXerces-c-devel
Requires:       libkolabxml-devel >= 1.1.1

%description devel
libkolab provides conversions from/to KDE containers, mime message handling and facilities
to read and write kolabv2 and kolabv3.
The Akonadi-Kolab-Resource as well as the upgradetool are based on this code.

%package -n %{php_name}-%{libname}
Summary:        PHP Bindings for libkolab
Group:          Development/Languages/Other
Requires:       %{libname} = %{version}
Provides:       php-%{libname} = %{version}
Obsoletes:      %{php_name}-%{libname} < %{version}-%{release}

%description -n %{php_name}-%{libname}
libkolab provides conversions from/to KDE containers, mime message handling and facilities
to read and write kolabv2 and kolabv3.
This package provides PHP Bindings for libkolab.

%package -n python3-%{libname}
Summary:        Python bindings for libkolab
Group:          Development/Languages/Python
Requires:       %{libname} = %{version}
Obsoletes:      python3-%{libname} < %{version}-%{release}

%description -n python3-%{libname}
libkolab provides conversions from/to KDE containers, mime message handling and facilities
to read and write kolabv2 and kolabv3.
This package provides Python bindings for libkolab.

%prep
%setup -q
%patch1 -p1

# We're using the cmake version for setting version information etc.
rm cmake/modules/FindSWIG.cmake

%build
# TESTS: require X and most fail anyway
%cmake \
    -DLibkolabxml_DIR=%{_libdir}/cmake/Libkolabxml \
    -DBoost_NO_BOOST_CMAKE=TRUE \
%if %{with php}
    -DPHP_BINDINGS=TRUE -DPHP_INSTALL_DIR=%{php_extdir} -DPHP_MAJOR=%{php_major} \
%endif
%if %{with python}
    -DPYTHON_BINDINGS=TRUE -DPYTHON_INSTALL_DIR=%{python3_sitearch} \
%endif
%if %{with tests}
    -DBUILD_TESTS=TRUE \
%else
    -DBUILD_TESTS=FALSE
%endif

make %{?_smp_mflags}

%install
%cmake_install

%if %{with php}
%if 0%{?sle_version} < 150600 && 0%{?suse_version} < 1600
# SWIG prior to 4.1 builds a .php wrapper to load the PHP extensions.
# With SWIG 4.1 (present in Leap >= 15.6), PHP wrapping is now done entirely via PHP's C API 
mkdir -p %{buildroot}%{_datadir}/%{php_name}
mv %{buildroot}%{php_extdir}/*.php %{buildroot}%{_datadir}/%{php_name}/.
%endif

mkdir -p %{buildroot}%{php_confdir}
cat >%{buildroot}%{php_confdir}/kolab.ini <<EOF
; Kolab libraries
extension=kolabcalendaring.so
extension=kolabobject.so
extension=kolabshared.so
EOF

cat >%{buildroot}%{php_confdir}/kolabdummy.ini <<EOF
; Kolab libraries
extension=dummy.so
EOF
%endif

%if %{with tests}
%check
cd build/tests
./calendaringtest || :
./kcalconversiontest || :
./timezonetest || :
%endif

%post   -n %{libname} -p /sbin/ldconfig
%postun -n %{libname} -p /sbin/ldconfig

%files -n %{libname}
%license COPYING*
%doc README RELEASE-NOTES
%{_libdir}/libkolab.so.*

%files devel
%license COPYING*
%{_includedir}/kolab/
%{_libdir}/libkolab.so
%{_libdir}/cmake/Libkolab/

%if %{with php}
%files -n %{php_name}-%{libname}
%license COPYING*
%config(noreplace) %{php_confdir}/kolab.ini
%config(noreplace) %{php_confdir}/kolabdummy.ini
%if 0%{?sle_version} < 150600 && 0%{?suse_version} < 1600
%{_datadir}/%{php_name}/kolabcalendaring.php
%{_datadir}/%{php_name}/kolabobject.php
%{_datadir}/%{php_name}/kolabshared.php
%{_datadir}/%{php_name}/dummy.php
%endif
%{php_extdir}/kolabcalendaring.so
%{php_extdir}/kolabobject.so
%{php_extdir}/kolabshared.so
%{php_extdir}/dummy.so
%endif

%if %{with python}
%files -n python3-%{libname}
%license COPYING*
%dir %{python3_sitearch}/kolab
%{python3_sitearch}/kolab/_calendaring.so
%{python3_sitearch}/kolab/calendaring.py*
%{python3_sitearch}/kolab/_kolabobject.so
%{python3_sitearch}/kolab/kolabobject.py*
%{python3_sitearch}/kolab/_shared.so
%{python3_sitearch}/kolab/shared.py*
%endif

%changelog
openSUSE Build Service is sponsored by