File linux-tools.spec of Package linux-tools

#
# spec file for package linux-tools
#
# Copyright (c) 2020 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 kver %(for dir in /usr/src/linux-obj/*/*/; do make %{?jobs:-j%jobs} -s -C "$dir" kernelversion 2>/dev/null; break; done |perl -ne '/(\\d+)\\.(\\d+)\\.(\\d+)?/&&printf "%%d%%02d%%03d\\n",$1,$2,$3')
%{echo: kver: %kver}

%if 0%{?kver} >= 413000
%bcond_without cpupower
%endif

%if 0%{?kver} >= 606000
%define libcpupower_sover 1
%else
%define libcpupower_sover 0
%endif

%if 0%{?kver} >= 413000
%bcond_without gpio
%endif

# newer versions provide separate libtraceevent
%if 0%{?suse_version} <= 1500
%if 0%{?kver} >= 413000
%bcond_without libtraceevent
%define libtraceevent_sover 1
%define libtraceevent_suffix .1
%endif
%endif

%if 0%{?kver} >= 504000
%ifarch %{ix86} x86_64
%bcond_without turbostat
%endif
%endif

%if 0%{?kver} >= 504000
%bcond_without iio
%endif

%bcond_without kvm_stat
%bcond_without usbip

%define version %(rpm -q --qf '%{VERSION}' kernel-source)

Name:           linux-tools
Version:        %{version}
Release:        0
Summary:        Set of tools for the Linux kernel
License:        GPL-2.0-only AND GPL-2.0-or-later AND LGPL-2.1-only
Group:          System/Base
URL:            https://www.kernel.org/
Patch0:         tmon-fix-panel-include.patch
BuildRequires:  asciidoc
BuildRequires:  autoconf
BuildRequires:  automake
BuildRequires:  binutils-devel
BuildRequires:  bison
BuildRequires:  flex
BuildRequires:  gettext-tools
BuildRequires:  glibc-devel
BuildRequires:  kernel-source
BuildRequires:  kernel-syms
BuildRequires:  libdwarf-devel
BuildRequires:  libtool
BuildRequires:  pkgconfig
BuildRequires:  sysfsutils
BuildRequires:  xmlto
BuildRequires:  pkgconfig(audit)
BuildRequires:  pkgconfig(glib-2.0)
BuildRequires:  pkgconfig(libcap)
BuildRequires:  pkgconfig(libdw)
BuildRequires:  pkgconfig(libelf)
BuildRequires:  pkgconfig(liblzma)
BuildRequires:  pkgconfig(libudev)
BuildRequires:  pkgconfig(libpci)
BuildRequires:  pkgconfig(ncurses)
BuildRequires:  pkgconfig(openssl)
BuildRequires:  pkgconfig(python3)
BuildRequires:  pkgconfig(zlib)

%description
A set of tools for the Linux kernel.

%package -n cpupower
Summary:        Tools to determine and set CPU power related settings
License:        GPL-2.0-only
Group:          System/Base
Recommends:     cpupower-lang

%description -n cpupower
This tool allows to control the Linux kernel's processor power subsystems
like CPU frequency switching (cpufreq) or CPU sleep states (cpuidle).

%package -n cpupower-lang
# FIXME: consider using %%lang_package macro
Summary:        Translations for package cpupower
License:        GPL-2.0-only
Group:          System/Localization

%description -n cpupower-lang
Provides translations for the "cpupower" package.

%package -n libcpupower%{?libcpupower_sover}
Summary:        Processor frequency related C library
License:        GPL-2.0-only
Group:          System/Libraries

%description -n libcpupower%{?libcpupower_sover}
"libcpupower" is a library which offers a unified access method for
userspace tools and programs to the cpufreq core and drivers in the
Linux kernel.

%package -n cpupower-devel
Summary:        Development files for libcpupower
License:        GPL-2.0-only
Group:          Development/Languages/C and C++
Requires:       libcpupower%{?libcpupower_sover} = %{version}
Conflicts:      cpufrequtils-devel

%description -n cpupower-devel
libcpupower is a library which offers a unified access method for
userspace tools and programs to the cpufreq core and drivers in the
Linux kernel.

This subpackage contains the headers for libcpupower.

%package -n cpupower-bench
Summary:        CPU frequency micro benchmark
License:        GPL-2.0-only
Group:          System/Benchmark

%description -n cpupower-bench
Helps testing the condition of a given kernel cpufreq governor (e.g.
ondemand, userspace, conservative) and the cpufreq HW driver (e.g.
powernow-k8, acpi-cpufreq, ...). For that purpose, it compares the
performance governor to a configured powersave module.

%package -n libtraceevent%{?libtraceevent_sover}
Summary:        Linux kernel trace event library
License:        LGPL-2.1-only
Group:          System/Libraries

%description -n libtraceevent%{?libtraceevent_sover}
libtraceevent is a trace event library for the Linux kernel.

%package -n x86_energy_perf_policy
Summary:        Read or write MSR_IA32_ENERGY_PERF_BIAS
License:        GPL-2.0-only
Group:          System/Base

%description -n x86_energy_perf_policy
The x86_energy_perf_policy tool allows administrators to define the
relative importance of performance and energy efficiency.

%package -n usbip
Summary:        A system for sharing USB devices over IP networks
License:        GPL-2.0-or-later
Group:          Hardware/Other

%description -n usbip
The USB/IP project provides a system for  general USB device sharing
over IP networks. To share USB devices between computers with their
full functionality, USB/IP encapsulates "USB I/O messages" into IP
packets and transmits them between computers. Original USB device
drivers and applications can be also used for remote USB devices
without any modification.

%package -n libusbip0
Summary:        A system for sharing USB devices over IP networks
License:        GPL-2.0-or-later
Group:          System/Libraries

%description -n libusbip0
The USB/IP project provides a system for  general USB device sharing
over IP networks. To share USB devices between computers with their
full functionality, USB/IP encapsulates "USB I/O messages" into IP
packets and transmits them between computers. Original USB device
drivers and applications can be also used for remote USB devices
without any modification.

%package -n usbip-devel
Summary:        Development files for usbip
License:        GPL-2.0-or-later
Group:          Development/Languages/C and C++
Requires:       glibc-devel
Requires:       libusbip0 = %{version}

%description -n usbip-devel
This package contains development files for USB/IP.

%package -n tmon
Summary:        Monitoring and Testing Tool for the Linux kernel thermal subsystem
License:        GPL-2.0-or-later
Group:          Development/Tools/Debuggers

%description -n tmon
TMON is conceived as a tool to help visualize, tune, and test the
complex thermal subsystem.

%package -n cgroup-tools
Summary:        Set of simple cgroup tools
License:        GPL-2.0-only
Group:          System/Base
Requires:       /usr/bin/fio
Requires:       /usr/bin/drgn

%description -n cgroup-tools
This package contains a set of simplle cgroup python and drgn tools.

%package -n turbostat
Summary:        Report processor frequency and idle statistics
License:        GPL-2.0-only
Group:          System/Base

%description -n turbostat
Turbostat reports processor topology, frequency, idle power-state
statistics, temperature and power on modern x86 processors. Either a
command is forked and statistics are printed upon its completion, or
statistics are printed periodically.

Turbostat must be run as root, and minimally requires that the
processor supports an "invariant" TSC, plus the APERF and MPERF MSRs.
Additional information is reported depending on hardware counter
support.

%package -n iio-tools
Summary:        Industial I/O tools
License:        GPL-2.0-only
Group:          Hardware/Other

%description -n iio-tools
This package contains lsiio and other tools for the industrial I/O
framework.

%package -n kvm_stat
Summary:        Monitoring Tool for KVM guests
License:        GPL-2.0-only
Group:          System/Monitoring
Conflicts:      qemu-kvm < 2.6.90

%description -n kvm_stat
This package provides a userspace tool "kvm_stat", which displays KVM vm exit
information as a means of monitoring vm behavior. The data is taken from the
KVM debugfs files or the vm tracepoints and outputs them as a curses ui or
simple text.

%package -n gpio-tools
Summary:        GPIO tools
License:        GPL-2.0-only
Group:          Hardware/Other

%description -n gpio-tools
This package contains lsgpio and other tools for GPIO management.
Those tools use the new chardev interface instead of the deprecated sysfs interface.

%prep
# copy necessary files from kernel-source since we need to modify them
(cd %{_prefix}/src/linux; tar -c COPYING CREDITS README tools include scripts Kbuild Makefile arch/*/{include,lib,Makefile} lib) | tar -x
%patch -P0 -p1
sed -ri '1 s|%{_bindir}/env\ (.*)|%{_bindir}/\1|' tools/kvm/kvm_stat/kvm_stat

%build
%if %{with libtraceevent}
%make_build EXTRA_CFLAGS="%{optflags}" -C tools/lib/traceevent
%endif

%if %{with cpupower}
CONF="PACKAGE_BUGREPORT=https://bugs.opensuse.org mandir=%{_mandir} libdir=%{_libdir} CPUFRQ_BENCH=true STRIP=true VERSION=%{version}"
%make_build EXTRA_CFLAGS="%{optflags}" -C tools/power/cpupower $CONF
%endif

%if %{with turbostat}
%make_build EXTRA_CFLAGS="%{optflags}" -C tools/power/x86/turbostat
%endif

%ifarch %{ix86} x86_64
%make_build EXTRA_CFLAGS="%{optflags}" -C tools/power/x86/x86_energy_perf_policy
%endif

%make_build EXTRA_CFLAGS="%{optflags}" -C tools/thermal/tmon
%if %{with iio}
%make_build EXTRA_CFLAGS="%{optflags}" -C tools/iio
%endif
%if %{with kvm_stat}
%make_build EXTRA_CFLAGS="%{optflags}" -C tools/kvm/kvm_stat
%endif
%if %{with gpio}
%make_build EXTRA_CFLAGS="%{optflags}" -C tools/gpio
%endif
pushd tools/usb/usbip
NOCONFIGURE=1 ./autogen.sh
%configure --disable-static
%make_build
popd

%install

%if %{with cpupower}
make -C tools/power/cpupower DESTDIR=%{buildroot} libdir=%{_libdir} mandir=%{_mandir} install
%find_lang cpupower
# copy to examples doc dir to avoid complains from the build
# system about an executable in the doc dir.
mkdir -p %{buildroot}%{_docdir}/cpupower/examples
mv %{buildroot}%{_docdir}/cpupower/cpufreq-bench_script.sh %{buildroot}%{_docdir}/cpupower/examples/cpufreq-bench_script.sh
%endif

make -C tools/thermal/tmon INSTALL_ROOT=%{buildroot} install

%if %{with turbostat}
make -C tools/power/x86/turbostat DESTDIR=%{buildroot} install
# Fix spurious-executable-perm
chmod 0644 %{buildroot}%{_mandir}/man8/turbostat*
%endif

%ifarch %{ix86} x86_64
install -Dm 755 tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy \
        %{buildroot}%{_bindir}/x86_energy_perf_policy
install -Dm 644 tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.8 \
        %{buildroot}%{_mandir}/man8/x86_energy_perf_policy.8
%endif

install -Dm755 tools/cgroup/iocost_coef_gen.py %{buildroot}%{_bindir}/iocost_coef_gen.py
install -Dm755 tools/cgroup/iocost_monitor.py %{buildroot}%{_bindir}/iocost_monitor.py
install -Dm755 tools/cgroup/memcg_shrinker.py %{buildroot}%{_bindir}/memcg_shrinker.py
install -Dm755 tools/cgroup/memcg_slabinfo.py %{buildroot}%{_bindir}/memcg_slabinfo.py

%if %{with iio}
make -C tools/iio DESTDIR=%{buildroot} INSTALL_ROOT=%{buildroot} install
%endif

%if %{with kvm_stat}
make -C tools INSTALL_ROOT=%{buildroot} kvm_stat_install
%endif

%if %{with gpio}
make -C tools DESTDIR=%{buildroot} gpio_install
%endif

%if %{with libtraceevent}
# Install libtraceevent.so only as plugins provided by perf
install -Dm0644 tools/lib/traceevent/libtraceevent.so %{buildroot}%{_libdir}/libtraceevent.so%{?libtraceevent_suffix}
%endif

%if %{with usbip}
make -C tools/usb/usbip DESTDIR=%{buildroot} install
find %{buildroot}%{_libdir} -type f -name "*.a" -delete -print
find %{buildroot} -type f -name "*.la" -delete -print
%endif

%post -n libcpupower%{?libcpupower_sover} -p /sbin/ldconfig
%post -n libtraceevent%{?libtraceevent_sover} -p /sbin/ldconfig
%post -n libusbip0 -p /sbin/ldconfig
%postun -n libcpupower%{?libcpupower_sover} -p /sbin/ldconfig
%postun -n libtraceevent%{?libtraceevent_sover} -p /sbin/ldconfig
%postun -n libusbip0 -p /sbin/ldconfig

%if %{with libtraceevent}
%files -n libtraceevent%{?libtraceevent_sover}
%{_libdir}/libtraceevent.so%{?libtraceevent_suffix}*
%endif

%if %{with turbostat}
%files -n turbostat
%{_mandir}/man8/turbostat*
%{_bindir}/turbostat
%endif

%ifarch %{ix86} x86_64
%files -n x86_energy_perf_policy
%{_bindir}/x86_energy_perf_policy
%{_mandir}/man8/x86_energy_perf_policy.8%{?ext_man}
%endif

%if %{with cpupower}
%files -n cpupower
%{_bindir}/cpupower
%{_mandir}/man1/cpupower*
%{_datadir}/bash-completion/completions/cpupower

%files -n cpupower-lang -f cpupower.lang

%files -n cpupower-bench
%dir %{_docdir}/cpupower
%dir %{_docdir}/cpupower/examples
%{_docdir}/cpupower/examples/cpufreq-bench_script.sh
%{_docdir}/cpupower/README-BENCH
%config %{_sysconfdir}/cpufreq-bench.conf
%{_sbindir}/cpufreq-bench
%{_bindir}/cpufreq-bench_plot.sh

%files -n libcpupower%{?libcpupower_sover}
%{_libdir}/libcpupower.so*.%{?libcpupower_sover}*

%files -n cpupower-devel
%{_includedir}/cpu*.h
%if 0%{?kver} >= 602000
%{_includedir}/powercap.h
%endif
%{_libdir}/libcpu*.so
%endif

%files -n cgroup-tools
%{_bindir}/iocost_coef_gen.py
%{_bindir}/iocost_monitor.py
%{_bindir}/memcg_shrinker.py
%{_bindir}/memcg_slabinfo.py

%files -n tmon
%{_bindir}/tmon

%if %{with iio}
%files -n iio-tools
%{_bindir}/iio_event_monitor
%{_bindir}/iio_generic_buffer
%{_bindir}/lsiio
%endif

%if %{with kvm_stat}
%files -n kvm_stat
%{_bindir}/kvm_stat
%{_mandir}/man1/kvm_stat*
%endif

%if %{with gpio}
%files -n gpio-tools
%{_bindir}/gpio-*
%{_bindir}/lsgpio
%endif

%if %{with usbip}
%files -n usbip-devel
%dir %{_includedir}/usbip
%{_includedir}/usbip/*.h
%{_libdir}/libusbip.so

%files -n usbip
%{_sbindir}/usbip
%{_sbindir}/usbipd
%{_mandir}/man8/usbip.8%{?ext_man}
%{_mandir}/man8/usbipd.8%{?ext_man}

%files -n libusbip0
%{_libdir}/libusbip.so.0*
%endif

%changelog
openSUSE Build Service is sponsored by