# Maintainer: Jeroen Ooms <jeroen@berkeley.edu>

_realname=argtable
pkgbase="mingw-w64-${_realname}"
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.13
intver=${pkgver//./-}
pkgrel=3
pkgdesc="ANSI C library for parsing GNU-style command-line options (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
license=("custom")
url="https://argtable.sourceforge.io"
source=("https://downloads.sourceforge.net/project/argtable/argtable/${_realname}-${pkgver}/${_realname}${intver}.tar.gz"
        "001-missing-ctype.patch"
        "002-recognize-aarch64.patch")
sha256sums=('8f77e8a7ced5301af6e22f47302fdbc3b1ff41f2b83c43c77ae5ca041771ddbf'
            'e487bf08f7d3d400e6a39f730da5af3ecd2ea239ccee348d5fc97881a9e76520'
            '4d635e457283396e381964c232097a1c4423ad611afd4411390f03d04e2c3cc6')
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools")


prepare() {
  cd "${srcdir}"/${_realname}${intver}
  sed -i.bak 's/EOVERFLOW/MYEOVERFLOW/g' src/arg_int.c

  patch -Np1 -i "${srcdir}/001-missing-ctype.patch"
  patch -Np1 -i "${srcdir}/002-recognize-aarch64.patch"
}

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

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

  make
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  make DESTDIR="${pkgdir}" install
}
