# -*- 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: Portfile 67382 2010-05-07 02:52:40Z ryandesign@macports.org $

PortSystem      1.0
PortGroup       muniversal 1.0

name            dbus-glib
version         0.86
revision        1
maintainers     jwa openmaintainer
categories      devel
platforms       darwin
description     Glib bindings for the dbus message bus system.

long_description \
    ${description}

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

checksums           md5     cd0ab148fb0c786fc88be49d19971f50 \
                    sha1    023c01b4f95596023a483002e9195a0263be542e \
                    rmd160  931fd97ea6dbf08b952ca73d2a9bd486f2d70c06

depends_build   port:pkgconfig \
                port:gtk-doc

depends_lib     port:expat \
                port:libiconv \
                path:lib/pkgconfig/glib-2.0.pc:glib2 \
                port:dbus \
                port:gettext

configure.args  --disable-doxygen-docs

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"
    }
}

variant test description {Enable building of test code} {
    if { ! [variant_isset universal] } {
        configure.args-append   --enable-tests
    } else {
        # Do not enable test when cross-compiling.
        foreach arch ${cross_archs} {
            lappend merger_configure_args(${arch}) --enable-tests
        }
    }
}

if { [variant_isset universal] } {
    # Find architectures which will not run on build platform.
    if { ${os.arch}=="i386" } {
        if { ${os.major} >= 10 } {
            set cross_archs "ppc ppc64"
        } else {
            set cross_archs "ppc64"
        }
    } else {
        set cross_archs "i386 x86_64"
    }

    set run_arch [lindex ${universal_archs} 0]
    if { [variant_isset universal] && [lsearch ${cross_archs} ${run_arch}] >= 0 } {
        ui_msg "When building a universal binary of ${name}, make sure none of {${cross_archs}} is first in universal_archs in ${prefix}/etc/macports/macports.conf"
        error "incompatible universal_archs value"
    }

    foreach arch ${cross_archs} {
        if {[lsearch ${universal_archs} ${arch}] >= 0} {
            lappend merger_configure_env(${arch}) \
                ac_cv_func_posix_getpwnam_r=yes \
                ac_cv_have_abstract_sockets=no
        }
    }

    post-configure {
        foreach arch ${cross_archs} {
            if {[lsearch ${universal_archs} ${arch}] >= 0} {
                reinplace "s|--mode=execute \$(top_builddir)/dbus/dbus-binding-tool|--mode=execute ${worksrcpath}-${run_arch}/dbus/dbus-binding-tool|" \
                    ${worksrcpath}-${arch}/dbus/examples/Makefile \
                    ${worksrcpath}-${arch}/dbus/examples/statemachine/Makefile

                reinplace "s|\$(top_builddir)/dbus/dbus-binding-tool --mode=glib-client|${worksrcpath}-${run_arch}/dbus/dbus-binding-tool --mode=glib-client|" \
                    ${worksrcpath}-${arch}/tools/Makefile
            }
        }
    }
}

livecheck.type  regex
livecheck.url   http://www.freedesktop.org/wiki/Software/DBusBindings
livecheck.regex ${name}-(\\d+(?:\\.\\d+)*)
