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

_realname=libproxy
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.4.17
pkgrel=2
pkgdesc="A library that provides automatic proxy configuration management (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://libproxy.github.io/libproxy/"
license=("LGPL")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-python")
options=('staticlibs' 'strip')
source=("${_realname}-${pkgver}.tar.gz::https://github.com/libproxy/libproxy/archive/${pkgver}.tar.gz"
        001-fix-casting-error.patch
        002-fix-win32-close-scoket.patch
        004-allow-bindings.patch
        005-modules.patch
        006-python-site-package-dir.patch)
sha256sums=('88c624711412665515e2800a7e564aabb5b3ee781b9820eca9168035b0de60a9'
            'f20ce4f17c1a858b3eac84a14226c5e368ea581b0b5ab3428f6e1f9d22d44124'
            '10a2ff72e1288014ad1c0e530f82c30cadb6fb5b6221d7544826bd4df758051b'
            'fc1076b89af1f6b4633e5fb86469334eb012773bb970ef925fe74c5dcba45d98'
            '88bbea202de12988953afc839f1b5e37738dc4ea0c7890708aaec1e525a944e9'
            '035efcd364e736f8987ea99d11250b3e2987ba31cefbd434003faf0b3da789b6')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i ${srcdir}/001-fix-casting-error.patch
  patch -p1 -i ${srcdir}/002-fix-win32-close-scoket.patch
  patch -p1 -i ${srcdir}/004-allow-bindings.patch
  patch -p1 -i ${srcdir}/005-modules.patch
  patch -p1 -i ${srcdir}/006-python-site-package-dir.patch
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir ${srcdir}/build-${MINGW_CHOST} && cd ${srcdir}/build-${MINGW_CHOST}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=;-DLIBEXEC_INSTALL_DIR=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"Ninja" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DLIBEXEC_INSTALL_DIR=${MINGW_PREFIX}/lib/libproxy \
    -DCMAKE_SKIP_RPATH=ON \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_CXX_FLAGS="${CXXFLAGS}" \
    -DCMAKE_C_FLAGS="${CFLAGS}" \
    -DWITH_PERL=OFF \
    -DWITH_PYTHON2=OFF \
    -DWITH_PYTHON3=ON \
    ../${_realname}-${pkgver}

  ${MINGW_PREFIX}/bin/cmake.exe --build ./
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake.exe --build ./ --target install
}
