Name:          libwd
Summary:       User Space Accelerator Development Kit
Version:       2.3.11
Release:       2
License:       Apache-2.0
Source:        %{name}-%{version}.tar.gz
Vendor:        Huawei Corporation
ExclusiveOS:   linux
URL:           https://support.huawei.com 
BuildRoot:     %{_tmppath}/%{name}-%{version}-root
Conflicts:     %{name} < %{version}-%{release}
Provides:      %{name} = %{version}-%{release}
BuildRequires: numactl-devel
BuildRequires: automake, autoconf, libtool
BuildRequires: gcc, make
ExclusiveArch: aarch64

%description
This package contains the User Space Accelerator Library
for hardware accelerator, compress, symmetric encryption
and decryption, asymmetric encryption and decryption.

%prep
%global debug_package %{nil}
%setup -c -n %{name}-%{version}

%build
cd uadk
sh autogen.sh
./configure
make

%install
mkdir -p ${RPM_BUILD_ROOT}/usr/lib64
install -b -m755 uadk/.libs/libwd.so.%{version} ${RPM_BUILD_ROOT}/usr/lib64
install -b -m755 uadk/.libs/libwd_crypto.so.%{version} ${RPM_BUILD_ROOT}/usr/lib64
install -b -m755 uadk/.libs/libwd_comp.so.%{version} ${RPM_BUILD_ROOT}/usr/lib64
install -b -m755 uadk/.libs/libhisi_sec.so.%{version} ${RPM_BUILD_ROOT}/usr/lib64
install -b -m755 uadk/.libs/libhisi_hpre.so.%{version} ${RPM_BUILD_ROOT}/usr/lib64
install -b -m755 uadk/.libs/libhisi_zip.so.%{version} ${RPM_BUILD_ROOT}/usr/lib64
mkdir -p ${RPM_BUILD_ROOT}/usr/include/warpdrive
mkdir -p ${RPM_BUILD_ROOT}/usr/include/warpdrive/include
cp uadk/v1/uacce.h ${RPM_BUILD_ROOT}/usr/include/warpdrive/include
cp uadk/v1/wd.h ${RPM_BUILD_ROOT}/usr/include/warpdrive
cp uadk/v1/wd_cipher.h ${RPM_BUILD_ROOT}/usr/include/warpdrive
cp uadk/v1/wd_comp.h ${RPM_BUILD_ROOT}/usr/include/warpdrive
cp uadk/v1/wd_dh.h ${RPM_BUILD_ROOT}/usr/include/warpdrive
cp uadk/v1/wd_digest.h ${RPM_BUILD_ROOT}/usr/include/warpdrive
cp uadk/v1/wd_rsa.h ${RPM_BUILD_ROOT}/usr/include/warpdrive
cp uadk/v1/wd_bmm.h ${RPM_BUILD_ROOT}/usr/include/warpdrive
mkdir -p ${RPM_BUILD_ROOT}/usr/include/uadk
mkdir -p ${RPM_BUILD_ROOT}/usr/include/uadk/include
cp uadk/include/uacce.h ${RPM_BUILD_ROOT}/usr/include/uadk/include
cp uadk/include/wd.h ${RPM_BUILD_ROOT}/usr/include/uadk
cp uadk/include/wd_cipher.h ${RPM_BUILD_ROOT}/usr/include/uadk
cp uadk/include/wd_comp.h ${RPM_BUILD_ROOT}/usr/include/uadk
cp uadk/include/wd_dh.h ${RPM_BUILD_ROOT}/usr/include/uadk
cp uadk/include/wd_digest.h ${RPM_BUILD_ROOT}/usr/include/uadk
cp uadk/include/wd_rsa.h ${RPM_BUILD_ROOT}/usr/include/uadk
cp uadk/include/wd_aead.h ${RPM_BUILD_ROOT}/usr/include/uadk
cp uadk/include/wd_ecc.h ${RPM_BUILD_ROOT}/usr/include/uadk
cp uadk/include/wd_ecc_curve.h ${RPM_BUILD_ROOT}/usr/include/uadk


%clean
rm -rf ${RPM_BUILD_ROOT}

%files
%defattr(755,root,root)
/usr/lib64/libwd.so.%{version}
/usr/lib64/libwd_crypto.so.%{version}
/usr/lib64/libwd_comp.so.%{version}
/usr/lib64/libhisi_sec.so.%{version}
/usr/lib64/libhisi_hpre.so.%{version}
/usr/lib64/libhisi_zip.so.%{version}
%defattr(644,root,root)
/usr/include/warpdrive/include/uacce.h
/usr/include/warpdrive/wd.h
/usr/include/warpdrive/wd_cipher.h
/usr/include/warpdrive/wd_comp.h
/usr/include/warpdrive/wd_dh.h
/usr/include/warpdrive/wd_digest.h
/usr/include/warpdrive/wd_rsa.h
/usr/include/warpdrive/wd_bmm.h
/usr/include/uadk/include/uacce.h
/usr/include/uadk/wd.h
/usr/include/uadk/wd_cipher.h
/usr/include/uadk/wd_comp.h
/usr/include/uadk/wd_dh.h
/usr/include/uadk/wd_digest.h
/usr/include/uadk/wd_rsa.h
/usr/include/uadk/wd_aead.h
/usr/include/uadk/wd_ecc.h
/usr/include/uadk/wd_ecc_curve.h
%exclude /usr/lib64/libwd.so.2
%exclude /usr/lib64/libwd_crypto.so.2
%exclude /usr/lib64/libwd_comp.so.2
%exclude /usr/lib64/libhisi_sec.so.2
%exclude /usr/lib64/libhisi_hpre.so.2
%exclude /usr/lib64/libhisi_zip.so.2


%pre
if [ "$1" = "2" ] ; then  #2: update
    rm -rf /usr/lib64/libwd.so   > /dev/null 2>&1 || true
    rm -rf /usr/lib64/libwd.so.2   > /dev/null 2>&1 || true
    rm -rf /usr/lib64/libwd_crypto.so   > /dev/null 2>&1 || true
    rm -rf /usr/lib64/libwd_crypto.so.2   > /dev/null 2>&1 || true
    rm -rf /usr/lib64/libwd_comp.so   > /dev/null 2>&1 || true
    rm -rf /usr/lib64/libwd_comp.so.2   > /dev/null 2>&1 || true
    rm -rf /usr/lib64/libhisi_sec.so   > /dev/null 2>&1 || true
    rm -rf /usr/lib64/libhisi_sec.so.2   > /dev/null 2>&1 || true
    rm -rf /usr/lib64/libhisi_hpre.so   > /dev/null 2>&1 || true
    rm -rf /usr/lib64/libhisi_hpre.so.2   > /dev/null 2>&1 || true
    rm -rf /usr/lib64/libhisi_zip.so   > /dev/null 2>&1 || true
    rm -rf /usr/lib64/libhisi_zip.so.2   > /dev/null 2>&1 || true
fi

%post
if [[ "$1" = "1" || "$1" = "2" ]] ; then  #1: install 2: update
    cd /usr/lib64
    ln -sf libwd.so.%{version} libwd.so
    ln -sf libwd.so.%{version} libwd.so.2
    ln -sf libwd_crypto.so.%{version} libwd_crypto.so
    ln -sf libwd_crypto.so.%{version} libwd_crypto.so.2
    ln -sf libwd_comp.so.%{version} libwd_comp.so
    ln -sf libwd_comp.so.%{version} libwd_comp.so.2
    ln -sf libhisi_sec.so.%{version} libhisi_sec.so
    ln -sf libhisi_sec.so.%{version} libhisi_sec.so.2
    ln -sf libhisi_hpre.so.%{version} libhisi_hpre.so
    ln -sf libhisi_hpre.so.%{version} libhisi_hpre.so.2
    ln -sf libhisi_zip.so.%{version} libhisi_zip.so
    ln -sf libhisi_zip.so.%{version} libhisi_zip.so.2
fi
/sbin/ldconfig

%preun
if [ "$1" = "0" ] ; then  #0: uninstall
    rm -rf /usr/lib64/libwd.so    > /dev/null 2>&1 || true
    rm -rf /usr/lib64/libwd.so.2    > /dev/null 2>&1 || true
    rm -rf /usr/lib64/libwd_crypto.so    > /dev/null 2>&1 || true
    rm -rf /usr/lib64/libwd_crypto.so.2    > /dev/null 2>&1 || true
    rm -rf /usr/lib64/libwd_comp.so    > /dev/null 2>&1 || true
    rm -rf /usr/lib64/libwd_comp.so.2   > /dev/null 2>&1 || true
    rm -rf /usr/lib64/libhisi_sec.so    > /dev/null 2>&1 || true
    rm -rf /usr/lib64/libhisi_sec.so.2   > /dev/null 2>&1 || true
    rm -rf /usr/lib64/libhisi_hpre.so    > /dev/null 2>&1 || true
    rm -rf /usr/lib64/libhisi_hpre.so.2    > /dev/null 2>&1 || true
    rm -rf /usr/lib64/libhisi_zip.so    > /dev/null 2>&1 || true
    rm -rf /usr/lib64/libhisi_zip.so.2    > /dev/null 2>&1 || true
fi

%postun
/sbin/ldconfig

%changelog
* Wed Jul 21 2021 caodongxia <caodongxia@huawei.com> 2.3.11-2
- change uacce.h path.

* Wed Jun 06 2021 Hao Fang <fanghao11@huawei.com> 2.3.11-1
- update warpdrive to uadk, support kunpeng 920/930.

* Sun Mar 15 2020 zhangtao <zhangtao221@huawei.com> 1.2.10-3
- Specify compilation aarch64 as platform

* Tue Mar 03 2020 catastrowings <jianghuhao1994@163.com> 1.2.10-2
- openEuler init

* Tue Jan 07 2020 jinbinhua <jinbinhua@huawei.com> 1.2.7-1
- First Spec Version Include Warpdrive Code
