File bcc.spec of Package bcc.13112

#
# spec file for package bcc
#
# Copyright (c) 2018 SUSE LINUX 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 libversion 0.5.0
%if 0%{?is_opensuse} == 1
%ifarch %ix86 x86_64
%{!?with_lua: %global with_lua 1}
%else
%{!?with_lua: %global with_lua 0}
%endif
%else
%{!?with_lua: %global with_lua 0}
%endif

Name:           bcc
Version:        0.5.0
Release:        0
Summary:        BPF Compiler Collection (BCC)
License:        Apache-2.0
Group:          Development/Tools/Other
Url:            https://github.com/iovisor/bcc
Source:         https://github.com/iovisor/bcc/archive/v%{version}.tar.gz
Patch1:         %{name}-check_int128.patch
Patch2:         %{name}-bsc1065593-llvm4-hack.patch
Patch3:         %{name}-python3.patch
Patch4:         %{name}-fix-build-for-llvm-5.0.1.patch
Patch5:         %{name}-bsc1080085-backport-bytes-strings.patch
Patch6:         %{name}-bsc1080085-fix-cachetop-py3-str.patch
Patch7:         %{name}-bsc1080085-import-readline-from-lib.patch
Patch8:         %{name}-bsc1080085-detect-slab-for-slabratetop.patch
Patch9:         %{name}-bsc1080085-fix-syscount-str.patch
Patch10:        %{name}-fix-compilation-error-with-latest-llvm.patch
Patch11:        %{name}-fix-a-compilation-error-with-latest-llvm-clang-trunk.patch
Patch12:        %{name}-compilation-error-with-latest-llvm.patch
Patch13:        %{name}-bsc1154926-update-kernel-headers.patch
ExcludeArch:    ppc s390
BuildRequires:  bison
BuildRequires:  cmake >= 2.8.7
BuildRequires:  flex
BuildRequires:  gcc-c++
BuildRequires:  libelf-devel
BuildRequires:  llvm-clang-devel >= 3.7.0
BuildRequires:  llvm-devel >= 3.7.0
%if 0%{?suse_version} > 1320
# bsc#1065593 Some static clang libraries are needed
BuildRequires:  clang-devel-static
BuildRequires:  llvm-gold
%if %{with_lua}
BuildRequires:  lua51-luajit-devel
%endif
%else
BuildRequires:  libstdc++-devel
%if %{with_lua}
BuildRequires:  luajit-devel
%endif
%endif
BuildRequires:  pkg-config
BuildRequires:  python-devel
BuildRequires:  python-setuptools
BuildRequires:  python3-devel
BuildRequires:  python3-setuptools

%description
BCC is a toolkit for creating efficient kernel tracing and manipulation
programs, and includes several useful tools and examples. It makes use
of eBPF (Extended Berkeley Packet Filters), a new feature that was first
added to Linux 3.15. Much of what BCC uses requires Linux 4.1 and above.

%package -n libbcc0
Summary:        Shared Library for BPF Compiler Collection
Group:          System/Libraries

%description -n libbcc0
Shared Library for BPF Compiler Collection (BCC)

%package -n libbpf0
Summary:        Standalone eBPF library
Group:          System/Libraries

%description -n libbpf0
A standalone library to load eBPF programs

%package devel
Summary:        BPF Compiler Collection (BCC) (devel package)
Group:          Development/Languages/C and C++
Requires:       libbcc0 = %{version}

%description devel
Shared library and pkg-config for developing BCC programs

%package -n python2-bcc
Summary:        Python2 bindings for BPF Compiler Collection
Group:          Development/Languages/Python
Requires:       kernel >= 4.1.0
Requires:       kernel-devel >= 4.1.0
Requires:       libbcc0 = %{version}
Provides:       python-bcc = %{version}
Obsoletes:      python-bcc < %{version}

%description -n python2-bcc
Python bindings for BPF Compiler Collection (BCC)

%package -n python3-bcc
Summary:        Python3 bindings for BPF Compiler Collection
Group:          Development/Languages/Python
Requires:       kernel >= 4.1.0
Requires:       kernel-devel >= 4.1.0
Requires:       libbcc0 = %{version}

%description -n python3-bcc
Python3 bindings for BPF Compiler Collection (BCC)

%if %{with_lua}
%package lua
Summary:        Lua interpreter for BPF Compiler Collection
Group:          Development/Languages/Other
Requires:       kernel >= 4.1.0
Requires:       kernel-devel >= 4.1.0
Requires:       libbcc0 = %{version}

%description lua
Lua interpreter for BPF Compiler Collection (BCC)
%endif

%package examples
Summary:        Examples for BPF Compiler Collection (BCC)
Group:          Development/Sources
Requires:       python3-bcc = %{version}
Requires:       python3-future
Recommends:     python3-pyroute2
Recommends:     python3-netaddr
Recommends:     netperf

%description examples
Python and C examples for BPF Compiler Collection (BCC)

%package tools
Summary:        Tracing tools of BPF Compiler Collection (BCC)
Group:          System/Monitoring
# ausyscall from audit is required by syscount.py
Requires:       audit
Requires:       python3-bcc = %{version}
Requires:       python3-future

%description tools
Python tracing scripts of BPF Compiler Collection (BCC)

%package docs
Summary:        BPF Compiler Collection (BCC) documentation
Group:          Documentation/Other

%description docs
The documentation of how to write programs with BPF Compiler Collection (BCC)


%prep
%setup -D -n %{name}-%{version}
%patch1 -p1
%if 0%{?suse_version} > 1320
%patch2 -p1
%endif
%patch3 -p1
%patch4 -p1
%patch5 -p1
%patch6 -p1
%patch7 -p1
%patch8 -p1
%patch9 -p1
%patch10 -p1
%patch11 -p1
%patch12 -p1
%patch13 -p1

%build
# Prevent the cpp examples from compilation and installation
# Those programs are statically linked and huge in binary size.
sed -i "/add_subdirectory(cpp)/d" examples/CMakeLists.txt

# Remove the lua scripts if bcc-lua is disabled
%if %{with_lua} == 0
sed -i "/add_subdirectory(lua)/d" examples/CMakeLists.txt
%endif

# Install bps to /usr/bin
sed -i "s,share/bcc/introspection,bin," introspection/CMakeLists.txt

export LD_LIBRARY_PATH="%{_builddir}/usr/lib64"
export PATH="%{_builddir}/usr/bin":$PATH

mkdir build
pushd build
CFLAGS=$RPM_OPT_FLAGS CXXFLAGS=$RPM_OPT_FLAGS cmake \
	-DPYTHON_CMD=python3 \
	-DREVISION_LAST=%{libversion} \
	-DREVISION=%{libversion} \
	-DCMAKE_INSTALL_PREFIX=/usr \
%if %{with_lua}
	-DLUAJIT_INCLUDE_DIR=`pkg-config --variable=includedir luajit` \
	-DLUAJIT_LIBRARY=%{_libdir}/lib`pkg-config --variable=libname luajit`.so \
%endif
%ifarch %arm || %ix86 || s390x
	-DENABLE_USDT=OFF \
%endif
	..
# Remove %{?_smp_mflags} since linking static libraries consumes lots of RAM.
# Don't add it back unless we can get rid of clang4-devel-static
make VERBOSE=1
popd

%install
pushd build
make install DESTDIR=%{buildroot}

%if 0%{?suse_version} <= 1500
# Remove bps due to the incomplete support in kernel (bsc#1085403)
rm -f %{buildroot}/%{_bindir}/bps
%endif

# For python2-bcc (should be removed in the future)
cmake -DPYTHON_CMD=python2 ..
pushd src/python/
make %{?_smp_mflags} VERBOSE=1
make install DESTDIR=%{buildroot}
popd

popd

%post -n libbcc0 -p /sbin/ldconfig

%postun -n libbcc0 -p /sbin/ldconfig

%post -n libbpf0 -p /sbin/ldconfig

%postun -n libbpf0 -p /sbin/ldconfig

%files -n bcc-devel
%{_libdir}/libbcc.so
%{_libdir}/libbpf.so
%dir %{_includedir}/bcc/
%{_includedir}/bcc/*
%{_libdir}/pkgconfig/libbcc.pc

%files -n libbcc0
%doc LICENSE.txt COPYRIGHT.txt
%{_libdir}/libbcc.so.*

%files -n libbpf0
%doc LICENSE.txt COPYRIGHT.txt
%{_libdir}/libbpf.so.*

%files -n python2-bcc
%{python_sitelib}/bcc*

%files -n python3-bcc
%{python3_sitelib}/bcc*

%if %{with_lua}
%files lua
%{_bindir}/bcc-lua
%endif

%files examples
%dir %{_datadir}/bcc/
%dir %{_datadir}/bcc/examples/
%{_datadir}/bcc/examples/*

%files tools
%dir %{_datadir}/bcc/
%dir %{_datadir}/bcc/tools/
%{_datadir}/bcc/tools/*
%dir %{_datadir}/bcc/man/
%{_datadir}/bcc/man/*
%if 0%{?suse_version} > 1500
%{_bindir}/bps
%endif

%files docs
%doc README.md FAQ.txt
%doc docs/kernel-versions.md docs/reference_guide.md
%doc docs/tutorial_bcc_python_developer.md docs/tutorial.md

%changelog
openSUSE Build Service is sponsored by