%global libqat_soversion  4
%global libusdm_soversion 0

Name:             qatlib
Version:          24.02.0
Release:          1
Summary:          Intel QuickAssist user space library
# The entire source code is released under BSD.
# For a breakdown of inbound licenses see the INSTALL file.
License:          BSD and GPLv2
URL:              https://github.com/intel/%{name}
Source0:          %{version}/%{name}-%{version}.tar.gz
BuildRequires:    gcc make autoconf automake libtool
BuildRequires:    systemd
BuildRequires:    openssl-devel zlib-devel systemd-devel
BuildRequires:    yasm nasm
Requires(pre):    shadow-utils
Recommends:       qatlib-service

ExclusiveArch:  x86_64

%description
Intel(R) QuickAssist Technology (Intel(R) QAT) provides hardware acceleration for offloading security, authentication and compression services from the CPU, thus significantly increasing the performance and efficiency of standard platform solutions.

Its services include symmetric encryption and authentication, asymmetric encryption, digital signatures, RSA, DH and ECC, and lossless data compression.

This package provides user space libraries that allow access to Intel(R) QuickAssist devices and expose the Intel(R) QuickAssist APIs and sample codes.

%package       devel
Summary:       Headers and libraries to build applications that use qatlib
Requires:      %{name} = %{version}-%{release}

%description   devel
This package contains headers and libraries required to build applications
that use the Intel QuickAssist APIs.

%package       tests
Summary:       Sample applications that use qatlib
Requires:      %{name} = %{version}-%{release}

%description   tests
This package contains sample applications that use the Intel QuickAssists APIs.

%package       service
Summary:       A daemon for qatlib resources management
Requires:      %{name} = %{version}-%{release}
%{?systemd_requires}

%description   service
This package contains a daemon that manages QAT resources for the Intel
QuickAssist Technology user space library (qatlib).

%package doc
Summary:        Documentation files for %{name}
Requires:       %{name} = %{version}-%{release}
BuildArch:      noarch

%description    doc
The %{name}-doc package contains documentation files for %{name}.

%prep
%autosetup -n %{name}-%{version} -p1

%build
autoreconf -vif
%configure
%make_build

%install
%make_install
make DESTDIR=%{buildroot} samples-install

find %{buildroot}%{_libdir} -iname '*.a' -exec rm -rf {} \;
find %{buildroot}%{_libdir} -iname '*.la' -exec rm -rf {} \;

%pre
getent group qat >/dev/null || groupadd -r qat
exit 0

%post          service
%systemd_post qat.service

%preun         service
%systemd_preun qat.service

%postun        service
%systemd_postun_with_restart qat.service

%files
%license LICENSE*
%{_libdir}/libqat.so.%{libqat_soversion}*
%{_libdir}/libusdm.so.%{libusdm_soversion}*

%files         devel
%{_libdir}/libqat.so
%{_libdir}/libusdm.so
%{_includedir}/qat
%{_libdir}/pkgconfig/*.pc

%files         tests
%doc quickassist/lookaside/access_layer/src/sample_code/README.txt
%attr(0754,-,qat) %{_bindir}/cpa_sample_code
%attr(0754,-,qat) %{_bindir}/dc_dp_sample
%attr(0754,-,qat) %{_bindir}/dc_stateless_sample
%attr(0754,-,qat) %{_bindir}/dc_stateless_multi_op_sample
%attr(0754,-,qat) %{_bindir}/algchaining_sample
%attr(0754,-,qat) %{_bindir}/ccm_sample
%attr(0754,-,qat) %{_bindir}/chaining_sample
%attr(0754,-,qat) %{_bindir}/cipher_sample
%attr(0754,-,qat) %{_bindir}/gcm_sample
%attr(0754,-,qat) %{_bindir}/hash_file_sample
%attr(0754,-,qat) %{_bindir}/hash_sample
%attr(0754,-,qat) %{_bindir}/ipsec_sample
%attr(0754,-,qat) %{_bindir}/ssl_sample
%attr(0754,-,qat) %{_bindir}/sym_dp_sample
%attr(0754,-,qat) %{_bindir}/dh_sample
%attr(0754,-,qat) %{_bindir}/eddsa_sample
%attr(0754,-,qat) %{_bindir}/prime_sample
%attr(0754,-,qat) %{_bindir}/hkdf_sample
%attr(0754,-,qat) %{_bindir}/ec_montedwds_sample
%attr(0754,-,qat) %{_bindir}/zuc_sample
%{_datadir}/qat/calgary
%{_datadir}/qat/calgary32
%{_datadir}/qat/canterbury

%files         service
%{_sbindir}/qatmgr
%{_sbindir}/qat_init.sh
%{_unitdir}/qat.service
%{_mandir}/man8/qatmgr.8*
%{_mandir}/man8/qat_init.sh.8*

%files         doc
%doc INSTALL README.md

%changelog
* Tue Jul 23 2024 Aichun Shi <aichun.shi@intel.com> - 24.02.0-1
- Initial Packaging

