# -*- 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$

PortSystem          1.0

name                asterisk
version             1.6.2.20
revision            3
categories          net
platforms           darwin
universal_variant   no
license             GPL-2
maintainers         nomaintainer

description         An Open Source PBX and telephony toolkit
long_description    Asterisk is an open source PBX and telephony \
                    toolkit. It provides the ability to develop \
                    telephony applications on top of Internet \
                    telephony (Voice over IP) as well as traditional \
                    telephony connectivity (PSTN).
homepage            http://www.asterisk.org

depends_lib         port:bison \
                    port:curl \
                    port:iksemel \
                    port:libogg \
                    port:libvorbis \
                    port:lua \
                    port:ncurses \
                    port:openldap \
                    path:lib/libssl.dylib:openssl \
                    port:popt \
                    port:portaudio \
                    port:spandsp-devel \
                    port:speex \
                    port:sqlite3 \
                    port:wget \
                    port:zlib

master_sites        http://downloads.digium.com/pub/asterisk/releases/
checksums           rmd160  8584d0f2e274517ce84576dfa7e936b9befb9fe2 \
                    sha256  4f3ef1de4644195e0d91816d6741c46ddb5d9ad28b07e631f594674ac9006a27

add_users           asterisk group=asterisk realname=Asterisk\ PBX

startupitem.create      yes
startupitem.netchange   yes
if {[getuid] == 0} {
    startupitem.executable  ${prefix}/sbin/asterisk -d -U asterisk -G asterisk
} else {
    startupitem.executable  ${prefix}/sbin/asterisk -d
}

patchfiles          makeopts.in.diff \
                    menuselect_Makefile.diff

configure.optflags  -O3
configure.args      --without-h323 \
                    --without-netsnmp

variant home_sound_cache description {Use/Build sound file cache from .asterisk_sounds_cache in your home directory} {
    configure.args-append --with-sounds-cache=~/.asterisk_sounds_cache
}

build.env           ASTCFLAGS=-I${prefix}/include \
                    ASTLDFLAGS=-L${prefix}/lib \
                    NOISY_BUILD=1 \
                    OPTIMIZE=${configure.optflags}

destroot.keepdirs   ${destroot}${prefix}/var/log/asterisk \
                    ${destroot}${prefix}/var/run/asterisk \
                    ${destroot}${prefix}/var/spool/asterisk \
                    ${destroot}${prefix}/var/spool/asterisk/dictate \
                    ${destroot}${prefix}/var/spool/asterisk/meetme \
                    ${destroot}${prefix}/var/spool/asterisk/monitor \
                    ${destroot}${prefix}/var/spool/asterisk/outgoing \
                    ${destroot}${prefix}/var/spool/asterisk/system \
                    ${destroot}${prefix}/var/spool/asterisk/tmp \
                    ${destroot}${prefix}/var/spool/asterisk/voicemail
post-destroot {
    system "rsync -a ${worksrcpath}/configs/*.sample ${destroot}${prefix}/etc/asterisk"
    xinstall -m 644 ${filespath}/asterisk.conf.sample.in ${destroot}${prefix}/etc/asterisk/asterisk.conf.sample
    reinplace "s|@PREFIX@|${prefix}|g" ${destroot}${prefix}/etc/asterisk/asterisk.conf.sample
    xinstall -d ${destroot}${prefix}/var/log/asterisk \
                ${destroot}${prefix}/var/run/asterisk \
                ${destroot}${prefix}/var/spool/asterisk/outgoing
    if {[getuid] == 0} {
        system "chown -R asterisk:asterisk ${destroot}${prefix}/var/log/asterisk ${destroot}${prefix}/var/run/asterisk ${destroot}${prefix}/var/spool/asterisk"
    }
}