PORTNAME=	avahi
PORTVERSION=	0.8
PORTREVISION?=	6	# don't delete, reset to 0, check slave ports
CATEGORIES?=	net dns
MASTER_SITES=	http://www.avahi.org/download/
PKGNAMESUFFIX?=	-app-small

MAINTAINER?=	desktop@FreeBSD.org
COMMENT?=	Service discovery on a local network
WWW=		https://www.avahi.org/

LICENSE=	LGPL21+
LICENSE_FILE=	${WRKSRC}/LICENSE

AVAHI_SLAVE?=	no

.if ${AVAHI_SLAVE} != header
LIB_DEPENDS?=	libexpat.so:textproc/expat2 \
		libdaemon.so:devel/libdaemon \
		libdbus-1.so:devel/dbus

USERS?=		${PORTNAME}
GROUPS?=	${USERS}

USES+=		gettext gmake 
USE_LDCONFIG=	yes
GNU_CONFIGURE=	yes
CONFIGURE_ARGS?=--with-distro=freebsd \
		--with-dbus-system-socket=unix:path=/var/run/dbus/system_bus_socket \
		--disable-static \
		--disable-monodoc \
		--disable-doxygen-doc \
		--disable-doxygen-dot \
		--disable-qt3 \
		--disable-qt4 \
		--disable-qt5 \
		--disable-gtk \
		--disable-gtk3 \
		--disable-expat \
		--disable-python \
		--disable-gdbm \
		--disable-mono \
		--disable-glib \
		--disable-stack-protector \
		--disable-gobject \
		--disable-autoipd \
		--disable-compat-libdns_sd \
		--localstatedir=/var \
		--enable-compat-howl
CPPFLAGS+=	-I${LOCALBASE}/include -DHAVE_KQUEUE
LDFLAGS+=	-L${LOCALBASE}/lib -lintl
INSTALL_TARGET=	install-strip

.if ${AVAHI_SLAVE} == no
CONFLICTS=	howl-[0-9]* avahi-app

DAEMON_CONFIG_FILES=	hosts avahi-daemon.conf
.endif
.endif # !avahi-header

.include <bsd.port.options.mk>

post-patch: avahi-post-patch

avahi-post-patch:
	@${REINPLACE_CMD} -e 's|avahi_runtime_dir="/run"|avahi_runtime_dir="/var/run"|' \
		${WRKSRC}/configure
	@${RM} ${WRKSRC}/man/*.bak
	@${REINPLACE_CMD} -e 's|-ldl||g ; s|netdev|network|g' \
		${WRKSRC}/configure \
		${WRKSRC}/avahi-client/Makefile.in \
		${WRKSRC}/avahi-daemon/Makefile.in
	@${REINPLACE_CMD} -e 's|%%GNOME_SUBR%%|${GNOME_SUBR}|' \
		${WRKSRC}/initscript/freebsd/avahi-dnsconfd.sh.in \
		${WRKSRC}/initscript/freebsd/avahi-daemon.sh.in

post-build: avahi-post-build

avahi-post-build:
.for f in ${AVAHI_PKGCONFIG}
	@cd ${WRKSRC} && ${SETENV} ${MAKE_ENV} ${MAKE_CMD} \
		${MAKE_FLAGS} ${MAKEFILE} ${MAKE_ARGS} ${f}
.endfor

pre-su-install: avahi-pre-su-install

avahi-pre-su-install:
.if ${AVAHI_SLAVE}=="no"
	@${MKDIR} ${STAGEDIR}${PREFIX}/lib/avahi
	@${TOUCH} -f ${STAGEDIR}${PREFIX}/lib/avahi/.keep
.endif

post-install: avahi-post-install

avahi-post-install:
.if defined(MANPAGES) && ${AVAHI_SLAVE} != gtk
.for f in ${MANPAGES}
	${INSTALL_DATA} ${WRKSRC}/man/${f} ${STAGEDIR}${PREFIX}/share/man/man${f:E}/${f}
.endfor
.endif
.for f in ${AVAHI_PKGCONFIG}
	${INSTALL_DATA} ${WRKSRC}/${f} ${STAGEDIR}${PREFIX}/libdata/pkgconfig
.endfor
.for f in ${DAEMON_CONFIG_FILES}
	${MKDIR} ${STAGEDIR}${PREFIX}/etc/avahi
	${INSTALL_DATA} ${WRKSRC}/avahi-daemon/${f} \
		${STAGEDIR}${PREFIX}/etc/avahi/${f}.sample
.endfor
.if ${AVAHI_SLAVE}==no
	${MKDIR} ${STAGEDIR}${PREFIX}/share/dbus-1/system-services
	${INSTALL_DATA} ${WRKSRC}/avahi-daemon/org.freedesktop.Avahi.service \
		${STAGEDIR}${PREFIX}/share/dbus-1/system-services
.endif

.include <bsd.port.mk>
