%bcond_with ndp
%bcond_with pcap
%bcond_without raw
%bcond_with nemea
%bcond_with unwind
%bcond_with is_el7

%if %{with ndp}
%global compile_ndp yes
%else
%global compile_ndp no
%endif

%if %{with raw}
%global compile_raw yes
%else
%global compile_raw no
%endif

%if %{with nemea}
%global compile_nemea yes
%else
%global compile_nemea yes
%endif

%if %{with unwind}
%global compile_unwind yes
%else
%global compile_unwind yes
%endif

%if "%{dist}" == ".el7"
%global is_el7 yes
%else
%global is_el7 no
%endif

# Hotfix to allow RPM build on fedora36+
# There is a problem in configure autodetection when
# LDFLAGS=-specs=/usr/lib/rpm/redhat/redhat-hardened-ld
%undefine _auto_set_build_flags

Name: ipfixprobe
Version: 4.14.0
Release: 1
URL: http://nemea.liberouter.org/
Source: https://www.liberouter.org/repo/SOURCES/%{name}-%{version}-%{release}.tar.gz
Group: Liberouter
License: BSD
Vendor: CESNET, z.s.p.o.
Packager: Pavel Siska <siska@cesnet.cz>
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}
Summary: IPFIX flow exporter with various extending IPFIX elements exported by plugins.
Requires: libatomic fuse3 telemetry lz4
BuildRequires: gcc gcc-c++ make doxygen pkgconfig libatomic telemetry lz4-devel
Provides: ipfixprobe

%if %{with ndp}
Requires: netcope-common
BuildRequires: netcope-common
%else
Requires: libpcap
BuildRequires: libpcap-devel
%endif

%if %{with nemea} || "yes" == "yes"
Requires: libtrap
BuildRequires: libtrap-devel
BuildRequires: unirec
%endif

%if %{with unwind} || "yes" == "yes"
Requires: libunwind
BuildRequires: libunwind-devel
%endif

%if "%{is_el7}" == "yes"
Requires: openssl11
BuildRequires: openssl11-devel
%else
Requires: openssl
BuildRequires: openssl-devel
%endif

%description
This package contains nemea flow exporter.

%package input-pcap
Group: Liberouter
License: BSD
Vendor: CESNET, z.s.p.o.
Packager: Pavel Siska <siska@cesnet.cz>
Summary: Libpcap input plugin for ipfixprobe IPFIX flow exporter.
Requires: libpcap telemetry
BuildRequires: libpcap-devel telemetry
Provides: ipfixprobe-input-pcap

%description input-pcap
Input plugin to monitor network traffic on network interface using libpcap or to process packets stored in PCAP files.

%prep
%setup

%build
./configure -q --enable-silent-rules --prefix=%{_prefix} --libdir=%{_libdir} --bindir=%{_bindir} --sysconfdir=%{_sysconfdir} --docdir=%{_docdir} --mandir=%{_mandir} --datadir=%{_datadir} --with-ndp=%{compile_ndp} --with-raw=%{compile_raw} --with-pcap=%{compile_pcap} --with-nemea=%{compile_nemea} --with-unwind=%{compile_unwind} --enable-legacy-ssl=%{is_el7};
make clean
make -j5

%install
make -j5 DESTDIR=$RPM_BUILD_ROOT install

%post
test -x %{_bindir}/ipfixprobe && setcap "CAP_NET_RAW+eip" %{_bindir}/ipfixprobe || true
ldconfig

%if %{with ndp}
%package devel
Summary: Devel package of ipfixprobe containing header files of libndpRI interface and devel files.
Group: Liberouter
Requires: ipfixprobe = %{version}-%{release}
Provides: ipfixprobe-devel

%description devel
This package contains header file for liburfilter.

%endif

%files
%attr(0755, root, nemead) %{_bindir}/ipfixprobe
%attr(0755, root, nemead) %{_bindir}/ipfixprobe_stats
%attr(0755, root, nemead) %{_bindir}/ipfixprobed
%{_sysconfdir}/bash_completion.d/ipfixprobe.bash
%{_sysconfdir}/ipfixprobe/link0.conf.example
%{_sysconfdir}/ipfixprobe/dpdk_direct.conf.example
%{_sysconfdir}/ipfixprobe/dpdk_mring.conf.example
%{_docdir}/ipfixprobe/README.md
%if %{with ndp}
%{_libdir}/libndpRI.so.0
%{_libdir}/libndpRI.so.0.0.0
%endif
/usr/lib/systemd/system

%if %{with ndp}
%files devel
%{_includedir}/ndpheader.h
%{_includedir}/ndpreader.h
%{_includedir}/ndpreader.hpp
%{_libdir}/libndpRI.a
%{_libdir}/libndpRI.la
%{_libdir}/libndpRI.so
%endif

%files input-pcap
%{_libdir}/ipfixprobe/input-pcap.so
%{_libdir}/ipfixprobe/input-pcap.la