pkgname=libgit2
pkgver=1.9.2
pkgdesc="A linkable library for Git"
arch=(x86_64)
homepage="https://github.com/libgit2/libgit2"
license=(LicenseRef-GPL-2.0-only-with-linking-exception)
depends=(
  gcc-libs
  glibc
  llhttp
  zlib
)
makedepends=(
  cmake
  libssh2
  openssl
  pcre2
  python
)
sources=("${pkgname}-v${pkgver}.tar.gz")
urls=("${homepage}/archive/v${pkgver}/${sources[0]}")
md5sums=("0764ca3436c81bae7c201b086ad156be")

src_prepare() {
  tar -xf ${distdir}/${sources[0]} --strip-components=1
}

src_build() {
  local cmake_options=(
    -B build
    -D CMAKE_BUILD_TYPE=None
    -D CMAKE_INSTALL_PREFIX=/usr
    -D REGEX_BACKEND=pcre2
    -D USE_HTTP_PARSER=llhttp
    -D USE_SSH=libssh2
    -D USE_GSSAPI=OFF
    -W no-dev
  )
  cmake ${cmake_options[@]}
  cmake --build build
}

src_check(){
  local ignored_tests=(
    'auth_clone|'
    'invasive|'
    'online|'
    'network_url_parse__hostname_implied_root_empty_port|'
    'network_url_parse__hostname_empty_port|'
    'network_url_parse__ipv4_implied_root_empty_port|'
    'network_url_parse__ipv4_empty_port|'
    'network_url_parse__ipv6_implied_root_empty_port|'
    'network_url_parse__ipv6_empty_port|'
    'proxy|'
    'proxy_auto_not_detected|'
    'ssh'
  )
  local ifs="$IFS"
  IFS=
  # NOTE: disable tests requiring the internet, relying on non-existent
  # resources, or those that are only compatible with the (modified) vendored
  # version of http-parser, but not with upstream http-parser
  ctest --test-dir build --output-on-failure -E "${ignored_tests[*]}"
  IFS="$ifs"
}

src_install() {
  DESTDIR="$pkgdir" cmake --install build
  install -vDm 644 ./{AUTHORS,README.md} -t "$pkgdir/usr/share/doc/$pkgname/"
  install -vDm 644 COPYING -t "$pkgdir/usr/share/licenses/$pkgname/"
}
# vim:ft=sh syn=sh et sw=2:
