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

pkgname=('gdbm' 'libgdbm' 'libgdbm-devel')
pkgver=1.26
pkgrel=1
pkgdesc="GNU database library"
url="https://www.gnu.org/software/gdbm/gdbm.html"
msys2_repository_url="https://git.savannah.gnu.org/cgit/gdbm.git"
license=('GPL3')
arch=('i686' 'x86_64')
makedepends=('libreadline-devel' 'autotools' 'gcc' 'gettext-devel' 'libiconv-devel' 'ncurses-devel')
source=(https://ftp.gnu.org/gnu/gdbm/${pkgname}-${pkgver}.tar.gz{,.sig}
        1.10-no-undefined.patch
        0001-missing-include.patch)
options=('!makeflags')
sha256sums=('6a24504a14de4a744103dcb936be976df6fbe88ccff26065e54c1c47946f4a5e'
            'SKIP'
            'b2d661b1365fde38e4ed1796433767ed61b3be72f3b6c48b3d27e4004db01877'
            '9fbde56f54e5e27e7c4c244f588224d3fba90dc6fb456a34db57e37ccf10f028')
validpgpkeys=('4BE4E62655488EB92ABB468F79FFD94BFCE230B1') # Sergey Poznyakoff <gray@gnu.org>

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

  patch -Np2 -i ${srcdir}/1.10-no-undefined.patch
  patch -Np1 -i ${srcdir}/0001-missing-include.patch

  autoreconf -fiv
}

build() {
  cd "${srcdir}/${pkgname}-${pkgver}"

  ./configure \
    --prefix=/usr \
    --build=${CHOST} \
    --enable-libgdbm-compat \
    COMPATINCLUDEDIR=/usr/include/gdbm

  make
  make DESTDIR=${srcdir}/dest install
}

check() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  make check || true
}

package_gdbm() {
  depends=("libgdbm=${pkgver}")
  groups=('Database')

  mkdir -p ${pkgdir}/usr/{bin,share}

  cp -f ${srcdir}/dest/usr/bin/*.exe ${pkgdir}/usr/bin/
  #cp -rf ${srcdir}/dest/usr/share/doc ${pkgdir}/usr/share/
  cp -rf ${srcdir}/dest/usr/share/info ${pkgdir}/usr/share/
  cp -rf ${srcdir}/dest/usr/share/locale ${pkgdir}/usr/share/
  cp -rf ${srcdir}/dest/usr/share/man ${pkgdir}/usr/share/
}

package_libgdbm() {
  depends=('gcc-libs' 'libreadline' 'libiconv' 'libintl' 'ncurses')
  groups=('libraries')

  mkdir -p ${pkgdir}/usr/bin
  cp -f ${srcdir}/dest/usr/bin/*.dll ${pkgdir}/usr/bin/
}

package_libgdbm-devel() {
  pkgdesc="libgdbm headers and libraries"
  options=('staticlibs')
  depends=("libgdbm=${pkgver}" 'libreadline-devel')
  groups=('development')

  mkdir -p ${pkgdir}/usr
  cp -rf ${srcdir}/dest/usr/include ${pkgdir}/usr/
  cp -rf ${srcdir}/dest/usr/lib ${pkgdir}/usr/
}
