# Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

# Disable build id note requirement for now
%undefine _missing_build_ids_terminate_build

# Force special prefix for Vespa
%define _prefix /opt/vespa-deps

# Only strip debug info
%global _find_debuginfo_opts -g

# Don't provide shared library or pkgconfig
%global __provides_exclude ^(lib.*\\.so\\.[0-9.]*\\(\\)\\(64bit\\)|pkgconfig\\(.*)$

# Exclude automated requires for libraries in /opt/vespa-deps/lib64.
%global __requires_exclude ^libzstd\\.so\\.[0-9.]*\\([A-Za-z._0-9]*\\)\\(64bit\\)$

# Version
%define ver_major 1
%define ver_minor 5
%define ver_patch 0
%define ver_release 1

Summary:        zstd compiled for vespa
Name:           vespa-zstd
Version:        %{ver_major}.%{ver_minor}.%{ver_patch}
Release:        %{ver_release}%{?dist}
License:        BSD and GPLv2
URL:            https://github.com/facebook/zstd
Source0:        https://github.com/facebook/zstd/archive/v%{version}.tar.gz#/zstd-%{version}.tar.gz

%if 0%{?el7}
%if 0%{?amzn2}
BuildRequires: gcc10%{?_isa}
%define _toolset_compiler_args CC=gcc10-gcc
%else
%define _devtoolset_enable /opt/rh/devtoolset-10/enable
BuildRequires: devtoolset-10-gcc
%endif
%endif
%if 0%{?el8}
%define _devtoolset_enable /opt/rh/gcc-toolset-10/enable
BuildRequires: gcc-toolset-10-gcc
%endif
%if 0%{?el9}
BuildRequires: gcc
%endif
%if 0%{?fedora}
BuildRequires: gcc
%endif
BuildRequires: make

%global _vespa_3rdparty_deps_packaging_notice \
See https://github.com/vespa-engine/vespa-3rdparty-deps for details \
about packaging.

%description
zstd compiled for vespa
%{_vespa_3rdparty_deps_packaging_notice}

%package -n vespa-libzstd
Summary:        zstd compiled for vespa -- library

%description -n vespa-libzstd
zstd compiled for vespa -- library
%{_vespa_3rdparty_deps_packaging_notice}

%package -n vespa-libzstd-devel
Summary:        zstd compiled for vespa -- devel
Requires:       vespa-libzstd%{?_isa} = %{version}-%{release}

%description -n vespa-libzstd-devel
zstd compiled for vespa -- devel
%{_vespa_3rdparty_deps_packaging_notice}

%prep
%setup -n zstd-%{version}
sed -i 's,-O3,-O3 -g -fno-omit-frame-pointer,g' $(find . -name Makefile -print)

%build
%if 0%{?_devtoolset_enable:1}
source %{_devtoolset_enable} || true
%endif
%make_build LIBDIR=%{_libdir} PREFIX=%{_prefix} %{?_toolset_compiler_args}

%install
%if 0%{?_devtoolset_enable:1}
source %{_devtoolset_enable} || true
%endif
%make_install LIBDIR=%{_libdir} PREFIX=%{_prefix} %{?_toolset_compiler_args}

%files
%license COPYING LICENSE
%doc CHANGELOG README.md
%{_bindir}
%{_mandir}

%files -n vespa-libzstd
%license COPYING LICENSE
%{_libdir}
%exclude %{_libdir}/*.so
%exclude %{_libdir}/libzstd.a

%files -n vespa-libzstd-devel
%{_includedir}
%{_libdir}/*.so

%changelog