# Tests by default. No tests: rpm -ba --define 'dotests 0' libgpg-error*.spec
%{!?dotests: %define dotests 1}
Summary: libgpg-error
Name: libgpg-error
Version: 1.42
Release: 1
URL: ftp://ftp.gnupg.org/gcrypt/libgpg-error/
Source0: ftp://ftp.gnupg.org/gcrypt/libgpg-error//libgpg-error-%{version}.tar.bz2
Source1: ftp://ftp.gnupg.org/gcrypt/%{name}/%{name}-%{version}.tar.bz2.sig
Source2: gpg-error.h
Source3: gpgrt.h
Patch0: libgpg-error-1.42-libintl-hardcode.patch
Patch1: libgpg-error-1.29-multilib.patch
Patch2: libgpg-error-1.42-gpgrt_config.patch
Patch3: libgpg-error-1.42-configure.patch


Group: Development/Libraries
License: LGPLv2.1
BuildRequires: gettext, make, sed
Requires: gettext >= 0.19.8.1-5
Requires: libgcc >= 8.3.0-1

%description
This is a library that defines common error values for all GnuPG
components.  Among these are GPG, GPGSM, GPGME, GPG-Agent, libgcrypt,
pinentry, SmartCard Daemon and possibly more in the future.

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


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

%description devel
This is a library that defines common error values for all GnuPG
components.  Among these are GPG, GPGSM, GPGME, GPG-Agent, libgcrypt,
pinentry, SmartCard Daemon and possibly more in the future. This package
contains files necessary to develop applications using libgpg-error.

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


%prep
%setup -q
%patch0 -p0
%patch1 -p1
%patch2 -p0
%patch3 -p0

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="/usr/bin/rm -f"

export CFLAGS="-O2"

# first build the 64-bit version
cd 64bit
export OBJECT_MODE=64
export CC="gcc -O2 -maix64"
export LDFLAGS="-L/opt/freeware/lib64 -L/opt/freeware/lib -Wl,-blibpath:/opt/freeware/lib64:/opt/freeware/lib:/usr/lib:/lib"

./configure \
    --prefix=%{_prefix} \
    --enable-shared --enable-static

gmake %{?_smp_mflags}

export LIBPATH="%{_builddir}/%{name}-%{version}/64bit/src/.libs:/opt/freeware/lib64:/opt/freeware/lib:/usr/lib"
if [ "%{dotests}" == 1 ]
then
    (gmake -k check || true)
fi
cp src/.libs/libgpg-error.so.0 ../32bit/
slibclean


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

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

gmake %{?_smp_mflags}

export LIBPATH="%{_builddir}/%{name}-%{version}/32bit/src/.libs:/opt/freeware/lib:/usr/lib"
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/libgpg-error.a ./libgpg-error.so.0


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

#Install on 64bit mode
export OBJECT_MODE=64
cd 64bit
gmake DESTDIR=${RPM_BUILD_ROOT} install
(
    cd  ${RPM_BUILD_ROOT}/%{_prefix}/include
    mv gpg-error.h gpg-error-ppc64.h
    mv gpgrt.h gpgrt-ppc64.h

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

#Install on 32bit mode
export OBJECT_MODE=32
cd ../32bit
gmake DESTDIR=${RPM_BUILD_ROOT} install
(
    cd  ${RPM_BUILD_ROOT}/%{_prefix}/include
    mv gpg-error.h gpg-error-ppc32.h
    mv gpgrt.h gpgrt-ppc32.h
    cp %{SOURCE2} ${RPM_BUILD_ROOT}/%{_includedir}/
    cp %{SOURCE3} ${RPM_BUILD_ROOT}/%{_includedir}/
    chmod 644 ${RPM_BUILD_ROOT}/%{_includedir}/*.h

    cd  ${RPM_BUILD_ROOT}/%{_prefix}/bin
    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}/* || :

# patch /opt/freeware/include/gpg-error.h for AIX5L V5.1
cp %{SOURCE2} ${RPM_BUILD_ROOT}%{_includedir}/
#/opt/freeware/bin/sed -i 's|#include <stdint.h>|#if defined(_AIX) \&\& !defined(_AIX52)\n#include <inttypes.h>\n#else\n#include <stdint.h>\n#endif|g' ${RPM_BUILD_ROOT}%{_includedir}/gpg-error.h


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


%files
%defattr(-,root,system)
%doc 32bit/COPYING 32bit/COPYING.LIB 32bit/AUTHORS 32bit/README 32bit/INSTALL 32bit/NEWS 32bit/ChangeLog
%{_bindir}/gpg-error
%{_bindir}/gpg-error_32
%{_bindir}/gpg-error_64
%{_libdir}/*.a
%{_datadir}/locale/*
%{_datadir}/common-lisp/*


%files devel
%defattr(-,root,system)
%{_bindir}/gpg-error-config*
%{_bindir}/gpgrt-config*
%{_bindir}/yat2m*
%{_includedir}/*
%{_datadir}/aclocal/gpg-error.m4
%{_libdir}/pkgconfig/*


%changelog
* Thu Jul 08 2021 Reshma V Kumar <reskumar@in.ibm.com> - 1.42-1
- Update to version 1.42
- Stop shipping files in /usr directory

* Fri Jan 31 2020 Reshma V Kumar <reskumar@in.ibm.com> - 1.36-1
- Update to latest version

* Tue Jun 05 2018 Ravi Hirekurabar <rhirekur@in.ibm.com> 1.29-1 
- Updated to 1.29 built with 64bit header  

* Tue Jan 16 2018 Reshma V Kumaar <reskumar@in.ibm.com> - 1.27-1
- Update to version 1.27

* Wed Nov 08 2017 Tony Reix <tony.reix@atos.net> - 1.27-1
- Re-port

* Thu Jul 13 2017 Michael Perzl <michael@perzl.org> - 1.27-1
- updated to version 1.27

* Tue Jan 31 2017 Michael Perzl <michael@perzl.org> - 1.26-1
- updated to version 1.26

* Tue Jan 31 2017 Michael Perzl <michael@perzl.org> - 1.25-1
- updated to version 1.25

* Tue Jan 31 2017 Michael Perzl <michael@perzl.org> - 1.24-1
- updated to version 1.24

* Thu Nov 24 2016 Michael Perzl <michael@perzl.org> - 1.23-1
- updated to version 1.23

* Wed Dec 23 2015 Michael Perzl <michael@perzl.org> - 1.21-1
- updated to version 1.21

* Wed Dec 23 2015 Michael Perzl <michael@perzl.org> - 1.20-1
- updated to version 1.20

* Wed Dec 23 2015 Michael Perzl <michael@perzl.org> - 1.19-1
- updated to version 1.19

* Tue Feb 03 2015 Michael Perzl <michael@perzl.org> - 1.18-1
- updated to version 1.18

* Mon Dec 08 2014 Michael Perzl <michael@perzl.org> - 1.17-1
- updated to version 1.17

* Mon Dec 08 2014 Michael Perzl <michael@perzl.org> - 1.16-1
- updated to version 1.16

* Thu Sep 18 2014 Michael Perzl <michael@perzl.org> - 1.15-1
- updated to version 1.15

* Fri Aug 15 2014 Michael Perzl <michael@perzl.org> - 1.13-1
- updated to version 1.13

* Mon Jul 08 2013 Michael Perzl <michael@perzl.org> - 1.12-1
- updated to version 1.12

* Fri Apr 05 2013 Michael Perzl <michael@perzl.org> - 1.11-1
- updated to version 1.11

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

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

* Mon Jul 05 2010 Michael Perzl <michael@perzl.org> - 1.8-2
- removed dependency on gettext >= 0.17

* Wed May 26 2009 Michael Perzl <michael@perzl.org> - 1.8-1
- updated to version 1.8

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

* Fri Mar 28 2008 Michael Perzl <michael@perzl.org> - 1.6-3
- corrected some SPEC file errors

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

* Tue Nov 27 2007 Michael Perzl <michael@perzl.org> - 1.6-1
- updated to v1.6

* Thu Aug 16 2007 Michael Perzl <michael@perzl.org> - 1.5-1
- updated to v1.5

* Tue Jan 03 2006 Michael Perzl <michael@perzl.org> - 1.1-1
- first version for AIX V5.1 and higher
