# Maintainer: Diego Sogari <diego.sogari@gmail.com>

_realname=lmdb
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.9.27
pkgrel=1
pkgdesc="Lightning Memory-mapped Database (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://symas.com/mdb/"
license=('custom')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
source=("${_realname}-${pkgver}.tar.gz::https://git.openldap.org/openldap/openldap/-/archive/LMDB_${pkgver}/openldap-LMDB_${pkgver}.tar.gz"
        001-mingw-build.patch
        lmdb.pc)
sha256sums=('752a3ebd4bbfa1830dff2ca4f5ff4c4be97da843810626d5dd9e2e4e5484a399'
            'db1d1934131e8b978b734c156b328d0c8c45b7c3ec6a47d544ece1377d77cd14'
            '4604bf63de206ac99b8f89ab6fa2cf0d52a29fc914411ccd51a357485b6fe699')

prepare() {
  cd "${srcdir}/openldap-LMDB_${pkgver}"
  patch -p1 -i ${srcdir}/001-mingw-build.patch
}

build() {
  cd "${srcdir}/openldap-LMDB_${pkgver}/libraries/liblmdb"
  make clean
  make
}

check() {
  cd "${srcdir}/openldap-LMDB_${pkgver}/libraries/liblmdb"
  make test
}

package() {
  cd "${srcdir}/openldap-LMDB_${pkgver}/libraries/liblmdb"
  make prefix=${MINGW_PREFIX} DESTDIR="${pkgdir}" install

  sed -s "s|@PREFIX@|${MINGW_PREFIX}|g" -i "${srcdir}"/lmdb.pc
  sed -s "s|@PKGVER@|${pkgver}|g" -i "${srcdir}"/lmdb.pc

  install -Dm644 LICENSE "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
  install -Dm644 "${srcdir}"/lmdb.pc "${pkgdir}"${MINGW_PREFIX}/lib/pkgconfig/lmdb.pc
}
