# Maintainer: Jan Alexander Steffens (heftig) <jan.steffens@gmail.com>
# Contributor: Gaetan Bisson <bisson@archlinux.org>
# Contributor: Douglas Soares de Andrade <douglas@archlinux.org>

pkgname=avahi
pkgver=0.8+r194+g3f79789
pkgrel=1.1
epoch=1
cross=nf
pkgdesc="Service Discovery for Linux using mDNS/DNS-SD (compatible with Bonjour)"
url="https://github.com/avahi/avahi"
license=(LGPL)
ncxfat_makedepends=(
  dbus
  expat
  gdbm
  glib2
  libcap
  libdaemon
  gobject-introspection
)
ncxfab_makedepends=(
  #doxygen
  base-devel
  git
  which
  #graphviz
  #gtk3
  #libevent
  #python-dbus
  #python-gobject
  #qt5-base
  #xmltoman
)
optdepends=(
  #'gtk3: avahi-discover, avahi-discover-standalone, bshell, bssh, bvnc'
  #'libevent: libevent bindings'
  'nss-mdns: NSS support for mDNS'
  #'python-dbus: avahi-bookmarks, avahi-discover'
  #'python-gobject: avahi-bookmarks, avahi-discover'
  'python-twisted: avahi-bookmarks'
  #'qt5-base: qt5 bindings'
)
backup=(
  $MPKG_BACKUPETCPATH/avahi/{hosts,avahi-daemon.conf,avahi-{autoip,dnsconf}d.action}
  $MPKG_BAREUSRPATH/lib/avahi/service-types.db
)
_commit=3f79789c484518f82c36ff59c0f45abe7e6580a2  # master
source=(
  "git+https://github.com/avahi/avahi#commit=$_commit"
  0001-HACK-Install-fixes.patch
)
b2sums=('SKIP'
        'a15b00c05cce3b6a1479d88b1393cd955a80c669fed03be5f624a8e8701f22fe327bbd42f7563a532ae8ebc39408f3aedfc982c42a2b6141ccc22af96f16293c')

pkgver() {
  cd avahi
  git describe --tags | sed 's/^v//;s/[^-]*-g/r&/;s/-/+/g'
}

prepare() {
  cd avahi

  # https://bugs.archlinux.org/task/47822
  git apply -3 ../0001-HACK-Install-fixes.patch
  
  NOCONFIGURE=1 ./autogen.sh
}

build() {
  local configure_options=(
    --prefix=$MPKG_USRPATH
    --sysconfdir=$MPKG_ETCPATH
    --localstatedir=$MPKG_VARPATH
    --sbindir=$MPKG_USRPATH/bin
    --runstatedir=/run
    --disable-mono
    --enable-compat-libdns_sd
    --with-autoipd-group=avahi
    --with-autoipd-user=avahi
    --with-avahi-priv-access-group=network
    --with-distro=archlinux
    --with-systemdsystemunitdir=$MPKG_USRPATH/lib/systemd/system
    with_dbus_sys=$MPKG_USRPATH/share/dbus-1/system.d
    # additions for bootstrap
    --disable-qt4
    --disable-qt5
    --disable-gtk
    --disable-gtk3
    --disable-pygobject
    --disable-python-dbus
    --disable-manpages
  )

  cd avahi

  ./configure "${configure_options[@]}"
  sed -i -e 's/ -shared / -Wl,-O1,--as-needed\0/g' libtool
  make
}

package() {
  ncxfat_depends=(
    dbus
    expat
    gdbm
    glib2
    libcap
    libdaemon
    libdbus-1.so
  )
  provides=(
    libavahi-{client,common,core,glib,gobject}.so # ,qt5,ui-gtk3,libevent
    libdns_sd.so
  )

  cd avahi
  make DESTDIR="$pkgdir" install

  echo 'u avahi - "Avahi mDNS/DNS-SD daemon"' |
    install -Dm644 /dev/stdin "$pkgdir/usr/lib/sysusers.d/$pkgname.conf"
}

# vim:set sw=2 sts=-1 et:
