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

pkgname=('apr' 'apr-devel')
pkgver=1.7.0
pkgrel=1
pkgdesc="The Apache Portable Runtime"
arch=('i686' 'x86_64')
url="https://apr.apache.org/"
makedepends=('libcrypt-devel' 'libuuid-devel')
options=('!libtool')
license=('APACHE')
source=(https://archive.apache.org/dist/apr/apr-${pkgver}.tar.bz2
      'apr-1.5.0-msys2.patch'
      'binary-copy.patch'
      'no-undefined.patch'
      'tests-disable_testproc.patch'
      'tests-fix_paths.patch'
      'tests.patch'
      'fix-debian-layout.patch')
sha256sums=('e2e148f0b2e99b8e5c6caa09f6d4fb4dd3e83f744aa72a952f94f5a14436f7ea'
            'aea722fe5f21cd7b60aae4aad41d6a9259ffad1fabcb2187ea0ba2f3e6769c48'
            'c2b3002e5afea7c8e48a46d64ec81aa07041e6948c89497a02c22ba1fc8a94d2'
            'b31b1dea25f292e911affd46f2487f275043d6d43926f9f4f491b74efa99021c'
            '3dcedbdfbd2af1945f6a621f51b28353995ddaf3cd61543090dbdbf9981c8163'
            '4c90def2d0fed5abcff1752c3ba8cba5bc6a1a628904df9c7f7d6a72207f7f53'
            '490d7dfeb754aed8dd14d42ed199bdc10e3a2120f2e7fcbf31bcdb3629dc1ccf'
            'edcb695fc87ced48cdeeb747d9b47e8cdd28ad7fcf29fa597c608fcac39621b9')

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

  patch -p1 -i ${srcdir}/binary-copy.patch
  patch -p1 -i ${srcdir}/no-undefined.patch
  patch -p1 -i ${srcdir}/tests-disable_testproc.patch
  patch -p1 -i ${srcdir}/tests.patch
  patch -p1 -i ${srcdir}/tests-fix_paths.patch
  patch -p1 -i ${srcdir}/apr-1.5.0-msys2.patch
  patch -p1 -i ${srcdir}/fix-debian-layout.patch

  autoreconf -fi
}

build() {
  cd "${srcdir}/apr-${pkgver}"
  ./configure --build=${CHOST} \
      --prefix=/usr \
      --libexecdir=/usr/lib/apr/modules \
      --datadir=/usr/share/apr \
      --enable-layout=Debian \
      ac_cv_header_windows_h=no \
      ac_cv_header_winsock2_h=no

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

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

package_apr() {
  depends=('libcrypt' 'libuuid')
  groups=('libraries')

  mkdir -p ${pkgdir}/usr/{bin,share}
  cp -f ${srcdir}/dest/usr/bin/*.dll ${pkgdir}/usr/bin/
  #cp -rf ${srcdir}/dest/usr/share/doc ${pkgdir}/usr/share/
}

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

  mkdir -p ${pkgdir}/usr/{bin,share}
  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/
  cp -rf ${srcdir}/dest/usr/share/apr ${pkgdir}/usr/share/
}
