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

_realname=apr-util
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.6.1
pkgrel=2
pkgdesc="The Apache Portable Runtime (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://apr.apache.org/"
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-libtool")
depends=("${MINGW_PACKAGE_PREFIX}-apr"
         "${MINGW_PACKAGE_PREFIX}-expat"
         "${MINGW_PACKAGE_PREFIX}-libmariadbclient"
         "${MINGW_PACKAGE_PREFIX}-sqlite3"
         "${MINGW_PACKAGE_PREFIX}-unixodbc"
         "${MINGW_PACKAGE_PREFIX}-postgresql"
         "${MINGW_PACKAGE_PREFIX}-openldap"
         "${MINGW_PACKAGE_PREFIX}-nss"
         "${MINGW_PACKAGE_PREFIX}-gdbm"
         "${MINGW_PACKAGE_PREFIX}-openssl")
license=('APACHE')
source=(https://www.apache.org/dist/apr/${_realname}-${pkgver}.tar.bz2
        'plugins.patch'
        'fix-dll-build.patch'
		'002-add_mod-static.patch')
sha256sums=('d3e12f7b6ad12687572a3a39475545a072608f4ba03a6ce8a3778f607dd0035b'
            'd79c9202ce6ddc9a67a671ec5bcf495672330a4fa7e29446fa54db793f3f09fe'
            'b33b18e612f54ea15c9303aede19e4a2b9ec2550fd081add61d13eff6446d44a'
			'69a356e706619b48ebaeabef53bae4f6eaed45f1a61a20f4b230f2faa1f3124e')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -Np1 -i "${srcdir}/plugins.patch"
  patch -Np1 -i "${srcdir}/fix-dll-build.patch"
  patch -Np1 -i "${srcdir}/002-add_mod-static.patch"
  
  #./buildconf --with-apr=${MINGW_PREFIX}
  autoreconf -fi
}

build() {
  [[ -d build-${MINGW_CHOST} ]] && rm -rf build-${MINGW_CHOST}
  mkdir -p build-${MINGW_CHOST}
  cd build-${MINGW_CHOST}
  APRUTIL_LDFLAGS+=" -L${MINGW_PREFIX}/${MINGW_CHOST}/lib -R${MINGW_PREFIX}/${MINGW_CHOST}/lib" \
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --with-apr=${MINGW_PREFIX} \
    --with-expat=${MINGW_PREFIX} \
    --with-iconv=${MINGW_PREFIX} \
    --with-crypto \
    --with-openssl=yes \
    --with-nss=yes \
    --with-dbm=gdbm \
    --with-gdbm=yes \
    --with-berkeley-db=no \
    --with-pgsql=yes \
    --with-sqlite3=yes \
    --with-ldap=yes \
    --with-oracle=no \
    --with-sqlite2=no \
    --with-mysql=yes \
    --with-odbc=yes \
    --with-commoncrypto=no

  make -j1
}

check() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  # in case of failing tests
  make -j1 check || true
}

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