# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
# $Id: Portfile 92318 2012-04-24 23:04:21Z pixilla@macports.org $

PortSystem          1.0

name                avahi
version             0.6.31
revision            1
categories          net devel
maintainers         pixilla openmaintainer
license             LGPL-2.1+
platforms           darwin
description         Avahi is an Implementation of the DNS Service Discovery and Multicast DNS \
                    specifications for Zeroconf Networking.

long_description    ${description} It uses D-Bus for communication between user applications and a \
                    system daemon. The daemon is used to coordinate application efforts in caching \
                    replies, necessary to minimize the traffic imposed on networks.

homepage            http://avahi.org/
master_sites        ${homepage}download/

checksums           rmd160  122f553ee2d43cdd0185540a63a8e1f587bdb08e \
                    sha256  8372719b24e2dd75de6f59bb1315e600db4fd092805bd1201ed0cb651a2dab48

patch.pre_args      -p1
patchfiles          patch-avahi-daemon-Makefile.in.diff \
                    patch-avahi-daemon-Makefile.in.orig.diff \
                    patch-avahi-dnsconfd-Makefile.in.diff \
                    patch-avahi-dnsconfd-Makefile.in.orig.diff \
                    patch-avahi-utils-Makefile.in.diff \
                    patch-avahi-utils-Makefile.in.orig.diff \
                    patch-configure.diff \
                    patch-configure.orig.diff \
                    patch-initscript-darwin-org.freedesktop.avahi-daemon.plist.in.diff \
                    patch-initscript-darwin-org.freedesktop.avahi-dnsconfd.plist.in.diff

post-patch {
# This preprocessor macro causes a lot of things to be undefined inside netinet/in.h system header.
    reinplace "s/-D_XOPEN_SOURCE=500//" ${worksrcpath}/configure
    reinplace "s|/System|${destroot}|g" ${worksrcpath}/initscript/darwin/Makefile.in
}

depends_build       port:pkgconfig

depends_run         port:intltool

depends_lib         port:libdaemon \
                    port:expat \
                    port:gdbm \
                    port:gettext

configure.args      --disable-autoipd \
                    --disable-qt3 \
                    --disable-qt4 \
                    --disable-mono \
                    --disable-monodoc \
                    --with-distro=darwin \
                    --enable-compat-libdns_sd \
                    --disable-gtk3 \
                    --disable-xmltoman \
                    --enable-introspection=no \
                    --disable-gtk \
                    --disable-pygtk \
                    --disable-tests


# __APPLE_USE_RFC_2292 should be removed once avhi is updated to support RFC 3542
configure.cppflags-append   -L${prefix}/lib -D__APPLE_USE_RFC_2292

pre-activate {
    addgroup avahi
    adduser avahi gid=[existsgroup avahi] realname=Avahi Service
}

post-activate {
    if {[file exists /System/Library/LaunchDaemons/org.freedesktop.avahi-dnsconfd.plist]} {
        ui_debug "Removing cruft from versions prior to 0.6.17_2..."
        delete \
            /System/Library/LaunchDaemons/org.freedesktop.avahi-dnsconfd.plist \
            /System/Library/LaunchDaemons/org.freedesktop.avahi-daemon.plist
    }
}

variant mono description {Enable Mono support} {
    depends_lib-append      port:mono \
                            port:gtk-sharp2

    configure.args-delete   --disable-mono

    post-patch {
        reinplace {s/\.so\.0/.0.dylib/} ${worksrcpath}/avahi-ui-sharp/avahi-ui-sharp.dll.config.in
    }

    post-build {
        # TODO This shouldn't be needed, we need to fix Mono dllmap library path.
        reinplace -E "s|(target=\")|\\1${prefix}/lib/|" \
            ${worksrcpath}/avahi-sharp/avahi-sharp.dll.config \
            ${worksrcpath}/avahi-ui-sharp/avahi-ui-sharp.dll.config
    }
}

variant test description {Build tests} {
    configure.args-delete   --disable-tests
    configure.args-append   --enable-tests
    test.run            yes
    test.target         check
}

variant gtk description {Build with GTK2} {
    depends_lib-append      port:libglade2

    configure.args-delete   --disable-gtk
}

variant python25 conflicts python26 python27 description {Use python 2.5} {
    configure.python        ${prefix}/bin/python2.5

    depends_lib-append      port:dbus-python25 \
                            port:py25-gdbm
    if [variant_isset gtk] {
        depends_lib-append      port:py25-gtk
        configure.args-delete   --disable-pygtk
    }
}

variant python26 conflicts python25 python27 description {Use python 2.6} {
    configure.python        ${prefix}/bin/python2.6

    depends_lib-append      port:dbus-python26 \
                            port:py26-gdbm
    if [variant_isset gtk] {
        depends_lib-append      port:py26-gtk
        configure.args-delete   --disable-pygtk
    }
}

variant python27 conflicts python25 python26 description {Use python 2.7} {
    configure.python        ${prefix}/bin/python2.7

    depends_lib-append      port:dbus-python27 \
                            port:py27-gdbm
    if [variant_isset gtk] {
        depends_lib-append      port:py27-gtk
        configure.args-delete   --disable-pygtk
    }
}

default_variants    +gtk
if {![variant_isset python25] && ![variant_isset python26]} {
    default_variants-append +python27
}

livecheck.type      regex
livecheck.url       [lindex ${master_sites} 0]
livecheck.regex     ${name}-(\[0-9.\]+)\\.tar
