description="Lightweight, easy to configure DNS forwarder and DHCP server"
url="http://www.thekelleys.org.uk/dnsmasq/doc.html"

packager="Great-OS Team"
maintainer="Dania"

name=dnsmasq
version=2.92

makedepends=(dbus gmp libidn2 libnetfilter_conntrack nettle)

source=(http://www.thekelleys.org.uk/$name/$name-$version.tar.xz
        dnsmasq-sysusers.conf
        dnsmasq.service)
      
_build_copts='-DHAVE_DNSSEC -DHAVE_DBUS -DHAVE_LIBIDN2 -DHAVE_CONNTRACK'

build() {
  cd $name-$version

  make \
    CFLAGS="$CPPFLAGS $CFLAGS" \
    LDFLAGS="$LDFLAGS" \
    COPTS="$_build_copts" \
    PREFIX=/usr \
    BINDIR=/usr/bin \
    all-i18n

  cd contrib/lease-tools

  make \
    CFLAGS="$CPPFLAGS $CFLAGS" \
    LDFLAGS="$LDFLAGS" \
    COPTS="$_build_copts" \
    all
}

package() {
  cd $name-$version

  # need to pass COPTS here to avoid rebuilding the binary.
  make \
    COPTS="$_build_copts" \
    PREFIX=/usr \
    BINDIR=/usr/bin \
    DESTDIR=$PKG \
    install install-i18n

  install -Dm0644 dbus/dnsmasq.conf $PKG/usr/share/dbus-1/system.d/dnsmasq.conf
  install -Dm0644 dnsmasq.conf.example $PKG/etc/dnsmasq.conf
  install -Dm0644 $SRC/dnsmasq.service $PKG/usr/lib/systemd/system/dnsmasq.service
  install -Dm0644 $SRC/dnsmasq-sysusers.conf $PKG/usr/lib/sysusers.d/dnsmasq.conf

  # DNSSEC setup
  sed -i 's,%%PREFIX%%,/usr,' $PKG/etc/dnsmasq.conf
  install -Dm0644 "trust-anchors.conf" $PKG/usr/share/dnsmasq/trust-anchors.conf

  install -Dm0755 -t $PKG/usr/bin/ 'contrib/lease-tools/dhcp_'{release{,6},lease_time}
  install -Dm0644 -t $PKG/usr/share/man/man1 'contrib/lease-tools/dhcp_'{release{,6},lease_time}.1
}
