File geopm-service.spec of Package geopm-service

#  Copyright (c) 2015 - 2023, Intel Corporation
#  SPDX-License-Identifier: BSD-3-Clause
#

# Packages: geopm-service, geopm-service-devel, libgeopmd2, python3-geopmdpy
# This spec file supports three options for level-zero support:
#
# 1. default:
#    No level-zero support.
#
# 2. rpmbuild --define 'enable_level_zero 1' ...
#    Enable level-zero with packages installed into standard
#    locations: libdir and includedir.
#
# 3. rpmbuild --define 'with_level_zero <LEVEL_ZERO_PREFIX>' ...
#    Enable level-zero with packages installed into a
#    non-standard prefix.

Summary: Global Extensible Open Power Manager Service
Name: geopm-service
Version: 3.0.1
Release: 1
License: BSD-3-Clause
%if 0%{?rhel_version} || 0%{?centos_ver} || 0%{?rocky_ver}
# Deprecated for RHEL and CentOS
Group: System Environment/Daemons
%else
Group: System/Daemons
%endif
URL: https://geopm.github.io
Source0: geopm-service-%{version}.tar.gz
BuildRoot: %{_tmppath}/geopm-service-%{version}-%{release}-root
Prefix: %{_prefix}
BuildRequires: gcc-c++
BuildRequires: unzip
BuildRequires: libtool
BuildRequires: libcap-devel
BuildRequires: systemd-devel >= 221
BuildRequires: python3
BuildRequires: python3-devel
BuildRequires: python3-setuptools
%if 0%{?suse_version}
BuildRequires: bash-completion-devel
%else
BuildRequires: bash-completion
%endif
%if %{defined enable_level_zero}
BuildRequires: level-zero
BuildRequires: level-zero-devel
Requires: level-zero >= 1.8.1
%endif
%if 0%{?suse_version}
BuildRequires: fdupes
%endif
BuildRequires: systemd-rpm-macros
BuildRequires: python-rpm-macros

%if %{defined suse_version}
%define docdir %{_defaultdocdir}/geopm-service
%else
%define docdir %{_defaultdocdir}/geopm-service-%{version}
%endif

%define compdir %(pkg-config --variable=completionsdir bash-completion)
%if "x%{?compdir}" == "x"
%define compdir "%{_sysconfdir}/bash_completion.d"
%endif

%define python_bin %{__python3}

%{!?python3_pkgversion:%global python3_pkgversion 3}

%define python_major_version 3

Requires: python%{python3_pkgversion}-geopmdpy = %{version}
Requires: libgeopmd2 = %{version}
ExclusiveArch: x86_64

%description

The GEOPM Service provides a user-level interface to read telemetry
and configure settings of heterogeneous hardware platforms. Linux
system administrators may manage permissions for user access to
telemetry and configuration at a fine granularity.  This package
includes the geopm systemd service unit that provides a DBus interface
io.github.geopm.  Additionally the libgeopmd.so shared object library
is installed with this package.


%package devel

Summary: Global Extensible Open Power Manager Service - development
%if 0%{?rhel_version} || 0%{?centos_ver} || 0%{?rocky_ver}
# Deprecated for RHEL and CentOS
Group: Development/Libraries
%else
Group: Development/Libraries/C and C++
%endif
Requires: libgeopmd2 = %{version}

%description devel

Development package for the GEOPM Service.  This provides the
programming interface to libgeopmd.so.  The package includes the C and
C++ header files, maunuals for these interfaces and the unversioned
libgeopmd.so shared object symbolic link.

%package -n libgeopmd2

Summary: Provides libgeopmd shared object library
%if 0%{?rhel_version} || 0%{?centos_ver} || 0%{?rocky_ver}
# Deprecated for RHEL and CentOS
Group: System Environment/Libraries
%else
Group: System/Libraries
%endif

# Lets GEOPM batch its IO operations to reduce syscall overhead in IOGroups
# with a lot of reads/writes per GEOPM batch operation.
%if %{defined disable_io_uring} || 0%{?centos_ver} == 8
%define io_uring_option --disable-io-uring
%else
BuildRequires: liburing-devel
%endif

%description -n libgeopmd2

Library supporting the GEOPM Service.  This provides the libgeopmd
library which provides C and C++ interfaces.

%package -n python%{python3_pkgversion}-geopmdpy

Summary: The geopmdpy Python package for the GEOPM Service
%if 0%{?rhel_version} || 0%{?centos_ver} || 0%{?rocky_ver}
# Deprecated for RHEL and CentOS
Group: System Environment/Libraries
%else
Group: Development/Libraries/Python
%endif

%if %{defined suse_version}
Requires: python3-gobject
BuildRequires: gobject-introspection
%else
Requires: python3-gobject-base
%endif
Requires: python3-dasbus >= 1.6
Requires: python3-jsonschema
Requires: python3-psutil
Requires: python3-cffi
Requires: libgeopmd2 = %{version}

%{?python_provide:%python_provide python%{python3_pkgversion}-geopmdpy}

%description -n python%{python3_pkgversion}-geopmdpy

Python %{python_major_version} package for GEOPM service.  Provides
the implementation for the geopmd service daemon and interfaces for
configuring the service.

# Steps for all packages
%global debug_package %{nil}
%prep
%setup

%build

%if %{defined with_level_zero}
# Disable libze_loader as an explicit dependency for installing the RPM
%global __requires_exclude ^(libze_loader[.]so.*)$
%define level_zero_option --enable-levelzero --with-levelzero=%{with_level_zero}
%else
%if %{defined enable_level_zero}
%define level_zero_option --enable-levelzero
%endif
%endif

./autogen.sh
unset CFLAGS CXXFLAGS
CC=gcc CXX=g++ \
./configure --prefix=%{_prefix} --libdir=%{_libdir} --libexecdir=%{_libexecdir} \
            --includedir=%{_includedir} --sbindir=%{_sbindir} \
            --mandir=%{_mandir} --docdir=%{docdir} \
            --with-python=%{python_bin} \
            --with-bash-completion-dir=%{compdir} \
            %{?level_zero_option} \
            %{?io_uring_option} \
            || ( cat config.log && false )

CFLAGS= CXXFLAGS= CC=gcc CXX=g++ \
%{__make} %{?_smp_mflags}

%install
%{__make} DESTDIR=%{buildroot} install
rm -f $(find %{buildroot}/%{_libdir} -name '*.a'; \
        find %{buildroot}/%{_libdir} -name '*.la')

install -Dp -m644 geopm.service %{buildroot}%{_unitdir}/geopm.service
install -Dp -m644 io.github.geopm.conf %{buildroot}%{_datadir}/dbus-1/system.d/io.github.geopm.conf
install -Dp -m644 io.github.geopm.xml %{buildroot}%{_datadir}/dbus-1/interfaces/io.github.geopm.xml
mkdir -p %{buildroot}%{_sysconfdir}/geopm
mkdir -p %{buildroot}%{_sbindir}
ln -s -r %{buildroot}%{_sbindir}/service %{buildroot}%{_sbindir}/rcgeopm
%if 0%{?suse_version}
%python_expand %fdupes %{buildroot}%{python3_sitelib}
%endif

%clean

%if 0%{?suse_version}
%pre -n geopm-service
%service_add_pre geopm.service
%endif

%post -n geopm-service
%if 0%{?rhel_version} || 0%{?centos_ver} || 0%{?rocky_ver}
%systemd_post geopm.service
%else
%service_add_post geopm.service
%endif

%preun -n geopm-service
%if 0%{?rhel_version} || 0%{?centos_ver} || 0%{?rocky_ver}
%systemd_preun geopm.service
%else
%service_del_preun geopm.service
%endif

%postun -n geopm-service
%if 0%{?rhel_version} || 0%{?centos_ver} || 0%{?rocky_ver}
%systemd_postun_with_restart geopm.service
%else
%service_del_postun geopm.service
%endif

# Installed files

%files
%defattr(-,root,root,-)
%{_sbindir}/rcgeopm
%{_bindir}/geopmread
%{_bindir}/geopmwrite
%{compdir}
%dir %{_datadir}/dbus-1
%dir %{_datadir}/dbus-1/system.d
%{_datadir}/dbus-1/system.d/io.github.geopm.conf
%dir %{_datadir}/dbus-1/interfaces
%{_datadir}/dbus-1/interfaces/io.github.geopm.xml
%{_unitdir}/geopm.service
%dir %{docdir}
%doc %{docdir}/COPYING
%doc %{docdir}/COPYING-TPP
%doc %{docdir}/README.rst
%doc %{docdir}/VERSION
%doc %{_mandir}/man1/geopmread.1.gz
%doc %{_mandir}/man1/geopmwrite.1.gz
%doc %{_mandir}/man7/geopm.7.gz
%doc %{_mandir}/man7/geopm_pio.7.gz
%doc %{_mandir}/man7/geopm_pio_cnl.7.gz
%doc %{_mandir}/man7/geopm_pio_const_config.7.gz
%doc %{_mandir}/man7/geopm_pio_cpuinfo.7.gz
%doc %{_mandir}/man7/geopm_pio_dcgm.7.gz
%doc %{_mandir}/man7/geopm_pio_levelzero.7.gz
%doc %{_mandir}/man7/geopm_pio_msr.7.gz
%doc %{_mandir}/man7/geopm_pio_nvml.7.gz
%doc %{_mandir}/man7/geopm_pio_profile.7.gz
%doc %{_mandir}/man7/geopm_pio_service.7.gz
%doc %{_mandir}/man7/geopm_pio_sst.7.gz
%doc %{_mandir}/man7/geopm_pio_time.7.gz
%doc %{_mandir}/man7/geopm_report.7.gz

%files -n libgeopmd2
%defattr(-,root,root,-)
%{_libdir}/libgeopmd.so.2.0.0
%{_libdir}/libgeopmd.so.2
%dir %{_libdir}/geopm

%files -n python%{python3_pkgversion}-geopmdpy
%defattr(-,root,root,-)
%{expand:%{python%{python_major_version}_sitelib}}/*
%doc %{_mandir}/man1/geopmaccess.1.gz
%doc %{_mandir}/man1/geopmsession.1.gz
%doc %{_mandir}/man7/geopmdpy.7.gz
%{_bindir}/geopmd
%{_bindir}/geopmaccess
%{_bindir}/geopmsession

%files devel
%defattr(-,root,root,-)
%dir %{_includedir}/geopm
%{_includedir}/geopm/Agg.hpp
%{_includedir}/geopm/CircularBuffer.hpp
%{_includedir}/geopm/Exception.hpp
%{_includedir}/geopm/Helper.hpp
%{_includedir}/geopm/IOGroup.hpp
%{_includedir}/geopm/json11.hpp
%{_includedir}/geopm/MSRIOGroup.hpp
%{_includedir}/geopm/PlatformIO.hpp
%{_includedir}/geopm/PlatformTopo.hpp
%{_includedir}/geopm/PluginFactory.hpp
%{_includedir}/geopm/ServiceProxy.hpp
%{_includedir}/geopm/SharedMemory.hpp
%{_includedir}/geopm/SharedMemoryScopedLock.hpp
%{_includedir}/geopm_debug.hpp
%{_includedir}/geopm_error.h
%{_includedir}/geopm_field.h
%{_includedir}/geopm_hash.h
%{_includedir}/geopm_hint.h
%{_includedir}/geopm_pio.h
%{_includedir}/geopm_plugin.hpp
%{_includedir}/geopm_sched.h
%{_includedir}/geopm_shmem.h
%{_includedir}/geopm_time.h
%{_includedir}/geopm_topo.h
%{_includedir}/geopm_version.h
%{_libdir}/libgeopmd.so
%doc %{_mandir}/man3/geopm::Agg.3.gz
%doc %{_mandir}/man3/geopm::CircularBuffer.3.gz
%doc %{_mandir}/man3/geopm::CNLIOGroup.3.gz
%doc %{_mandir}/man3/geopm::CpuinfoIOGroup.3.gz
%doc %{_mandir}/man3/geopm::Exception.3.gz
%doc %{_mandir}/man3/geopm::Helper.3.gz
%doc %{_mandir}/man3/geopm::IOGroup.3.gz
%doc %{_mandir}/man3/geopm::MSRIO.3.gz
%doc %{_mandir}/man3/geopm::MSRIOGroup.3.gz
%doc %{_mandir}/man3/geopm::PlatformIO.3.gz
%doc %{_mandir}/man3/geopm::PlatformTopo.3.gz
%doc %{_mandir}/man3/geopm::PluginFactory.3.gz
%doc %{_mandir}/man3/geopm::SampleAggregator.3.gz
%doc %{_mandir}/man3/geopm::SharedMemory.3.gz
%doc %{_mandir}/man3/geopm::TimeIOGroup.3.gz
%doc %{_mandir}/man3/geopm_error.3.gz
%doc %{_mandir}/man3/geopm_field.3.gz
%doc %{_mandir}/man3/geopm_hash.3.gz
%doc %{_mandir}/man3/geopm_pio.3.gz
%doc %{_mandir}/man3/geopm_sched.3.gz
%doc %{_mandir}/man3/geopm_time.3.gz
%doc %{_mandir}/man3/geopm_topo.3.gz
%doc %{_mandir}/man3/geopm_version.3.gz
openSUSE Build Service is sponsored by