# Tests by default. No tests: rpmbuild -ba --define 'dotests 0' lz4*.spec
%{!?dotests: %define dotests 1}

Name:           lz4
Version:	1.10.0
Release:        1
Summary:        Extremely fast compression algorithm
Group:          System Environment/Libraries
License:        GPLv2+ and BSD
URL:            https://lz4.org
Source0:	https://github.com/lz4/lz4/releases/download/v%{version}/lz4-%{version}.tar.gz
# Both patches already upstreamed, available in next version 
Patch0:         lz4-1.10.0-Makefile-aix.patch
Patch1:         lz4-1.10.0-Makefile.patch
BuildRequires:	make
BuildRequires:  bash

Requires:	libgcc >= 10.3.0

%define _libdir64 %{_prefix}/lib64

%description
LZ4 is an extremely fast loss-less compression algorithm, providing compression
speed at 400 MB/s per core, scalable with multi-core CPU. It also features
an extremely fast decoder, with speed in multiple GB/s per core, typically
reaching RAM speed limits on multi-core systems.

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


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

%description    devel
This package contains the header(.h) and library(.so) files required to build
applications using liblz4 library.

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


%prep
%setup -q

%patch0
%patch1

/usr/bin/rm -rf /tmp/%{name}-%{version}-32bit
/usr/bin/cp -pr . /tmp/%{name}-%{version}-32bit
/usr/bin/rm -fr *
/usr/bin/mv /tmp/%{name}-%{version}-32bit 32bit
/usr/bin/cp -pr 32bit 64bit

%build
# There is no need to export -O2/-O3 in CFLAGS since it is already taken care by Makefile

cd 32bit
export CC="gcc -D_LARGE_FILES"
export LDFLAGS="-L/opt/freeware/lib -Wl,-blibpath:/opt/freeware/lib:/usr/lib:/lib -Wl,-bmaxdata:0x80000000"
gmake V=1

if [ "%{dotests}" == 1 ]
then
     (gmake -k test SHELL=/usr/bin/bash || true)
fi

cd ../64bit
export CC="gcc -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"
gmake V=1

if [ "%{dotests}" == 1 ]
then
     (gmake -k test SHELL=/usr/bin/bash || true)
fi
 

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

cd 32bit
gmake install DESTDIR=${RPM_BUILD_ROOT} PREFIX=%{_prefix} LIBDIR=%{_libdir}

cd ../64bit
export OBJECT_MODE=64
gmake install DESTDIR=${RPM_BUILD_ROOT} PREFIX=%{_prefix} LIBDIR=%{_libdir64}

# Add 64 bit library in /opt/freeware/lib/liblz4.a archive as well
/usr/bin/ar -q ${RPM_BUILD_ROOT}%{_libdir}/lib%{name}.a ${RPM_BUILD_ROOT}%{_libdir64}/lib%{name}.so.1

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


%files
%defattr(-,root,system)
%doc 32bit/programs/COPYING 32bit/lib/LICENSE 32bit/NEWS
%{_bindir}/*
%{_datadir}/man/man1/*
%{_libdir}/*.a
%{_libdir64}/*.a

%files devel
%defattr(-,root,system)
%{_includedir}/*
%{_libdir}/pkgconfig/*.pc
%{_libdir64}/pkgconfig/*.pc


%changelog
* Mon May 04 2026 Ayappan Perumal <ayappap2@in.ibm.com> - 1.10.0-1
- Update to version 1.10.0

* Wed Oct 25 2023 Shubham Gupta <shubham.gupta36@ibm.com> - 1.9.4-1 
- Update to version 1.9.4-1

* Fri Jun 03 2022 Reshma V Kumar <reskumar@in.ibm.com> - 1.9.3-1
- Update to latest version

* Thu Oct 24 2019 Ayappan P <ayappap2@in.ibm.com> - 1.9.2-1
- First port to AIX Toolbox

* Wed Apr 17 2019 Tony Reix <tony.reix@atos.net> - 1.8.0-1
- Port for BullFreeware

* Wed Nov 15 2017 Michael Perzl <michael@perzl.org> - 1.8.0-1
- updated to version 1.8.0

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

* Tue Dec 13 2016 Michael Perzl <michael@perzl.org> - 1.7.3-1
- first version for AIX V5.1 and higher

