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

_realname=dnscrypt-proxy
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.6.0
pkgrel=2
pkgdesc="A tool for securing communications between a client and a DNS resolver (mingw-w64)"
arch=(any)
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://dnscrypt.org"
license=('custom:ISC')
depends=("${MINGW_PACKAGE_PREFIX}-libsodium"
         "${MINGW_PACKAGE_PREFIX}-ldns")
makedepends=("${MINGW_PACKAGE_PREFIX}-doxygen"
             "${MINGW_PACKAGE_PREFIX}-gcc")
source=("https://download.dnscrypt.org/${_realname}/${_realname}-${pkgver}.tar.bz2"
        001-outside-source-build.patch)
sha256sums=('e0cce91dc6ab4ed76478579a899b2abb888b1d7ed133cb55294c2f9ce24edc7d'
            '43603ce61b663e17823e529e528a351d31e3665f262e7c749f5a0508fda1fc08')

prepare() {
  cd ${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/001-outside-source-build.patch
  autoreconf -fi
}

build() {
  rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"

  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --sbindir=${MINGW_PREFIX}/bin \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-plugins \
    --with-included-ltdl
  make
}

check() {
  cd ${srcdir}/build-${MINGW_CHOST}
  make -k check
}

package() {
  cd ${srcdir}/build-${MINGW_CHOST}
  make DESTDIR="${pkgdir}" install
  install -Dm644 ${srcdir}/${_realname}-${pkgver}/COPYING "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
