# -*- 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 52048 2009-06-09 00:20:54Z jeremyhu@macports.org $

PortSystem      1.0
PortGroup       muniversal 1.0

name            dbus-glib
version         0.80
maintainers     nomaintainer
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     86ea60ba2118a1b9deafe8257f6a6a1a \
                sha1    927e43f2d429cff5472ab726882347ec06e53f6b \
                rmd160  802dcdc4b7c7a8805b051b7bedf44022fece27d2

depends_build   port:pkgconfig

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.check regex
livecheck.url   http://www.freedesktop.org/wiki/Software/DBusBindings
livecheck.regex ${name}-(\\d+(?:\\.\\d+)*)
