# Contributor: Teemu Nätkinniemi ("teepean") <tnatkinn@gmail.com>

_realname=bcftools
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.22
pkgrel=1
pkgdesc="tools for manipulating next-generation sequencing data (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="http://www.htslib.org/"
msys2_repository_url="https://github.com/samtools/bcftools"
license=('spdx:MIT')
depends=("${MINGW_PACKAGE_PREFIX}-htslib"
         "${MINGW_PACKAGE_PREFIX}-zlib")
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-cc"
  "${MINGW_PACKAGE_PREFIX}-autotools"
)
source=(https://github.com/samtools/bcftools/releases/download/$pkgver/$_realname-$pkgver.tar.bz2)
sha256sums=('f2ab9e2f605b1203a7e9cbfb0a3eb7689322297f8c34b45dc5237fe57d98489f')

prepare() {
  cd $srcdir/$_realname-$pkgver

  # prevent shipped htslib to be used
  rm -rf htslib-$pkgver || exit 1
}

build() {
  cd $srcdir/$_realname-$pkgver

  ./configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --with-htslib=system

  make
}

check() {
  cd $srcdir/$_realname-$pkgver
  make check || warning "Tests failed"
}

package() {
  cd $srcdir/$_realname-$pkgver

  make DESTDIR=$pkgdir install

  install -Dm644 LICENSE $pkgdir${MINGW_PREFIX}/share/licenses/$_realname/LICENSE
}
