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

pkgname=('apr-util' 'apr-util-devel')
pkgver=1.6.3
pkgrel=2
pkgdesc="The Apache Portable Runtime"
arch=('i686' 'x86_64')
url="https://apr.apache.org/"
makedepends=('apr-devel' 'libexpat-devel' 'libsqlite-devel' 'autotools' 'gcc' 'libxcrypt-devel')
options=('!libtool')
license=('spdx:Apache-2.0')
source=("https://archive.apache.org/dist/apr/apr-util-${pkgver}.tar.bz2"
        plugins.patch)
sha256sums=('a41076e3710746326c3945042994ad9a4fcac0ce0277dd8fea076fec3c9772b5'
            '3280d6ed8e577b626e60d495856d16f6944c3144c495fe9ed8cad6b39332824c')

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

  patch -p1 -i ${srcdir}/plugins.patch

  autoreconf -fi
}

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

  export MSYSTEM=CYGWIN
  local CYGWIN_CHOST="${CHOST/-msys/-cygwin}"
  ./configure \
    --build=${CYGWIN_CHOST} \
    --prefix=/usr \
    --with-apr=/usr \
    --with-expat=/usr \
    --without-gdbm \
    --without-ldap \
    --without-pgsql \
    --with-sqlite3=/usr

  make -j1
  make DESTDIR="${srcdir}/dest" install
}

check() {
  cd "${srcdir}/apr-util-${pkgver}"
  make -j1 check
}

package_apr-util() {
  depends=('apr' 'expat' 'libsqlite' 'libxcrypt')
  groups=('libraries')

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

package_apr-util-devel() {
  pkgdesc="Libapr-util headers and libraries"
  groups=('development')
  depends=("apr-util=${pkgver}" "apr-devel" "libexpat-devel" "libsqlite-devel")
  options=('staticlibs')

  mkdir -p ${pkgdir}/usr/bin
  cp -f ${srcdir}/dest/usr/bin/*-config ${pkgdir}/usr/bin/
  cp -rf ${srcdir}/dest/usr/include ${pkgdir}/usr/
  cp -rf ${srcdir}/dest/usr/lib ${pkgdir}/usr/
}
