# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

pkgbase=nghttp2
pkgname=("nghttp2" "libnghttp2" "libnghttp2-devel")
pkgver=1.67.1
pkgrel=1
pkgdesc='Framing layer of HTTP/2 is implemented as a reusable C library'
arch=(i686 x86_64)
url='https://nghttp2.org/'
msys2_repository_url="https://github.com/nghttp2/nghttp2"
msys2_references=(
  "cpe: cpe:/a:nghttp2:nghttp2"
  "gentoo: net-libs/nghttp2"
)
depends=("jansson"
         "libevent"
         "libxml2"
         "openssl"
         "libcares"
         "gcc-libs")
makedepends=('jansson-devel' 'libevent-devel' 'openssl-devel' 'libcares-devel' 'zlib-devel' 'autotools' 'gcc' 'make')
license=('spdx:MIT')
source=(https://github.com/nghttp2/nghttp2/releases/download/v$pkgver/nghttp2-${pkgver}.tar.xz)
sha256sums=('153972aad57e7bf9d911666df7613f2390acf37ea7e1a97a0c5567e90f98e830')

prepare() {
  cd nghttp2-${pkgver}

  autoreconf -fiv
}

build() {
  cd nghttp2-${pkgver}

  ./configure \
    --prefix=/usr \
    --build=${CHOST} \
    --enable-static=yes \
    --enable-shared=yes \
    --disable-examples \
    --disable-python-bindings

  make
  make DESTDIR="${srcdir}/dest" install
}

package_nghttp2() {
  depends=('gcc-libs' 'jansson' "libnghttp2=${pkgver}")
  mkdir -p ${pkgdir}/usr/bin
  cp -f ${srcdir}/dest/usr/bin/*.exe ${pkgdir}/usr/bin/
}

package_libnghttp2() {
  pkgdesc='Framing layer of HTTP/2 is implemented as a reusable C library (runtime)'
  depends=('gcc-libs' )
  groups=('libraries')

  mkdir -p ${pkgdir}/usr/bin
  cp -f ${srcdir}/dest/usr/bin/*.dll ${pkgdir}/usr/bin/
  install -Dm644 ${srcdir}/nghttp2-${pkgver}/COPYING "${pkgdir}/usr/share/licenses/libnghttp2/COPYING"
}

package_libnghttp2-devel() {
  pkgdesc="nghttp2 headers and libraries"
  options=('staticlibs')
  depends=("libnghttp2=${pkgver}")
  groups=('development')
  depends+=('jansson-devel' 'libevent-devel' 'openssl-devel' 'libcares-devel')

  mkdir -p ${pkgdir}/usr/bin
  cp -rf ${srcdir}/dest/usr/include ${pkgdir}/usr/
  cp -rf ${srcdir}/dest/usr/lib ${pkgdir}/usr/
  cp -rf ${srcdir}/dest/usr/share ${pkgdir}/usr/
}
