# Tests by default. No tests: rpm -ba --define 'dotests 0' p11-kit-*.spec
%{!?dotests:%define DO_TESTS 1}

Name:           p11-kit
Version:	0.26.2
Release:        1
Summary:        Library to work with PKCS#11 modules
License:        BSD-3-Clause
Group:          Development/Libraries/C and C++
Url:            https://p11-glue.github.io/p11-glue/p11-kit.html 
Source0:	https://github.com/p11-glue/p11-kit/releases/download/%{version}/p11-kit-%{version}.tar.xz
Source1:	https://github.com/p11-glue/p11-kit/releases/download/%{version}/p11-kit-%{version}.tar.xz.sig 

Patch0:         %{name}-0.23.15-aixconf.patch
Patch3:         %{name}-0.23.15-getopt_long.patch
Patch4:		%{name}-0.25.5-getopt_long.patch
#Patch5:         %{name}-0.25.0-use_bash.patch


BuildRequires:	gettext >= 0.21
BuildRequires:	pkg-config >= 0.29.2
Requires:	gettext >= 0.21
Requires:	libgcc >= 10.3.0
Requires:	libffi >= 3.4.4
Requires:	libtasn1 >= 4.19.0

%define _libdir64 %{_prefix}/lib64


%description
p11-kit provides a way to load and enumerate PKCS#11 modules, as well
as a standard configuration setup for installing PKCS#11 modules in
such a way that they're discoverable.

The library is available as 32-bit and 64-bit.


%package tools
License:        BSD-3-Clause
Summary:        Library to work with PKCS#11 modules -- Tools
Group:          Development/Libraries/C and C++
Requires:       %{name} = %{version}-%{release}
Requires:	libffi >= 3.4.4
Requires:	libtasn1 >= 4.19.0

%description tools
p11-kit provides a way to load and enumerate PKCS#11 modules, as well
as a standard configuration setup for installing PKCS#11 modules in
such a way that they're discoverable.


%package devel
License:        BSD-3-Clause
Summary:        Library to work with PKCS#11 modules -- Development Files
Group:          Development/Libraries/C and C++
Requires:       %{name} = %{version}-%{release}

%description devel
p11-kit provides a way to load and enumerate PKCS#11 modules, as well
as a standard configuration setup for installing PKCS#11 modules in
such a way that they're discoverable.

If you are compiling a 32-bit program, no special compiler options are
needed.

If you are compiling a 64-bit program, you have to compile and link your
application with "cc -q64" or "gcc -maix64".


%prep
%setup -q
%patch0 -p0
%patch3 -p1 
%patch4 
#%patch5 -p1 -b .use_bash.patch

# Duplicate source for 32 & 64 bits
rm -rf   /tmp/%{name}-%{version}-32bit
cp -pr . /tmp/%{name}-%{version}-32bit
rm -fr *
mv       /tmp/%{name}-%{version}-32bit 32bit
cp -pr 32bit 64bit

%build
PATH=/usr/bin:/opt/freeware/bin:/usr/sbin:/usr/ucb:/usr/bin/X11:/sbin:.
export RM="/usr/bin/rm -f"
export CONFIG_SHELL=/opt/freeware/bin/bash
export CONFIG_ENV_ARGS=/opt/freeware/bin/bash

cd 64bit
# first build the 64-bit version
export CC="%{__cc__} -maix64"
export CXX="%{__cxx__} -maix64"
export OBJECT_MODE=64
export LDFLAGS="-L/opt/freeware/lib64 -L/opt/freeware/lib -Wl,-blibpath:/opt/freeware/lib64:/opt/freeware/lib:/usr/lib:/lib"
export CFLAGS="-O2"

./configure \
    --prefix=%{_prefix} \
    --libdir=%{_libdir64} \
    --with-trust-paths=%{_datadir}/pki/ca-trust-source \
    --without-systemd \
    --enable-shared --disable-static

gmake V=1 %{?_smp_mflags}


if [ "%{DO_TESTS}" == 1 ]
then
    (gmake -k check || true)
    /usr/sbin/slibclean
fi


cd ../32bit
# now build the 32-bit version
export OBJECT_MODE=32
export CC="%{__cc__} -maix32 -D_LARGE_FILES"
export CXX="%{__cxx__} -maix32 -D_LARGE_FILES"
export LDFLAGS="-L/opt/freeware/lib -Wl,-blibpath:/opt/freeware/lib:/usr/lib:/lib -Wl,-bmaxdata:0x80000000"
export CFLAGS="-O2"

./configure \
    --prefix=%{_prefix} \
    --libdir=%{_libdir} \
    --with-trust-paths=%{_datadir}/pki/ca-trust-source \
    --without-systemd \
    --enable-shared --disable-static

gmake V=1 %{?_smp_mflags}


if [ "%{DO_TESTS}" == 1 ]
then
    (gmake -k check || true)
    /usr/sbin/slibclean
fi


%install
[ "${RPM_BUILD_ROOT}" != "/" ] && rm -rf ${RPM_BUILD_ROOT}

cd 64bit
export OBJECT_MODE=64
unset LDFLAGS

make DESTDIR=${RPM_BUILD_ROOT} install


(
  cd ${RPM_BUILD_ROOT}%{_bindir}
  for f in * ; do
    mv -f ${f} ${f}_64
  done
)

(
    cd  ${RPM_BUILD_ROOT}/%{_libexecdir}/p11-kit
    for fic in $(ls -1| grep -v -e _32 -e _64)
    do
        mv $fic "$fic"_64
    done
)


cd ../32bit
export OBJECT_MODE=32
unset LDFLAGS

make DESTDIR=${RPM_BUILD_ROOT} install

(
    cd  ${RPM_BUILD_ROOT}/%{_bindir}
    for fic in $(ls -1| grep -v -e _32 -e _64)
    do
        mv $fic "$fic"_32
        ln -sf "$fic"_64 $fic
    done
)

(
    cd  ${RPM_BUILD_ROOT}/%{_libexecdir}/p11-kit
    for fic in $(ls -1| grep -v -e _32 -e _64)
    do
        mv $fic "$fic"_32
        ln -sf "$fic"_64 $fic
    done
)

/usr/bin/strip -X32_64 ${RPM_BUILD_ROOT}%{_bindir}/* || :

(
  cd ${RPM_BUILD_ROOT}%{_libdir64}
  for f in *.a ; do
    /usr/bin/ar -X64 -x ${f}
  done

)

# p11-kit needs modules as .so
(
  cd ${RPM_BUILD_ROOT}%{_libdir64}/pkcs11
  for f in *.a ; do
    /usr/bin/ar -X64 -x ${f}
  done

  cd ${RPM_BUILD_ROOT}%{_libdir}/pkcs11
  for f in *.a ; do
    /usr/bin/ar -X32 -x ${f}
  done
)



# add the 64-bit shared objects to the shared libraries containing already the
# 32-bit shared objects
/usr/bin/ar -X64 -q ${RPM_BUILD_ROOT}%{_libdir}/lib%{name}.a ${RPM_BUILD_ROOT}%{_libdir64}/lib%{name}.so*
/usr/bin/ar -X64 -q ${RPM_BUILD_ROOT}%{_libdir}/pkcs11/%{name}-client.a ${RPM_BUILD_ROOT}%{_libdir64}/pkcs11/%{name}-client.so*
/usr/bin/ar -X64 -q ${RPM_BUILD_ROOT}%{_libdir}/pkcs11/%{name}-trust.a ${RPM_BUILD_ROOT}%{_libdir64}/pkcs11/%{name}-trust.so*

# Create pkcs11 config directory
mkdir -p ${RPM_BUILD_ROOT}%{_sysconfdir}/pkcs11/modules

# lib64 lib is link to lib
(
  cd ${RPM_BUILD_ROOT}%{_libdir64}
  for fic in *.a ; do
    ln -sf ../lib/${fic} ${fic}
  done
)


%clean
[ "${RPM_BUILD_ROOT}" != "/" ] && rm -rf ${RPM_BUILD_ROOT}


%files
%defattr(-,root,system)
%doc 32bit/AUTHORS 32bit/ChangeLog 32bit/COPYING 32bit/NEWS 32bit/README
%doc 32bit/p11-kit/pkcs11.conf.example
%dir %{_sysconfdir}/pkcs11
%dir %{_sysconfdir}/pkcs11/modules
%dir %{_datadir}/p11-kit/
%dir %{_datadir}/p11-kit/modules/
%dir %{_libexecdir}/p11-kit
%{_libdir}/*.a
%{_libdir64}/*.a
%{_libexecdir}/p11-kit/p11-kit-remote*
%{_libexecdir}/p11-kit/p11-kit-server*
%{_libexecdir}/p11-kit/trust-extract-compat*
%{_datadir}/p11-kit/modules/p11-kit-trust.module
%{_libdir}/pkcs11/*.so
%{_libdir64}/pkcs11/*.so


%files tools 
%defattr(-,root,system)
%{_bindir}/p11-kit*
%{_bindir}/trust*


%files devel
%defattr(-,root,system)
%doc %dir %{_datadir}/gtk-doc
%doc %dir %{_datadir}/gtk-doc/html
%doc %{_datadir}/gtk-doc/html/p11-kit/
%{_includedir}/p11-kit-1
%{_libdir}/pkgconfig/*.pc
%{_libdir64}/pkgconfig/*.pc


%changelog
* Thu May 07 2026 Lakshmi Surekha Kovvuri <Lakshmi.Kovvuri@ibm.com> - 0.26.2-1
- Update to version 0.26.2 to fix CVE-2026-2100.

* Mon Oct 13 2025 Lakshmi Surekha Kovvuri <Lakshmi.Kovvuri@ibm.com> - 0.25.10-1
- Update to latest version 0.25.10.

* Thu Oct 17 2024 Shubham Gupta <Shubham.Gupta36@ibm.com>  - p11-kit-0.25.5-1
- Update to version p11-kit-0.25.5-1

* Thu Jul 06 2023 Raghu N Arava <raghuara@in.ibm.com> - p11-kit-0.24.1-1 
- Update to version p11-kit-0.24.1-1

* Tue May 18 2021 Rishita Saha <risaha16@in.ibm.com> - 0.23.22-1
- Update to version 0.23.22

* Fri Apr 30 2021 Rishita Saha <risaha16@in.ibm.com> - 0.23.16-2
- Rebuilt to ship missing files and binaries 
- Not shipping files in /usr directory any longer 

* Mon Jun 17 2019 Ravi Hirekurabar <rhirekur@in.ibm.com> - 0.23.16-1
- Updated to 0.23.16 
- Made 64bit as default

* Fri Nov 11 2016 Ravi Hirekur@in.ibm.com  <rhirekur@in.ibm.com> - 0.23.2-1
- updated to version 0.23.2

* Wed Jun 21 2013 Gerard Visiedo <gerard.visiedo@bull.net> - 0.14-2
- Initial port on Aix6.1

* Mon Sep 17 2012 Michael Perzl <michael@perzl.org> - 0.14-1
- updated to version 0.14

* Fri Mar 16 2012 Michael Perzl <michael@perzl.org> - 0.12-1
- updated to version 0.12

* Fri Mar 16 2012 Michael Perzl <michael@perzl.org> - 0.11-1
- updated to version 0.11

* Mon Nov 21 2011 Michael Perzl <michael@perzl.org> - 0.9-1
- updated to version 0.9

* Thu Oct 06 2011 Michael Perzl <michael@perzl.org> - 0.7-1
- updated to version 0.7

* Wed Sep 21 2011 Michael Perzl <michael@perzl.org> - 0.6-1
- updated to version 0.6

* Wed Sep 07 2011 Michael Perzl <michael@perzl.org> - 0.5-1
- updated to version 0.5

* Sun Aug 21 2011 Michael Perzl <michael@perzl.org> - 0.4-1
- updated to version 0.4

* Tue Aug 09 2011 Michael Perzl <michael@perzl.org> - 0.3-1
- first version for AIX V5.1 and higher

