# Maintainer: David Macek <david.macek.0@gmail.com>

# todo -DBUILD_SHARED_LIBS=ON
_realname=badvpn
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.999.130
pkgrel=4
pkgdesc="NCD scripting language, tun2socks proxifier, P2P VPN (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/ambrop72/badvpn"
license=('spdx:BSD-3-Clause')
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja")
depends=("${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-nspr"
         "${MINGW_PACKAGE_PREFIX}-nss"
         "${MINGW_PACKAGE_PREFIX}-openssl")
source=("https://github.com/ambrop72/badvpn/archive/${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('bfd4bbfebd7274bcec792558c9a2fd60e39cd92e04673825ade5d04154766109')

build() {
  mkdir -p "${srcdir}"/build-${MSYSTEM} && cd "${srcdir}"/build-${MSYSTEM}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G "Ninja" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INCLUDE_PATH="${MINGW_PREFIX}/include/nspr:${MINGW_PREFIX}/include/nss3" \
    -DBUILD_EXAMPLES=OFF \
    -DBUILD_TESTS=OFF \
    ../${_realname}-${pkgver}

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

package() {
  cd "${srcdir}"/build-${MSYSTEM}
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake --install .
  install -Dm644 "${srcdir}"/${_realname}-${pkgver}/COPYING "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/COPYING
}
