# Maintainer: Biswapriyo Nath <nathbappai@gmail.com>

_realname=bzip3
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.5.3
pkgrel=1
pkgdesc='A better and stronger spiritual successor to BZip2 (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://github.com/iczelia/bzip3'
msys2_changelog_url='https://github.com/iczelia/bzip3/blob/master/NEWS'
msys2_references=(
  'anitya: 301351'
  'archlinux: bzip3'
  'cpe: cpe:2.3:a:bzip3_project:bzip3'
  'gentoo: app-arch/bzip3'
)
license=('spdx:LGPL-3.0-or-later OR Apache-2.0')
depends=("${MINGW_PACKAGE_PREFIX}-libwinpthread")
makedepends=("${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-cc")
source=(https://github.com/iczelia/bzip3/releases/download/${pkgver}/bzip3-${pkgver}.tar.xz)
sha256sums=('58a53d002eb80c6f74c292ddf37d4f53604f6e2126cb3ae2bff738971302aa85')

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

  # For clang
  autoreconf -fiv
}

build() {
  cd "${srcdir}/${_realname}-${pkgver}"
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  CFLAGS+=" -D_GNU_SOURCE" \
  ../"${_realname}-${pkgver}"/configure \
    --prefix="${MINGW_PREFIX}" \
    --build="${MINGW_CHOST}" \
    --host="${MINGW_CHOST}" \
    --target="${MINGW_CHOST}" \
    --enable-static \
    --enable-shared

  make
}

check() {
  cd "${srcdir}/build-${MSYSTEM}"
  make check
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  make install DESTDIR="${pkgdir}"
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
