SUMMARY="A C library for asynchronous DNS requests"
DESCRIPTION="Avahi is a free, LGPL implementation of DNS Service Discovery \
(DNS-SD RFC 6763) over Multicast DNS (mDNS RFC 6762), commonly known as and \
compatible with Apple Bonjour primarily targetting Linux."
HOMEPAGE="http://avahi.org/"
COPYRIGHT="2004-2015 the Avahi developers"
LICENSE="GNU LGPL v2.1"
REVISION="1"
srcGitRev="e8a3dd0d480a754318e312e6fa66fea249808187"
SOURCE_URI="https://github.com/lathiat/avahi/archive/$srcGitRev.tar.gz"
CHECKSUM_SHA256="09e3f0aaf05a174776b22b0cff0fed42adea1ba39fd5ff10a5660f3f97aa947c"
SOURCE_DIR="avahi-$srcGitRev"
PATCHES="avahi-$portVersion.patchset"

GLOBAL_WRITABLE_FILES="
	settings/avahi/avahi-daemon.conf keep-old
	settings/avahi/avahi-dnsconfd.action keep-old
	settings/avahi/hosts keep-old
	settings/avahi/services/sftp-ssh.service keep-old
	settings/avahi/services/ssh.service keep-old
	settings/dbus-1/system.d/avahi-dbus.conf keep-old
	"
USER_SETTINGS_FILES="
	settings/avahi directory
	"
avahiUserHomeDir="/packages/$portVersionedName-$REVISION/.self/$relativeDataDir/avahi/empty"

PACKAGE_USERS="
	avahi real-name \"avahi user\" home \"$avahiUserHomeDir\" shell \"/bin/true\" groups \"avahi\"
	"
PACKAGE_GROUPS="avahi"

ARCHITECTURES="?all !x86_gcc2"
SECONDARY_ARCHITECTURES="?x86"

# On x86_gcc2 we don't want to install the commands in bin/<arch>/, but in bin/.
commandSuffix=$secondaryArchSuffix
commandBinDir=$binDir
if [ "$targetArchitecture" = x86_gcc2 ]; then
	commandSuffix=
	commandBinDir=$prefix/bin
fi

PROVIDES="
	avahi$secondaryArchSuffix = $portVersion
	lib:libavahi_client$secondaryArchSuffix = 3.2.9 compat >= 3
	lib:libavahi_common$secondaryArchSuffix = 3.5.4 compat >= 3
	lib:libavahi_core$secondaryArchSuffix = 7.1.0 compat >= 7
	lib:libavahi_glib$secondaryArchSuffix = 1.0.2 compat >= 1
	lib:libavahi_gobject$secondaryArchSuffix = 0.0.5 compat >= 0
	lib:libavahi_libevent$secondaryArchSuffix = 1.0.0 compat >= 1
	lib:libavahi_qt5$secondaryArchSuffix = 1.0.2 compat >= 1
	cmd:avahi_browse
	cmd:avahi_browse_domains
	cmd:avahi_daemon
	cmd:avahi_dnsconfd
	cmd:avahi_publish
	cmd:avahi_publish_address
	cmd:avahi_publish_service
	cmd:avahi_resolve
	cmd:avahi_resolve_address
	cmd:avahi_resolve_host_name
	cmd:avahi_set_host_name
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libdbus_1$secondaryArchSuffix
	lib:libevent_2.1$secondaryArchSuffix
	lib:libexpat$secondaryArchSuffix
	lib:libglib_2.0$secondaryArchSuffix
	lib:libgobject_2.0$secondaryArchSuffix
	lib:libintl$secondaryArchSuffix
	lib:libQt5Core$secondaryArchSuffix
	"

PROVIDES_devel="
	avahi${secondaryArchSuffix}_devel = $portVersion
	devel:libavahi_client$secondaryArchSuffix = 3.2.9 compat >= 3
	devel:libavahi_common$secondaryArchSuffix = 3.5.4 compat >= 3
	devel:libavahi_core$secondaryArchSuffix = 7.1.0 compat >= 7
	devel:libavahi_glib$secondaryArchSuffix = 1.0.2 compat >= 1
	devel:libavahi_gobject$secondaryArchSuffix = 0.0.5 compat >= 0
	devel:libavahi_libevent$secondaryArchSuffix = 1.0.0 compat >= 1
	devel:libavahi_qt5$secondaryArchSuffix = 1.0.2 compat >= 1
	"
REQUIRES_devel="
	avahi$secondaryArchSuffix == $portVersion base
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libdaemon$secondaryArchSuffix
	devel:libdbus_1$secondaryArchSuffix
	devel:libevent_2.1$secondaryArchSuffix
	devel:libexpat$secondaryArchSuffix
	devel:libglib_2.0$secondaryArchSuffix
	devel:libpcap$secondaryArchSuffix
	devel:libQt5Core$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:aclocal
	cmd:autoconf
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:libtoolize$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	cmd:sed
	cmd:which
	"

BUILD()
{
	autoreconf -fi
	runConfigure --omit-dirs binDir ./configure --bindir=$commandBinDir \
		--disable-gtk3 --disable-gtk \
		--disable-gdbm --disable-python --disable-autoipd \
		--disable-mono --disable-manpages --disable-stack-protector \
		--localstatedir=$prefix/var/run
	make $jobArgs
}

INSTALL()
{
	make install

	# remove libtool files
	rm $libDir/lib*.la

	prepareInstalledDevelLibs libavahi-client libavahi-common \
		libavahi-core libavahi-glib libavahi-gobject libavahi-libevent \
		libavahi-qt5
	fixPkgconfig

	packageEntries devel \
		"$developDir"
}
