#!/usr/bin/bash
# JOBoRun		: Jwm OpenBox Obarun RUNit
# Maintainer	: Joe Bo Run <joborun@disroot.org>
# PkgSource		: url="https://gittea.disroot.org/joborun-pkg/jobextra/$pkgname"
# Website		: https://pozol.eu
#-----------------------------------------| DESCRIPTION |---------------------------------------

pkgname=libgit2
pkgver=1.6.4
pkgrel=01
epoch=1
pkgdesc="A linkable library for Git"
url="https://github.com/libgit2/libgit2"
depends=(gcc-libs glibc http-parser zlib)
makedepends=(cmake libssh2 openssl python pcre2)
provides=(libgit2.so)
source=($url/archive/v$pkgver/$pkgname-v$pkgver.tar.gz)
#	$pkgname-1.5.0-remove_http-parse_incompatible_tests.patch)

#prepare() {
#  # remove tests that are only compatible with the (modified) vendored version
#  # of http-parser, but not with upstream http-parser
#  patch -d $pkgname-$pkgver -Np1 -i ../$pkgname-1.5.0-remove_http-parse_incompatible_tests.patch
#}

build() {
  local cmake_options=(
    -B build
    -DCMAKE_BUILD_TYPE=None
    -DCMAKE_INSTALL_PREFIX=/usr
    -DREGEX_BACKEND=pcre2
    -DUSE_HTTP_PARSER=system
    -DUSE_SSH=ON
    -S $pkgname-$pkgver
    -Wno-dev
  )

  cmake "${cmake_options[@]}"
  cmake --build build --verbose
}

check() {
  local ignored_tests=(
    'invasive|'
    'online|'
    'ssh|'
    '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'
  )
  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"
}

package() {
  depends+=(
    libssh2 libssh2.so
    openssl libcrypto.so libssl.so
    pcre2 libpcre2-8.so
  )

  DESTDIR="$pkgdir" cmake --install build
  install -vDm 644 $pkgname-$pkgver/{AUTHORS,README.md} -t "$pkgdir/usr/share/doc/$pkgname/"
}

#---- arch license gpg-key & sha256sums ----

arch=(x86_64)

license=(GPL2)

sha512sums=('fd73df91710f19b0d6c3765c37c7f529233196da91cf4d58028a8d3840244f11df44abafabd74a8ed1cbe4826d1afd6ff9f01316d183ace0924c65e7cf0eb8d5')

sha256sums=(d25866a4ee275a64f65be2d9a663680a5cf1ed87b7ee4c534997562c828e500d) # libgit2-v1.6.4.tar.gz

##  d38f531f4b24b689819016c5a7cb993674dd0cc1d41b197fea0ee7d4dc413afd  libgit2-1:1.6.4-01-x86_64.pkg.tar.lz
