# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:filetype=tcl:et:sw=4:ts=4:sts=4
# $Id$

PortSystem      1.0

name            dbus
version         1.2.12
revision        4
maintainers     nomaintainer
categories      devel
platforms       darwin
description     A message bus system, a simple way for applications to talk to one another.

long_description \
    ${description}

homepage        http://www.freedesktop.org/Software/dbus
master_sites    http://dbus.freedesktop.org/releases/dbus

checksums           md5     39bd582c3b06a261cac44d4cab6fd60b \
                    sha1    13de8dc28c9edae7b9d2928ff691549bb2bef21a \
                    rmd160  779d76320f1343dae7447c82a683e372e6c11729

                
patchfiles      patch-dbus-sysdeps-unix.c.diff \
                patch-launchd-integration-dist.diff \
                patch-configure-int64.diff

post-patch {
   reinplace "s|@@PREFIX@@|${prefix}|g" ${worksrcpath}/dbus/dbus-sysdeps-unix.c
}

depends_build   port:pkgconfig

depends_lib     port:expat

configure.args  --disable-doxygen-docs \
                --disable-xml-docs \
                --without-x \
                --enable-launchd

post-configure {
    if {[variant_isset universal] && [lsearch -glob ${universal_archs} *64] != -1} {
        system "cd ${worksrcpath} && patch -p0 < ${filespath}/patch-config.h.diff && touch stamp-h1"
    }
}

platform darwin 7 {
    patchfiles              patch-dbus-launch-x11.c.diff \
                            patch-dbus-sysdeps-util-unix.c.diff

    depends_lib-append      port:xorg-libX11

    configure.args-delete   --without-x \
                            --enable-launchd
    configure.args-append   --with-x
}

use_parallel_build  yes

test.run        yes
test.target     check

pre-test {
    if {![variant_isset test]} {
        ui_error "test variant must be activated to enable test support."
        error "Please enable test variant."
    }
}

post-destroot {
    foreach dir ${destroot.keepdirs} {
        file mkdir $dir
    }
}

destroot.keepdirs \
    ${destroot}${prefix}/share/dbus-1/services \
    ${destroot}${prefix}/var/run/dbus \
    ${destroot}${prefix}/var/lib/dbus \
    ${destroot}${prefix}/etc/dbus-1/system.d \
    ${destroot}${prefix}/etc/dbus-1/session.d

startupitem.create  yes
startupitem.name    dbus
startupitem.executable   ${prefix}/bin/dbus-daemon --system --nofork

pre-activate {
    addgroup messagebus
    adduser messagebus gid=[existsgroup messagebus] realname=Message\ Bus
}

post-activate {
    file attributes ${prefix}/var/run/dbus -group messagebus -owner messagebus
    file attributes ${prefix}/libexec/dbus-daemon-launch-helper -group messagebus
    system "dbus-uuidgen --ensure"

    if {![variant_isset darwin_7]} {
        ui_msg "##############################################################################"
        ui_msg "# It is absolutely necessary for dbus enabled programs to work to execute"
        ui_msg "#"
        ui_msg "# launchctl load /Library/LaunchAgents/org.freedesktop.dbus-session.plist"
        ui_msg "#"
        ui_msg "# once for every user. Don't use 'sudo', else it will work only for root!"
        ui_msg "# You also have to unload it before deactivating/uninstalling this software!"
        ui_msg "##############################################################################"
    }
}

variant test description {enable tests} {
    configure.args-append   --enable-tests
}

livecheck.check regex
livecheck.regex {D-Bus (\d+(?:\.\d+)*)}
