# Tests by default. No tests: rpm -ba --define 'dotests 0' libassuan*.spec
%{!?dotests: %define dotests 1}
Summary: X.509 library
Name:    libksba
Version: 1.6.0
Release: 1
License: GPL
Group:   System Environment/Libraries
URL:     http://www.gnupg.org/
Source0: ftp://ftp.gnupg.org/gcrypt/%{name}/%{name}-%{version}.tar.bz2
Source1: ftp://ftp.gnupg.org/gcrypt/%{name}/%{name}-%{version}.tar.bz2.sig

BuildRequires: libgpg-error-devel >= 1.36
BuildRequires: libgcrypt-devel >= 1.8.5
Requires: libgpg-error >= 1.36 
Requires: libgcrypt >= 1.8.5
Requires: libgcc >= 8.3.0

%description
KSBA is a library designed to build software based on the X.509 and
CMS protocols.

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


%package devel
Summary: Development headers and libraries for %{name}
Group:   Development/Libraries
Requires: %{name} = %{version}-%{release}
Requires: info
Requires: /sbin/install-info

%description devel
%{summary}.

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 "xlc -q64" or "gcc -maix64".


%prep
%setup -q
#%patch0
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
# setup environment for 32-bit and 64-bit builds
export AR="ar -X32_64"
export NM="nm -X32_64"
export RM="rm -f"

# first build the 64-bit version
export OBJECT_MODE=64
cd 64bit
#export CC="xlc -q64"
export CC="gcc -maix64 -O2"
./configure \
    --prefix=%{_prefix} \
    --libdir=%{_libdir}64 \
    --infodir=%{_prefix}/info \
    --enable-static --enable-shared

make %{?_smp_mflags}

cp src/.libs/libksba.so.8 ../32bit

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

# now build the 32-bit version
export OBJECT_MODE=32
cd ../32bit
#export CC="xlc"
export CC="gcc -maix32 -O2 -D_LARGE_FILES"
export GPG_ERROR_CONFIG="/opt/freeware/bin/gpg-error-config_32"
export LIBGCRYPT_CONFIG="/opt/freeware/bin/libgcrypt-config_32"

./configure \
    --prefix=%{_prefix} \
    --libdir=%{_libdir} \
    --infodir=%{_prefix}/info \
    --enable-static --enable-shared

make %{?_smp_mflags}

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

# add the 64-bit shared objects to the shared library containing already the
# 32-bit shared objects
${AR} -q src/.libs/libksba.a ./libksba.so.8


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

#Install on 64bit mode
export OBJECT_MODE=64
cd 64bit
make DESTDIR=${RPM_BUILD_ROOT} install

(
    cd  ${RPM_BUILD_ROOT}/%{_prefix}/bin
    mv ksba-config ksba-config_64
)

#Install on 32bit mode
export OBJECT_MODE=32
cd ../32bit
make DESTDIR=${RPM_BUILD_ROOT} install

(
    cd  ${RPM_BUILD_ROOT}/%{_prefix}/bin
    mv ksba-config ksba-config_32
    ln -sf ksba-config_64 ksba-config
)

export RM="rm -f"

rm -f ${RPM_BUILD_ROOT}%{_infodir}/dir
gzip --best ${RPM_BUILD_ROOT}%{_infodir}/ksba.info

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


%post devel
install-info %{_infodir}/ksba.info.gz %{_infodir}/dir


%postun devel
if [ $1 -eq 0 ]; then
    install-info --delete %{_infodir}/ksba.info.gz %{_infodir}/dir
fi


%files
%defattr(-,root,system,-)
%doc 32bit/AUTHORS 32bit/ChangeLog 32bit/COPYING 32bit/NEWS 32bit/README* 32bit/THANKS 32bit/TODO
%{_libdir}/lib*.a
%{_libdir}64/lib*.a


%files devel
%defattr(-,root,system,-)
%{_bindir}/ksba-config*
%{_includedir}/*
%{_datadir}/aclocal/*
%{_infodir}/*


%changelog
* Wed Aug 26 2020 Ashwini Chandrappa<ashwic22@in.ibm.com> - 1.4.0-1
- Updated to version 1.4.0
- Stop shipping files in /usr directory 

* Fri Jan 19 2018 Reshma V Kumar <reskumar@in.ibm.com> 1.3.5-1
- Initial port for AIX

* Tue Nov 07 2017 Tony Reix <tony.reix@atos.net> - 1.3.5-1
- updated to version 1.3.5

* Tue Jan 08 2013 Michael Perzl <michael@perzl.org> - 1.3.0-1
- updated to version 1.3.0

* Tue Mar 29 2011 Michael Perzl <michael@perzl.org> - 1.2.0-1
- updated to version 1.2.0

* Wed Nov 17 2010 Michael Perzl <michael@perzl.org> - 1.1.0-1
- updated to version 1.1.0

* Thu Jul 22 2010 Michael Perzl <michael@perzl.org> - 1.0.8-1
- updated to version 1.0.8

* Tue Sep 08 2009 Michael Perzl <michael@perzl.org> - 1.0.7-1
- updated to version 1.0.7

* Tue Mar 10 2009 Michael Perzl <michael@perzl.org> - 1.0.5-1
- updated to version 1.0.5

* Fri Sep 26 2008 Michael Perzl <michael@perzl.org> - 1.0.4-1
- updated to version 1.0.4

* Wed Apr 23 2008 Michael Perzl <michael@perzl.org> - 1.0.3-1
- updated to version 1.0.3

* Thu Jan 03 2008 Michael Perzl <michael@perzl.org> - 1.0.2-2
- included both 32-bit and 64-bit shared objects

* Fri Oct 05 2007 Michael Perzl <michael@perzl.org> - 1.0.2-1
- first version for AIX V5.1 and higher
