File sanlock.spec of Package sanlock

#
# spec file for package sanlock
#
# Copyright (c) 2012 SUSE LINUX Products GmbH, Nuernberg, Germany.
#
# 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 http://bugs.opensuse.org/
#


%define with_systemd       0
%if 0%{?suse_version} > 1140
%define with_systemd       1
%endif

Name:           sanlock
Version:        2.1
Release:        1%{?dist}
Summary:        A shared disk lock manager
License:        GPL-2.0 ; GPL-2.0+ ; LGPL-2.1+
Group:          System/Base

Url:            https://fedorahosted.org/sanlock/
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
BuildRequires:  libaio-devel
BuildRequires:  libblkid-devel
BuildRequires:  python
BuildRequires:  python-devel
%if %{with_systemd}
BuildRequires:  systemd
%{?systemd_requires}
%endif
Requires(pre):  %insserv_prereq %fillup_prereq
Requires:       %{name}-lib = %{version}-%{release}
# Latest version available at
# https://fedorahosted.org/releases/s/a/sanlock/
Source0:        %{name}-%{version}.tar.bz2
Source1:        sanlock.init
Source2:        wdmd.init
Source3:        sysconfig.sanlock
Patch0:         sanlock-SCHED_RESET_ON_FORK-undefined.patch
Patch1:         sanlock-python-prefix.patch
Patch2:         sanlock-old_blkid.patch
Patch3:         suse-systemd.patch
Patch4:         suse-no-date-time.patch

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

%description
sanlock uses disk paxos to manage leases on shared storage.
Hosts connected to a common SAN can use this to synchronize their
access to the shared disks.

%prep
%setup -q
%patch0
%patch1
%patch2
%patch3 -p1
%patch4 -p1

%build
# upstream does not require configure
# upstream does not support _smp_mflags
CFLAGS=$RPM_OPT_FLAGS make -C wdmd
CFLAGS=$RPM_OPT_FLAGS make -C src
CFLAGS=$RPM_OPT_FLAGS make -C python

%install
make -C src \
        install LIBDIR=%{_libdir} \
        DESTDIR=$RPM_BUILD_ROOT
make -C wdmd \
        install LIBDIR=%{_libdir} \
        DESTDIR=$RPM_BUILD_ROOT
make -C python \
        install LIBDIR=%{_libdir} \
        DESTDIR=$RPM_BUILD_ROOT PREFIX=%_prefix
install -D -m 755 %SOURCE1 $RPM_BUILD_ROOT/etc/init.d/sanlock
ln -s /etc/init.d/sanlock $RPM_BUILD_ROOT%{_sbindir}/rcsanlock
install -D -m 755 %SOURCE3 $RPM_BUILD_ROOT/%{_localstatedir}/adm/fillup-templates/sysconfig.sanlock
install -D -m 755 %SOURCE2 $RPM_BUILD_ROOT/etc/init.d/wdmd
ln -s /etc/init.d/wdmd $RPM_BUILD_ROOT%{_sbindir}/rcwdmd
%if %{with_systemd}
install -D -m 755 init.d/sanlock.service $RPM_BUILD_ROOT/%{_unitdir}/sanlock.service
install -D -m 755 init.d/wdmd.service $RPM_BUILD_ROOT/%{_unitdir}/wdmd.service
%endif

%clean
rm -rf $RPM_BUILD_ROOT

%pre
%if %{with_systemd}
%service_add_pre wdmd.service
%service_add_pre sanlock.service
%endif

%post
%if %{with_systemd}
%service_add_post wdmd.service sanlock.service
%endif
%fillup_only -n sanlock
%restart_on_update wdmd
%restart_on_update sanlock

%preun
%if %{with_systemd}
%service_del_preun wdmd.service sanlock.service
%endif
%stop_on_removal wdmd
%stop_on_removal sanlock

%postun
%if %{with_systemd}
%service_del_postun wdmd.service sanlock.service
%endif
%insserv_cleanup

%files
%defattr(-,root,root,-)
/etc/init.d/sanlock
%{_sbindir}/rcsanlock
%{_localstatedir}/adm/fillup-templates/sysconfig.sanlock
/etc/init.d/wdmd
%{_sbindir}/rcwdmd
%if %{with_systemd}
%{_unitdir}/sanlock.service
%{_unitdir}/wdmd.service
%endif
%{_sbindir}/sanlock
%{_sbindir}/wdmd
%{_mandir}/man8/wdmd*
%{_mandir}/man8/sanlock*

%package        -n libsanlock1
Provides:       sanlock-lib
Summary:        A shared disk lock manager library
Group:          Development/Libraries/C and C++

%description    -n libsanlock1
The %{name}-lib package contains the runtime libraries for sanlock,
a shared disk lock manager.
Hosts connected to a common SAN can use this to synchronize their
access to the shared disks.

%post -n libsanlock1 -p /sbin/ldconfig

%postun -n libsanlock1 -p /sbin/ldconfig

%files  -n libsanlock1
%defattr(-,root,root,-)
%{_libdir}/libsanlock.so.*
%{_libdir}/libsanlock_client.so.*
%{_libdir}/libwdmd.so.*

%package        -n python-%name
Provides:       sanlock-python
Summary:        Python bindings for the sanlock library
Group:          Development/Libraries/Python
Requires:       libsanlock1 = %{version}-%{release}

%description    -n python-%name
The %{name}-python package contains a module that permits applications
written in the Python programming language to use the interface
supplied by the sanlock library.

%files          -n python-%name
%defattr(-,root,root,-)
%{python_sitearch}/Sanlock-1.0-py*.egg-info
%{python_sitearch}/sanlock.so

%package        devel
Summary:        Development files for %{name}
Group:          Development/Libraries/C and C++
Requires:       libsanlock1 = %{version}-%{release}

%description    devel
The %{name}-devel package contains libraries and header files for
developing applications that use %{name}.

%files          devel
%defattr(-,root,root,-)
%{_libdir}/libwdmd.so
%{_includedir}/wdmd.h
%{_libdir}/libsanlock.so
%{_libdir}/libsanlock_client.so
%{_includedir}/sanlock.h
%{_includedir}/sanlock_rv.h
%{_includedir}/sanlock_admin.h
%{_includedir}/sanlock_resource.h
%{_includedir}/sanlock_direct.h

%changelog
openSUSE Build Service is sponsored by