Summary:        libknet
Name:           knet
Version:        1.0.0
Release:        4
License:        MulanPSL-2.0
Group:          Development/Libraries
Vendor:         Huawei Technologies Co., Ltd.
BuildRequires:  python3 gcc gcc-c++ make numactl-devel numactl libpcap-devel libcap-devel cmake >= 3.5
BuildRequires:  dpdk-devel >= 21.11-5
BuildRequires:  dpdk >= 21.11-5
BuildRequires:  libboundscheck cjson-devel cjson
Source:         %{name}-%{version}.tar.gz

Patch1:         0001-knet-1.0.0-add-support-for-loongarch64.patch

%define project %{name}-%{version}
%define projectdir %(echo $PWD)/rpmbuild/BUILD/%{project}
%define knetsysdir /etc
%define debug_package %{nil}
%define _debugsource_template %{nil}
%define _debuginfo_template %{nil}

%description
A multi-protocol framework, enables NIC acceleration and provides seamless application migration.

%prep
%autosetup -p1


%build
python3 build.py rpm

%install
install -d %{buildroot}"/usr/lib64"
install -d %{buildroot}"/usr/bin"
install -d %{buildroot}"/usr/include"
install -d %{buildroot}"/usr/include/knet"
install -d %buildroot%{knetsysdir}/knet/
install -d %buildroot%{knetsysdir}/knet/run
install -d %buildroot%{knetsysdir}/rsyslog.d/
install -d %buildroot%{knetsysdir}/logrotate.d/

cp -ar %{projectdir}/build/rpmbuild/BUILD/usr/lib64/libknet_core.so* %{buildroot}"/usr/lib64"
cp -ar %{projectdir}/build/rpmbuild/BUILD/usr/lib64/libknet_frame.so* %{buildroot}"/usr/lib64"
cp -ar %{projectdir}/build/rpmbuild/BUILD/usr/lib64/libdpstack.so* %{buildroot}"/usr/lib64"
cp -rf %{projectdir}/build/rpmbuild/BUILD/usr/bin/knet_mp_daemon %{buildroot}"/usr/bin"
cp -rf %{projectdir}/build/rpmbuild/BUILD/usr/include/knet/knet_socket_api.h %{buildroot}"/usr/include/knet"
cp -rf %{projectdir}/build/rpmbuild/SOURCES/knet_comm.conf %buildroot%{knetsysdir}/knet/
cp -rf %{projectdir}/build/rpmbuild/SOURCES/knet_rsyslog.conf %buildroot%{knetsysdir}/rsyslog.d/
cp -rf %{projectdir}/build/rpmbuild/SOURCES/logrotate/knet %buildroot%{knetsysdir}/logrotate.d/

%pre
if [ -e "/etc/knet/knet_comm.conf" ]; then
    cp -pf /etc/knet/knet_comm.conf /etc/knet/knet_comm.conf.tmp
fi

%post
if [ ! -f /.dockerenv ]; then
    systemctl restart rsyslog
fi

if [ -e "/etc/knet/knet_comm.conf.tmp" ]; then
    diff -q /etc/knet/knet_comm.conf /etc/knet/knet_comm.conf.tmp >/dev/null >&1
    if [ $? -eq 0 ]; then
        rm -f /etc/knet/knet_comm.conf.tmp
    else
        mv /etc/knet/knet_comm.conf.tmp /etc/knet/knet_comm.conf.bak
    fi
fi

%postun
if [ ! -f /.dockerenv ] && [ "$1" = "0" ]; then
    systemctl stop rsyslog
fi

if [[ "$1" = "0" && -e "/etc/knet/knet_comm.conf.bak" ]]; then
    rm -rf /etc/knet/knet_comm.conf.bak
fi

%clean

%files
%defattr(-,root,root,-)

%attr(550, root, root) /usr/lib64/libknet_core.so.%{version}
/usr/lib64/libknet_core.so.1
/usr/lib64/libknet_core.so
%attr(550, root, root) /usr/lib64/libknet_frame.so.%{version}
/usr/lib64/libknet_frame.so.1
/usr/lib64/libknet_frame.so
%attr(550, root, root) /usr/lib64/libdpstack.so.%{version}
/usr/lib64/libdpstack.so.1
/usr/lib64/libdpstack.so
%attr(550, root, root) /usr/bin/knet_mp_daemon
%attr(440, root, root) /usr/include/knet/knet_socket_api.h
%attr(600, root, root) %{knetsysdir}/knet/knet_comm.conf
%attr(640, root, root) %{knetsysdir}/rsyslog.d/knet_rsyslog.conf
%attr(640, root, root) %{knetsysdir}/logrotate.d/knet
%dir %{knetsysdir}/knet/run

%changelog
* Wed Oct 28 2026 doupengda <doupengda@loongson.cn> - 1.0.0-4
- add support for loongarch64

* Tue May 19 2026 Build System <tangzhengliang1@huawei.com> - 1.0.0-3
- [fix] newest os output syslog without ident of openlog parameter, prefix libknet to solve it
- and based on "more accurate prefix to match" commit of openEuler/knet

* Tue Feb 10 2026 Build System <tangzhengliang1@huawei.com> - 1.0.0-2
- resolve cjson, dpdk, libboundscheck dependency automatically.
- and based on tag knet-26.0.rc1-0331 adapting dpdk23

* Wed Jan 14 2026 Build System <tangzhengliang1@huawei.com> - 1.0.0-1
- Initial package build
- Provide libknet_core.so, libknet_frame.so, libdpstack.so
- Include knet_mp_daemon binary
- Add configuration files for knet communication, rsyslog, and logrotate