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

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

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 -d $pkgdir${MINGW_PREFIX}/include/bam
  install -Dm644 *.h $pkgdir${MINGW_PREFIX}/include/bam

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