# Contributor: Mehdi Chinoune <mehdi.chinoune@hotmail.com>

_realname=cabextract
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.11
pkgrel=1
pkgdesc="Free Software for extracting Microsoft cabinet files. (mingw-w64)"
arch=('any')
mingw_arch=('ucrt64' 'clang64' 'clangarm64')
url='https://www.cabextract.org.uk'
msys2_repository_url="https://github.com/kyz/libmspack"
license=('spdx:GPL-2.0-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-libiconv"
         "${MINGW_PACKAGE_PREFIX}-libmspack")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools")
source=("https://github.com/kyz/libmspack/archive/v${pkgver}/libmspack-${pkgver}.tar.gz"
        "001-fix-build-on-mingw.patch")
sha256sums=('284e0e51fee991c40e8cbbc0f5e635f99722796a3642a14397989fc00b862f72'
            '8c00c104d7b2be03c85c7c7e66ea7c0973c354695b3f877e199d7e9468e004d6')
noextract=("libmspack-${pkgver}.tar.gz")

prepare() {
  echo "Extracting libmspack-${pkgver}.tar.gz..."
  tar -xzf libmspack-${pkgver}.tar.gz || true

  cd libmspack-${pkgver}/cabextract

  patch -p1 -i "${srcdir}"/001-fix-build-on-mingw.patch

  autoreconf -fiv
}

build() {
  mkdir -p build-${MSYSTEM} && cd build-${MSYSTEM}

  CFLAGS+=" -Wno-int-conversion -Wno-implicit-function-declaration -Wno-incompatible-pointer-types" \
  ../libmspack-${pkgver}/cabextract/configure \
    --prefix="${MINGW_PREFIX}" \
    --with-external-libmspack

  make
}

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

  make install DESTDIR="${pkgdir}"
}
