File zstd.spec of Package zstd
#
# spec file for package zstd
#
# Copyright (c) 2024 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.
# Please submit bugfixes or comments via https://bugs.opensuse.org/
#
%define __builder ninja
%define libname libzstd1
%if 0%{?suse_version} <= 1500
%define with_gzip 0
%else
%define with_gzip 1
%endif
Name: zstd
Version: 1.5.6
Release: 0
Summary: Zstandard compression tools
License: BSD-3-Clause AND GPL-2.0-only
Group: Productivity/Archiving/Compression
URL: https://github.com/facebook/zstd
Source0: https://github.com/facebook/zstd/releases/download/v%{version}/%{name}-%{version}.tar.gz
Source1: https://github.com/facebook/zstd/releases/download/v%{version}/%{name}-%{version}.tar.gz.sig
Source2: zstd.keyring
Source99: baselibs.conf
Patch1: pzstd.1.patch
BuildRequires: cmake
BuildRequires: gcc
BuildRequires: meson
BuildRequires: ninja
# C++ is needed for pzstd only
BuildRequires: gcc-c++
BuildRequires: pkgconfig
# for .gz support
BuildRequires: pkgconfig(liblz4)
BuildRequires: pkgconfig(liblzma)
BuildRequires: pkgconfig(zlib)
%{?suse_build_hwcaps_libs}
%description
Zstd, short for Zstandard, is a lossless compression algorithm. Speed
vs. compression trade-off is configurable in small increments.
Decompression speed is preserved and remains roughly the same at all
settings, a property shared by most LZ compression algorithms, such
as zlib or lzma.
At roughly the same ratio, zstd (v1.4.0) achieves ~870%% faster
compression than gzip. For roughly the same time, zstd achives a
~12%% better ratio than gzip. LZMA outperforms zstd by ~10%% faster
compression for same ratio, or ~1–4%% size reduction for same time.
%package -n %{libname}
Summary: Zstd compression library
Group: System/Libraries
%description -n %{libname}
Zstd, short for Zstandard, is a lossless compression algorithm,
targeting faster compression than zlib at comparable ratios.
This subpackage contains the implementation as a shared library.
%package -n lib%{name}-devel
Summary: Development files for the Zstd compression library
Group: Development/Libraries/C and C++
Requires: %{libname} = %{version}
Requires: glibc-devel
%description -n lib%{name}-devel
Zstd, short for Zstandard, is a lossless compression algorithm,
targeting faster compression than zlib at comparable ratios.
Needed for compiling programs that link with the library.
%package -n lib%{name}-devel-static
Summary: Development files for the Zstd compression library
Group: Development/Libraries/C and C++
BuildRequires: glibc-devel-static
Requires: lib%{name}-devel = %{version}
%description -n lib%{name}-devel-static
Zstd, short for Zstandard, is a lossless compression algorithm,
targeting faster compression than zlib at comparable ratios.
Needed for compiling programs that link with the library.
%if %{with_gzip}
%package gzip
Summary: zstd and zlib based gzip drop-in
Group: Productivity/Archiving/Compression
Requires: %{name} >= %{version}
Conflicts: busybox-gzip
Conflicts: gzip
Conflicts: alternative(gzip)
Provides: gzip
Provides: alternative(gzip)
%description gzip
Zstd, short for Zstandard, is a lossless compression algorithm,
targeting faster compression than zlib at comparable ratios.
This subpackage provides a compatible alternative to gzip(1) using
an optimized deflate/zlib handling.
%endif
%prep
%autosetup -p1
%build
%global _lto_cflags %{_lto_cflags} -ffat-lto-objects
export CFLAGS="%{optflags} -fPIC -O3 -ftree-parallelize-loops=16 -ftree-vectorize -fvect-cost-model=cheap -fpredictive-commoning"
%ifarch x86_64
export CFLAGS="${CFLAGS} -march=x86-64 -mtune=generic -mssse3 -msse4 -msse4.1 -msse4.2 -mavx -maes -mpclmul"
%endif
export CXXFLAGS="%{optflags}"
# cmake devel files are only found in cmake build but gz/lz support is only found in meson build…
# typical corpo-style, so let's build whole thing twice
export DIR="$(pwd)/"
pushd build/cmake
%cmake \
-DZSTD_MULTITHREAD_SUPPORT=ON \
-DZSTD_MULTITHREAD_SUPPORT_DEFAULT=ON \
-DZSTD_LEGACY_SUPPORT=ON \
-DZSTD_BUILD_CONTRIB=ON \
-DZSTD_BUILD_TESTS=OFF
%cmake_build
pwd
#pushd ../..
pushd "${DIR}"build/meson
%meson \
-Ddefault_library=both \
-Dbin_tests=false \
-Dbin_contrib=true \
-Dmulti_thread=enabled \
-Dzlib=enabled \
-Dlzma=enabled \
-Dlz4=enabled
%meson_build
%check
pushd build/meson
#ctest
%install
pushd build/cmake
%cmake_install
pwd
pushd ../..
pushd build/meson
%meson_install
install -D -m644 ../../programs/zstd.1 %{buildroot}%{_mandir}/man1/pzstd.1
%if %{with_gzip}
ln -s zstd %{buildroot}/%{_bindir}/gzip
ln -s zstd %{buildroot}/%{_bindir}/gunzip
ln -s zstdcat %{buildroot}/%{_bindir}/zcat
ln -s zstdgrep %{buildroot}/%{_bindir}/zgrep
ln -s zstdless %{buildroot}/%{_bindir}/zless
%endif
rm -rfv %{buildroot}%{_datarootdir}/doc || echo "no trash in %{buildroot}%{_datarootdir}/doc"
%ldconfig_scriptlets -n %{libname}
%files
%license COPYING LICENSE
%doc README.md CHANGELOG
%{_bindir}/pzstd
%{_bindir}/unzstd
%{_bindir}/zstd
%{_bindir}/zstd-frugal
%{_bindir}/zstdcat
%{_bindir}/zstdgrep
%{_bindir}/zstdless
%{_bindir}/zstdmt
%{_mandir}/man1/*.1%{?ext_man}
#{_datarootdir}/doc/zstd
%files -n %{libname}
%license COPYING LICENSE
%{_libdir}/libzstd.so.1*
%files -n lib%{name}-devel
%license COPYING LICENSE
%{_includedir}/*.h
%{_libdir}/cmake
%{_libdir}/pkgconfig/libzstd.pc
%{_libdir}/libzstd.so
%files -n lib%{name}-devel-static
%license COPYING LICENSE
%{_libdir}/libzstd.a
%if %{with_gzip}
%files gzip
%license COPYING LICENSE
%{_bindir}/gzip
%{_bindir}/gunzip
%{_bindir}/zcat
%{_bindir}/zgrep
%{_bindir}/zless
%endif
%changelog