# Maintainer: Alx Sa <cmyk.student@gmail.com>

_realname=libiff
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.1.r60.g0290be4
pkgrel=2
pkgdesc="Portable, extensible parser for the Interchange File Format (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/svanderburg/libiff"
msys2_references=(
  "cpe: cpe:/a:libiff_project:libiff"
)
license=('spdx:MIT')
depends=()
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools"
             'help2man'
             'git')
_appcommit='0290be4ed3df0c1b8e8f5c24012cc75ba8870570'
source=("${_realname}"::"git+https://github.com/svanderburg/libiff.git#commit=$_appcommit"
        0001-libiff-fix-shared-library.patch)
sha256sums=('SKIP'
            'be986e175cbf9e0f2aba6c1a73d6372e172eee95a9d3157ec4c1e60824af8670')

pkgver() {
  cd "${srcdir}/${_realname}"
  printf "0.1.r%s.g%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

prepare() {
  cd "${srcdir}"/${_realname}
  git apply "${srcdir}/0001-libiff-fix-shared-library.patch"

  ./bootstrap
}

build() {
  cd "${srcdir}"/${_realname}

  ./configure \
    --prefix="${MINGW_PREFIX}" \
    --build="${MINGW_CHOST}" \
    --host="${MINGW_CHOST}" \
    --target="${MINGW_CHOST}" \
    --enable-static \
    --enable-shared

  make -j 1
}

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