# $Id: Portfile 51955 2009-06-07 10:04:10Z arthurk@macports.org $

PortSystem      1.0

name            avahi
version         0.6.24
categories      net devel
maintainers     nomaintainer
platforms       darwin
description     A system which facilitates service discovery on a local network

long_description \
    Avahi is a system which facilitates service discovery on a local \
    network. This means that you can plug your laptop or computer into \
    a network and instantly be able to view other people who you can \
    chat with, find printers to print to or find files being shared. \
    This kind of technology is already found in Mac OS X (branded \
    Rendezvous, Bonjour and sometimes Zeroconf) and is very convenient. \
    Avahi is mainly based on Lennart Poettering's flexmdns mDNS \
    implementation for Linux which has been discontinued in favour \
    of Avahi.

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

checksums       md5     068c1d220b07037e64caf87d4a7a0504 \
                sha1    a187af361fefc8bda026936bb07ccdeb41dc74bc \
                rmd160  94f59ccbd14d99e91e259b27dd7f03404c6691e6

patchfiles      patch-avahi-utils-Makefile.in-nls.diff \
                patch-initscript_darwin_org.freedesktop.avahi-daemon.plist.in \
                patch-initscript_darwin_org.freedesktop.avahi-dnsconfd.plist.in

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 \
                path:lib/pkgconfig/glib-2.0.pc:glib2 \
                port:gtk2 \
                port:libglade2 \
                port:python25 \
                port:dbus \
                port:dbus-glib \
                port:dbus-python25 \
                port:expat \
                port:gdbm \
                port:py25-gtk \
                port:gettext \
                port:libiconv

configure.args  --disable-autoipd \
                --disable-qt3 \
                --disable-qt4 \
                --disable-mono \
                --disable-monodoc \
                --with-libiconv-prefix=${prefix} \
                --with-libintl-prefix=${prefix} \
                --with-distro=darwin \
                --enable-compat-libdns_sd

configure.cppflags-append   -L${prefix}/lib
configure.python            ${prefix}/bin/python2.5

test.run        yes
test.target     check

pre-test {
    if {![variant_isset test]} {
        error "test variant must be enabled to run the tests."
    }
}

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_build-append    port:monodoc

    depends_lib-append      port:mono \
                            port:gtk-sharp2

    configure.args-delete   --disable-mono \
                            --disable-monodoc

    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-append   --enable-tests
}

