# Maintainer: Yasuhiro MATSUMOTO <mattn.jp@gmail.com>

pkgname=znc
pkgver=1.10.1
pkgrel=2
pkgdesc='An IRC bouncer with modules & scripts support'
url='https://znc.in/'
msys2_repository_url="https://github.com/znc/znc"
msys2_references=(
  "cpe: cpe:/a:znc:znc"
)
license=('spdx:Apache-2.0')
arch=('i686' 'x86_64')
replaces=('znc-git')
conflicts=('znc-git')
depends=('openssl' 'icu')
makedepends=('cmake'
             'cyrus-sasl'
             'gettext-devel'
             'git'
             'icu-devel'
             'libsasl-devel'
             'perl'
             'python'
             'swig'
             'gcc'
             #'tcl'
             'ninja'
             )
optdepends=('tcl: modtcl module'
            'python: modpython module'
            'perl: modperl module'
            'cyrus-sasl: cyrusauth module')
source=(znc-${pkgver}::git+https://github.com/znc/znc.git#tag=znc-${pkgver})
sha256sums=('9da4ea858bc1d4b0f20f610121037f3296a2d37ca7687162f98386503422238d')

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

  git submodule update --init --recursive
}

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

  cmake \
    -GNinja \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DBUILD_SHARED_LIBS=OFF \
    -DCMAKE_BUILD_TYPE=Release \
    -DWANT_CYRUS=ON \
    -DWANT_PERL=ON \
    -DWANT_PYTHON=ON \
    -DWANT_I18N=OFF \
    ../${pkgname}-${pkgver}
  cmake --build .
}

package() {
  cd "${srcdir}/build-${CARCH}"
  DESTDIR="${pkgdir}" cmake --install .

  python3 -m compileall -o 0 -o 1 -s "${pkgdir}" "${pkgdir}/usr/lib/znc"

  install -Dm644 ${srcdir}/${pkgname}-${pkgver}/LICENSE ${pkgdir}/usr/share/licenses/${_pkgname}/LICENSE
}
