# Template file for 'avahi'
pkgname=avahi
version=0.8
revision=2
build_style=gnu-configure
configure_args="--disable-qt3 --disable-qt4 --disable-qt5
 --disable-libevent --disable-mono --disable-monodoc
 --disable-doxygen-doc --enable-compat-libdns_sd --enable-compat-howl
 --with-xml=expat --with-avahi-user=avahi --with-avahi-group=avahi
 --with-avahi-priv-access-group=network --with-autoipd-user=avahi
 --with-autoipd-group=avahi --with-distro=none --disable-xmltoman
 --disable-static ssp_cv_lib=no --enable-python --disable-pygobject
 --disable-glib --disable-python-dbus --disable-gobject --disable-gtk
 --disable-gtk3 --disable-dbm --disable-introspection --sbindir=/usr/bin
 --with-dbus-system-address=unix:path=/run/dbus/system_bus_socket
 --without-systemdsystemunitdir"
short_desc="Multicast DNS Service Discovery"
maintainer="Andrew J. Hesford <ajh@sideband.org>"
license="LGPL-2.1-or-later"
homepage="https://github.com/lathiat/avahi"
### NOTE: The Avahi 0.8 release tarball is broken; it is missing the build-db
### script. Fetching and manipulation of this file in post_extract should be
### undone in a future release that fixes this oversight.
_build_db="service-type-database/build-db"
distfiles="${homepage}/releases/download/v${version}/avahi-${version}.tar.gz
 https://raw.githubusercontent.com/lathiat/${pkgname}/v${version}/${_build_db}>build-db.txt"
checksum="060309d7a333d38d951bc27598c677af1796934dbd98e1024e7ad8de798fedda
 83edd888ccc464ab032134a45b7ded3bc43cb1dda2cd921ff47b01949d98ed7c"
skip_extraction="build-db.txt"

hostmakedepends="pkg-config gettext python3"
makedepends="dbus-devel libcap-devel libdaemon-devel gdbm-devel"
conf_files="
	/etc/avahi/services/ssh.service
	/etc/avahi/services/sftp-ssh.service
	/etc/avahi/avahi-daemon.conf
	/etc/avahi/hosts
	/etc/avahi/avahi-dnsconfd.action"
system_accounts="avahi:23"

if [ "$CROSS_BUILD" ]; then
	hostmakedepends+=" automake libtool glib-devel gettext-devel"
	pre_configure() {
		autoreconf -if
	}
fi

post_extract() {
	# Avahi 0.8 release accidentally left this out of the tarball
	cp ${XBPS_SRCDISTDIR}/${pkgname}-${version}/build-db.txt "${_build_db}"
}

post_install() {
	# Python modules will be built in avahi-discover subpackage
	rm -rf ${DESTDIR}/usr/lib/python*
	# Man page will be installed in avahi-discover subpackage
	rm -f ${DESTDIR}/usr/share/man/man1/avahi-bookmarks.1

	# Set 'enable-dbus=warn' option by default to not require dbus.
	vsed -e 's,\#\(enable-dbus\).*,\1=warn,' -i ${DESTDIR}/etc/avahi/avahi-daemon.conf
	vsv avahi-daemon
}

avahi-autoipd_package() {
	depends="net-tools"
	short_desc="Avahi IPv4LL network address configuration daemon"
	pkg_install() {
		vmove usr/bin/avahi-autoipd
		vmove "usr/share/man/man8/avahi-autoipd*"
		vmove etc/avahi/avahi-autoipd.action
	}
}

avahi-compat-libs-devel_package() {
	depends="avahi-libs-devel>=${version}_${revision} avahi-compat-libs>=${version}_${revision}"
	short_desc="Avahi compat libraries - development files"
	pkg_install() {
		vmove "usr/include/avahi-compat*"
		vmove "usr/lib/pkgconfig/avahi-compat*"
		vmove usr/lib/libhowl.so
		vmove usr/lib/libdns_sd.so
	}
}

avahi-compat-libs_package() {
	short_desc="Avahi compatiblity shared libraries"
	pkg_install() {
		vmove "usr/lib/libhowl.so.*"
		vmove "usr/lib/libdns_sd.so.*"
	}
}

avahi-libs-devel_package() {
	depends="dbus-devel avahi-libs>=${version}_${revision}"
	short_desc="Avahi core libraries - development files"
	pkg_install() {
		for f in common client core; do
			vmove usr/include/avahi-${f}
		done
		vmove usr/lib/pkgconfig/avahi-core.pc
		vmove usr/lib/pkgconfig/avahi-client.pc
		vmove usr/lib/libavahi-client.so
		vmove usr/lib/libavahi-core.so
		vmove usr/lib/libavahi-common.so
	}
}

avahi-libs_package() {
	short_desc="Avahi shared libraries"
	pkg_install() {
		vmove "usr/lib/libavahi-client.so.*"
		vmove "usr/lib/libavahi-core.so.*"
		vmove "usr/lib/libavahi-common.so.*"
	}
}

avahi-utils_package() {
	short_desc="Avahi browsing, publishing and discovery utilities"
	pkg_install() {
		vmove usr/bin/avahi-browse*
		vmove usr/bin/avahi-publish*
		vmove usr/bin/avahi-resolv*
		vmove usr/share/man/man1
	}
}
