%global with_mingw 0

%global realname nghttp2
%global _prefix /opt/rx
%global _libdir %{_prefix}/%{_lib}
%global _includedir %{_prefix}/include
%global _libexecdir %{_prefix}/libexec
%global _datadir %{_prefix}/share
%global _mandir %{_datadir}/man

Summary: Experimental HTTP/2 client, server and proxy
Name: rx-nghttp2
Version: 1.62.1
Release: 1%{?dist}

# Parts of ruby bindings are additionally under GPL-2.0-or-later, MIT and
# HPND-Kevlin-Henney but they are NOT shipped.
License: MIT

URL: https://nghttp2.org/
Source0: https://github.com/tatsuhiro-t/nghttp2/releases/download/v%{version}/nghttp2-%{version}.tar.xz

BuildRequires: CUnit-devel
BuildRequires: c-ares-devel
%if 0%{?rhel} >= 8
BuildRequires: clang
%else
BuildRequires: gcc-c++
%endif
BuildRequires: libev-devel
BuildRequires: libxml2-devel
BuildRequires: make
BuildRequires: pkgconfig(openssl) >= 3.0
BuildRequires: python3.11-devel python3.11-rpm-macros
BuildRequires: zlib-devel

# For gpg verification of source tarball
BuildRequires: gnupg2



%description
This package contains the HTTP/2 client, server and proxy programs.


%package -n rx-libnghttp2
Summary: A library implementing the HTTP/2 protocol

%description -n rx-libnghttp2
libnghttp2 is a library implementing the Hypertext Transfer Protocol
version 2 (HTTP/2) protocol in C.


%package -n rx-libnghttp2-devel
Summary: Files needed for building applications with libnghttp2
Requires: rx-libnghttp2%{?_isa} = %{version}-%{release}
Requires: pkgconfig

%description -n rx-libnghttp2-devel
The libnghttp2-devel package includes libraries and header files needed
for building applications with libnghttp2.



%prep
%autosetup -p1 -n %{realname}-%{version}

%build
export PKG_CONFIG_PATH=%{_libdir}/pkgconfig${PKG_CONFIG_PATH:+:${PKG_CONFIG_PATH}}
export LDFLAGS="-L%{_libdir} -Wl,-rpath=%{_libdir} ${LDFLAGS:-%__global_ldflags}"
%if 0%{?rhel} >= 8
export CC=clang
export CXX=clang++
%endif

mkdir build
pushd build
%define _configure ../configure
%configure PYTHON=%{__python3}              \
    --disable-hpack-tools                   \
    --disable-python-bindings               \
    --disable-static                        \
    --with-libxml2

# avoid using rpath
sed -i libtool                              \
    -e 's/^runpath_var=.*/runpath_var=/'    \
    -e 's/^hardcode_libdir_flag_spec=".*"$/hardcode_libdir_flag_spec=""/'

%make_build
popd


%install
pushd build
%make_install


# not needed on Fedora/RHEL
rm -f "$RPM_BUILD_ROOT%{_libdir}/libnghttp2.la"

# will be installed via %%doc
rm -f "$RPM_BUILD_ROOT%{_datadir}/doc/nghttp2/README.rst"

rm -rf %{buildroot}%{_bindir}
rm -rf %{buildroot}%{_mandir}
rm -rf %{buildroot}%{_unitdir}
rm -f %{buildroot}%{_datadir}/nghttp2/fetch-ocsp-response

%ldconfig_scriptlets -n rx-libnghttp2

%files -n rx-libnghttp2
%{_libdir}/libnghttp2.so.*
%{!?_licensedir:%global license %%doc}
%license COPYING

%files -n rx-libnghttp2-devel
%{_includedir}/nghttp2
%{_libdir}/pkgconfig/libnghttp2.pc
%{_libdir}/libnghttp2.so
%doc README.rst
