# Maintainer: Daurnimator <daurnimator@archlinux.org>
# Contributor: Tomas Krizek <tomas.krizek@nic.cz>
# Contributor: Ondřej Surý <ondrej@sury.org>

pkgname=knot-resolver
pkgver=5.4.1
pkgrel=1
pkgdesc='Caching DNSSEC-validating DNS resolver'
arch=('x86_64')
url='https://www.knot-resolver.cz/'
license=('GPL3')
depends=(
    'dnssec-anchors'
    'gnutls'
    'knot'
    'libedit'
    'libuv'
    'lmdb'
    'luajit'
    'libcap-ng'
    'libnghttp2'
    'systemd-libs'
)
makedepends=(
    'cmocka'
    'meson'
)
optdepends=(
    'lua51-basexx: experimental_dot_auth module'
    'lua51-cqueues: http and dns64 module, policy.rpz() function'
    # TODO: 'lua51-etcd: etcd module'
    'lua51-http: http and prefill modules, trust_anchors bootstrap'
    'lua51-psl: policy.slice_randomize_psl() function'
)
backup=('etc/knot-resolver/kresd.conf')
source=("https://secure.nic.cz/files/${pkgname}/${pkgname}-${pkgver}.tar.xz")
sha256sums=('fb8b962dd9ef744e2551c4f052454bc2a30e39c1f662f4f3522e8f221d8e3d66')

build() {
    cd "${pkgname}-${pkgver}"
    arch-meson build \
        -D keyfile_default=/etc/trusted-key.key \
        -D systemd_files=enabled \
        -D client=enabled \
        -D install_kresd_conf=enabled \
        -D unit_tests=enabled
    ninja -C build
}

check() {
    meson test -C "${pkgname}-${pkgver}/build"
}

package() {
    DESTDIR="${pkgdir}" ninja -C "${pkgname}-${pkgver}/build" install

    # add kresd.target to multi-user.target.wants to support enabling kresd services
    mkdir -p "${pkgdir}/usr/lib/systemd/system/multi-user.target.wants/"
    ln -s ../kresd.target "${pkgdir}/usr/lib/systemd/system/multi-user.target.wants/kresd.target"
}
