# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Daichi Shinozaki <dsdseg@gmail.com>

pkgname=gdnsd
pkgver=3.8.2
pkgrel=1
pkgdesc="an Authoritative-only DNS server which does geographic balancing, redirection, weighting, and service-state-conscious failover at the DNS layer"
arch=('x86_64')
url="https://gdnsd.org/"
license=('GPL3')
depends=('libev' 'libmaxminddb' 'libsodium' 'libunwind' 'liburcu')
makedepends=('ragel')
checkdepends=('perl-socket6' 'perl-io-socket-inet6' 'perl-http-daemon' 'perl-libwww' 'perl-net-dns')
source=("https://github.com/$pkgname/$pkgname/releases/download/v$pkgver/$pkgname-$pkgver.tar.xz"
        gdnsd.sysusers)
sha512sums=('982d81cf3b4b20c0bbe640b3bd75697aaea08636c89077729def1c053f5cc3515854a46e1f5009367bfcb2671fa6a394152bde68307a92f3ce748a0badefa8d2'
            '8f39c0bed725d298314675b97610d37fc4dee31600c7f096deb38c63dba96e1b0c12239855154ea2c34f0ac3e8f5b7f1a86d9652210859982ab2339949b66e05')

prepare() {
    cd "$pkgname-$pkgver"
    autoreconf -vif
}

build() {
    cd "$pkgname-$pkgver"
    ./configure \
       --prefix=/usr \
      --sbindir=/usr/bin \
      --localstatedir=/ \
      --libexecdir=/usr/lib \
      --sysconfdir=/etc \
      --with-systemdsystemunitdir=/usr/lib/systemd/system
      
    make
}

check() {
    cd "$pkgname-$pkgver"
    # https://github.com/gdnsd/gdnsd/issues/236
    make -k check || echo "Tests failed"
}

package() {
    cd "$pkgname-$pkgver"
    make DESTDIR="$pkgdir/" install
    rm -rf "$pkgdir"/{lib,run}

    install -Dm644 ../gdnsd.sysusers "$pkgdir/usr/lib/sysusers.d/gdnsd.conf"
}
