# -*- 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 92937 2012-05-11 14:01:55Z ryandesign@macports.org $

PortSystem          1.0
PortGroup           qt4 1.0

name                mumble
version             1.2.2
revision            4
categories          aqua audio
license             GPL
maintainers         snc openmaintainer
description         low-latency voice chat for gaming
long_description \
    Mumble is an open source, low-latency, high quality \
    voice chat software primarily intended for use while gaming.
homepage            http://mumble.sourceforge.net/
platforms           macosx
supported_archs     ppc i386

master_sites        sourceforge

checksums           rmd160  501aa1c4c170fb5aad2841cdfe3421376e62a07b \
                    sha256  2c564e3d5b7481129482f2365375a2dc77e134c0c00012073cfdfbeadaa49be8

livecheck.type      regex
livecheck.url       http://mumble.sourceforge.net
livecheck.regex     (\\d+(\\.\\d+)+) \\(Stable\\)

depends_lib-append \
    port:openssl \
    port:portaudio \
    port:ice-cpp \
    port:libsndfile \
    port:protobuf-cpp \
    path:lib/libspeex.dylib:speex

depends_build-append \
    port:boost

configure.args

variant debug description "Build as both release and debug" {}

post-patch {
    # when not doing debug ...
    if {![variant_isset debug]} {
        # ... build just the release version
        configure.args-append release
        foreach fixfile [exec find ${worksrcpath} -name "*.pr*"] {
            reinplace "s@debug_and_release@release@" ${fixfile}
        }
    } else {
        # else build both debug and release
        configure.args-append debug_and_release
    }

    # Fix LIBPATH -> QMAKE_LIBPATH per Qt 4.7's warnings
    foreach fixfile [exec find ${worksrcpath} -name "*.pr*"] {
        reinplace "s@LIBPATH@QMAKE_LIBDIR@" ${fixfile}
    }
}

configure.env-append QMAKESPEC=${qt_mkspecs_dir}/macx-g++
configure.cmd       ${qt_qmake_cmd}
configure.pre_args  CONFIG+=\"
configure.post_args \" DEFINES+=NO_UPDATE_CHECK main.pro
configure.args-append no-dbus no-universal no-server \
    no-embed-qt-translations no-bundled-speex no-g15 \
    no-update

variant dbus description {Build DBus support} {
    configure.args-delete no-dbus
}

variant universal {
    configure.args-delete no-universal
}

build.env-append    QMAKESPEC=${qt_mkspecs_dir}/macx-g++

destroot {
    file copy ${worksrcpath}/release/Mumble.app ${destroot}${applications_dir}/Mumble.app
    file copy ${worksrcpath}/release/plugins ${destroot}${applications_dir}/Mumble.app/Contents/Plugins
}

pre-activate {
    # mumble 1.1.8_0 thru 1.2.2_3 installed these items directly to
    # ${prefix}${applications_dir}; remove them if found
    foreach file {Mumble.app} {
        set filepath ${prefix}${applications_dir}/${file}
        if {[file exists ${filepath}] && [registry_file_registered ${filepath}] == "0"} {
            if {[catch {delete ${filepath}}]} {
                ui_warn "Cannot delete ${filepath}; please remove it manually"
            }
        }
    }
}
