# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=gdbm
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.19
pkgrel=5
pkgdesc="GNU database library (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://www.gnu.org/software/gdbm/gdbm.html"
license=('spdx:GPL-3.0-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-cc-libs"
         "${MINGW_PACKAGE_PREFIX}-gettext-runtime"
         "${MINGW_PACKAGE_PREFIX}-libiconv"
         "${MINGW_PACKAGE_PREFIX}-readline")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-gettext-tools")
source=(https://ftp.gnu.org/gnu/gdbm/${_realname}-${pkgver}.tar.gz
        'gdbm-1.15-win32.patch')
sha256sums=('37ed12214122b972e18a0d94995039e57748191939ef74115b1d41d8811364bc'
            '2c3f0ed37482fe874218f4464414b592ebffa8776cca3c20fb0660f0036f4324')
validpgpkeys=('325F650C4C2B6AD58807327A3602B07F55D0C732')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
  patch -Np1 -i "${srcdir}"/gdbm-1.15-win32.patch

  autoreconf --install --force
}

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

  CFLAGS+=" -std=gnu17"
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --enable-static \
    --enable-shared \
    --enable-libgdbm-compat

  make
}

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

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

  install -Dm644 "${srcdir}"/${_realname}-${pkgver}/COPYING \
    "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/COPYING
}
