# 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.]*\\([A-Za-z._0-9]*\\)\\(64bit\\)|pkgconfig\\(.*)$

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

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

Name:           vespa-brpc
Summary:        An industrial-grade RPC framework used throughout Baidu, with 1,000,000+ instances(not counting clients) and thousands kinds of services.
Version:        %{ver_major}.%{ver_minor}.%{ver_patch}
Release:        %{ver_release}%{?dist}

Group:          Development
License:        Apache2
URL:            https://github.com/apache/incubator-brpc
Source0:        https://github.com/apache/incubator-brpc/archive/refs/tags/%{version}.tar.gz
Patch0:         patches.remove_log.diff

# https://access.redhat.com/solutions/519993
%global  _filter_GLIBC_PRIVATE 1
%global __filter_GLIBC_PRIVATE 1

%if 0%{?el7}
BuildRequires: gflags-devel >= 2.1
BuildRequires: leveldb-devel
BuildRequires: vespa-protobuf-devel >= 3.19.1-1.el7
BuildRequires: vespa-openssl-devel >= 1.1.1n-1
BuildRequires: cmake3
%define _cmake_prog cmake3
%if 0%{?amzn2}
BuildRequires: gcc10-c++%{?_isa}
%define _configure_args CC=gcc10-gcc CXX=gcc10-g++ CC_FOR_BUILD=gcc10-gcc CXX_FOR_BUILD=gcc10-g++
%else
%define _devtoolset_enable /opt/rh/devtoolset-10/enable
BuildRequires: devtoolset-10-gcc-c++%{?_isa}
%endif
%endif

%description
An industrial-grade RPC framework used throughout Baidu, with 1,000,000+ instances(not counting clients) and thousands kinds of services.
"brpc" means "better RPC".

%package devel
Summary: The %{name} headers and shared development libraries
Requires: %{name} = %{version}-%{release}

%description devel
Headers and shared object symbolic links for the %{name} library.

%prep
%setup -q -n incubator-brpc-%{version}
%patch0 -p1

%build
%if 0%{?_devtoolset_enable:1}
source %{_devtoolset_enable} || true
%endif

mkdir -p build && cd build
%{_cmake_prog} ..  -DCMAKE_INSTALL_PREFIX=%{_prefix} \
                   -DCMAKE_INSTALL_RPATH=%{_prefix}/lib64 \
                   -DCMAKE_BUILD_WITH_INSTALL_RPATH=true \
                   -DCMAKE_PREFIX_PATH=/opt/vespa-deps

make %{?_smp_mflags}

%install
%if 0%{?_devtoolset_enable:1}
source %{_devtoolset_enable} || true
%endif
cd build
%make_install

%define _unpackaged_files_terminate_build 0

%clean
rm -rf $RPM_BUILD_ROOT

%files
%{_libdir}/libbrpc.so
%{_bindir}/*

%files devel
%{_includedir}/*
%{_libdir}/pkgconfig/*

%changelog