Name:           p11-kit
Version:	0.23.14
Release:	6
Summary:        Provides a way to load and enumerate PKCS#11 modules.
License:        BSD
URL:            http://p11-glue.freedesktop.org/p11-kit.html

Source0:        https://github.com/p11-glue/p11-kit/releases/download/%{version}//%{name}-%{version}.tar.gz
Source1:        p11-kit-client.service

Patch6001:	debug-Work-around-cppcheck-false-positives.patch
Patch6002:	build-Call-va_end-always-when-leaving-the-function.patch
Patch6003:	rpc-server-p11_kit_remote_serve_tokens-Fix-memleak.patch
Patch6004:	rpc-server-Check-calloc-failure.patch
Patch6005:	trust-Check-index-buckets-is-allocated-on-cleanup.patch
Patch6006:	trust-Propagate-library-verbosity-to-module-through-.patch
Patch6007:	trust-Fail-if-trust-anchors-are-not-loaded-from-a-fi.patch
Patch6008:	trust-p11_token_load-Treat-parse-error-as-failure.patch
Patch6009:	trust-Continue-parsing-if-the-file-cannot-be-read-as.patch
Patch6010:	pem-Fix-assert-condition.patch
Patch6011:	trust-Ignore-unreadable-content-in-anchors.patch
Patch6012:	modules-check-gl.modules-before-iterates-on-it-when-.patch
Patch6013:	modules-Fix-index-used-in-call-to-p11_dict_remove.patch

BuildRequires:  gcc libtasn1-devel >= 2.3 libffi-devel gtk-doc systemd-devel pkgconfig(glib-2.0) libxslt

Provides:       p11-kit-server = %{version}-%{release}
Obsoletes:      p11-kit-server < %{version}-%{release}

%description
Provides a way to load and enumerate PKCS#11 modules.
Provides a standard configuration setup for installing
PKCS#11 modules in such a way that they're discoverable.
Also solves problems with coordinating the use of PKCS#11
by different components or libraries living in the same process.

%package devel
Summary:        Development files for %{name}
Requires:       %{name} = %{version}-%{release}

%description devel
Provides header and libraries files for applications use %{name} to develop.

%package trust
Summary:        Trust policy module of %{name}
Requires:       %{name} = %{version}-%{release}
Requires(post): %{_sbindir}/update-alternatives
Requires(postun): %{_sbindir}/update-alternatives
Conflicts:      nss < 3.14.3-9

%description trust
This package contains PKCS#11 trust policy module.

%package help
Summary:        Help infomation of %{name}
Requires:       %{name} = %{version}-%{release}

%description help
This package contains help information of p11-kit.

%define multilib_arches ppc64 sparc64 x86_64 ppc64le
%ifarch %{multilib_arches}
%define alt_ckbi  libnssckbi.so.%{_arch}
%else
%define alt_ckbi  libnssckbi.so
%endif

%prep
%autosetup -p1

%build
%configure --enable-doc --with-trust-paths=/etc/pki/ca-trust/source:/usr/share/pki/ca-trust-source
make -j 4 V=1

%install
make install DESTDIR=$RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/pkcs11/modules
install -p -m 644 %{SOURCE1} $RPM_BUILD_ROOT%{_userunitdir}
find $RPM_BUILD_ROOT -type f -name "*.la" -delete -print

%check
make check

%post -p /sbin/ldconfig

%post trust
%{_sbindir}/update-alternatives --install %{_libdir}/libnssckbi.so %{alt_ckbi} %{_libdir}/pkcs11/p11-kit-trust.so 30

%postun -p /sbin/ldconfig

%postun trust
if [ $1 -eq 0 ]; then
        %{_sbindir}/update-alternatives --remove %{alt_ckbi} %{_libdir}/pkcs11/p11-kit-trust.so
fi
 
%files
%license COPYING
%dir %{_libexecdir}/p11-kit
%dir %{_sysconfdir}/pkcs11
%dir %{_sysconfdir}/pkcs11/modules
%dir %{_datadir}/p11-kit
%dir %{_datadir}/p11-kit/modules
%{_bindir}/p11-kit
%{_libdir}/libp11-kit.so.*
%{_libdir}/p11-kit-proxy.so
%{_libdir}/pkcs11/p11-kit-client.so
%{_libexecdir}/p11-kit/p11-kit-remote
%{_libexecdir}/p11-kit/p11-kit-server
%{_userunitdir}/p11-kit-client.service
%{_userunitdir}/p11-kit-server.service
%{_userunitdir}/p11-kit-server.socket

%files help
%doc AUTHORS NEWS README
%doc p11-kit/pkcs11.conf.example
%{_mandir}/man1/trust.1.gz
%{_mandir}/man8/p11-kit.8.gz
%{_mandir}/man5/pkcs11.conf.5.gz
%{_sysconfdir}/pkcs11/pkcs11.conf.example

%files devel
%doc %{_datadir}/gtk-doc/
%{_includedir}/p11-kit-1/
%{_libdir}/libp11-kit.so
%{_libdir}/pkgconfig/p11-kit-1.pc

%files trust
%{_bindir}/trust
%dir %{_libdir}/pkcs11
%ghost %{_libdir}/libnssckbi.so
%{_libdir}/pkcs11/p11-kit-trust.so
%{_datadir}/p11-kit/modules/p11-kit-trust.module

%changelog
* Fri Jan 10 2020 openEuler Buildteam <buildteam@openeuler.org> - 0.23.14-6
- delete unused file

* Sat Dec 28 2019 openEuler Buildteam <buildteam@openeuler.org> - 0.23.14-5
- fix update problem

* Fri Dec 20 2019 openEuler Buildteam <buildteam@openeuler.org> - 0.23.14-4
- Add missing Requires

* Wed Nov 20 2019 openEuler Buildteam <buildteam@openeuler.org> - 0.23.14-3
- Add Buildrequires: libxslt

* Fri Sep 27 2019 openEuler Buildteam <buildteam@openeuler.org> - 0.23.14-2
- Correct patch number

* Sat Sep 7 2019 openEuler Buildteam <buildteam@openeuler.org> - 0.23.14-1
- Package init
