--- _orig/net/asterisk/Portfile	2014-12-29 15:31:09.000000000 -0500
+++ net/asterisk/Portfile	2015-02-22 13:34:04.000000000 -0500
@@ -1,14 +1,14 @@
 # -*- 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 130247 2014-12-29 20:23:19Z mf2k@macports.org $
+# $Id: Portfile 103074 2013-02-13 04:13:46Z jmr@macports.org $
 
 PortSystem          1.0
 
 name                asterisk
-version             1.6.2.20
+version             13.2.0
 categories          net
 license             GPL-2
 platforms           darwin
-maintainers         viagente.ca:marc.blanchet openmaintainer
+maintainers         viagente.ca:marc.blanchet mr_bond openmaintainer
 
 description         An Open Source PBX and telephony toolkit
 long_description    Asterisk is an open source PBX and telephony toolkit.  It \
@@ -17,7 +17,8 @@
                 
 homepage            http://www.asterisk.org
 master_sites        http://downloads.digium.com/pub/asterisk/releases/
-                    
+
+## Missing? gmime pjsip srtp
 depends_lib         port:ncurses \
                     port:openssl \
                     port:zlib \
@@ -33,23 +34,44 @@
                     port:spandsp-devel \
                     port:speex \
                     port:sqlite3 \
-                    port:wget
+                    port:wget \
+                    port:jansson
+## Optional components: libpri DAHDI
+
+## need specific ice-cpp w patch https://wiki.asterisk.org/wiki/display/TOP/System+Requirements
+depends_build       port:cmake port:boost
+# port:zeroc-ice34 => fails to build
 
-checksums           rmd160  8584d0f2e274517ce84576dfa7e936b9befb9fe2 \
-                    sha256  4f3ef1de4644195e0d91816d6741c46ddb5d9ad28b07e631f594674ac9006a27
+checksums           rmd160  fd7a42251994831f2c8ee4f2fdb598de5577748a \
+                    sha256  bcef6b30cf7bb1943b12939a4dc98a53f837a8f7ef564fe44cf73ea87e114a9b
 
 startupitem.create      yes
 startupitem.netchange   yes
-startupitem.executable  ${prefix}/sbin/asterisk -d
+startupitem.executable  ${prefix}/sbin/asterisk -d -U asterisk -G asterisk -C ${prefix}/etc/asterisk.conf
 
 universal_variant   no
 
-patchfiles          makeopts.in.diff menuselect_Makefile.diff
+#patchfiles          makeopts.in.diff menuselect_Makefile.diff
+patchfiles          patch-makeopts.in.diff
+
+add_users asterisk group=asterisk home=${prefix}/var/spool/asterisk shell=/sbin/nologin realname=asterisk\ user
 
 configure.args      --without-h323 \
-                    --without-netsnmp
+                    --without-netsnmp \
+                    --with-crypto=${prefix} --with-curses=${prefix} \
+                    --with-iconv=${prefix} --with-sqlite3=${prefix} \
+                    --with-ssl=${prefix} \
+                    --without-gtk2 \
+                    --enable-dev-mode
 
 configure.optflags  -O3
+## http://comments.gmane.org/gmane.comp.telephony.pbx.asterisk.devel/62632
+#configure.compiler  macports-gcc-4.9
+## FIXME! need review to adjust blacklist
+#compiler.blacklist gcc-4.0 gcc-4.2 macports-gcc-4.2 macports-gcc-4.3 {clang < 500}
+#compiler.blacklist clang macports-clang
+
+## FIXME! http://forums.asterisk.org/viewtopic.php?f=1&t=91239
 
 build.env           ASTCFLAGS=-I${prefix}/include \
                     ASTLDFLAGS=-L${prefix}/lib \
@@ -67,15 +89,112 @@
                     ${destroot}${prefix}/var/spool/asterisk/tmp \
                     ${destroot}${prefix}/var/spool/asterisk/voicemail
 
+## clang support actions
+#pre-configure {
+#    system -W ${worksrcpath} "./bootstrap.sh"
+#}
+#post-configure {
+#   system -W ${worksrcpath} "make menuselect.makeopts; menuselect/menuselect --enable DISABLE_INLINE"
+#}
+#build.env-append    ASTCFLAGS="-I${prefix}/include -Wno-unknown-warning-option -Wno-error"
+
+
 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
 }
 
+variant snmp description { snmp support } {
+    depends_lib-append           port:net-snmp
+    configure.args-delete --without-netsnmp
+    configure.args-append --with-netsnmp=${prefix}
+}
+
+variant libpri description { libpri support } {
+    depends_lib-append           port:libpri
+    configure.args-append --with-pri=${prefix}
+}
+
+variant dahdi description { dahdi support } {
+    depends_lib-append           port:dahdi
+    configure.args-append --with-dahdi=${prefix}
+}
+
+variant ldap description { ldap support } {
+    depends_lib-append    port:openldap
+    configure.args-append --with-ldap=${prefix}
+}
+
+## https://issues.asterisk.org/jira/browse/ASTERISK-22459
+variant libiodbc description { use libiodbc for ODBC access } {
+    depends_lib-append port:libiodbc
+}
+
+variant unixodbc description { use unixodbc for ODBC access } {
+    depends_lib-append port:unixODBC
+}
+
 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 \
+    xinstall -d ${destroot}${prefix}/share/examples/${name}
+    system "rsync -a ${worksrcpath}/configs/*.sample ${destroot}${prefix}/share/examples/${name}/"
+    xinstall -m 644 ${filespath}/asterisk.conf.sample.in ${destroot}${prefix}/share/examples/${name}/asterisk.conf.sample
+    reinplace "s|@PREFIX@|${prefix}|g" ${destroot}${prefix}/share/examples/${name}/asterisk.conf.sample
+    xinstall -d -o asterisk -g asterisk ${destroot}${prefix}/var/log/asterisk \
                 ${destroot}${prefix}/var/run/asterisk \
                 ${destroot}${prefix}/var/spool/asterisk/outgoing
 }
+
+post-activate {
+     foreach f [glob -directory ${prefix}/share/examples/${name} *.sample] {
+         set fname [file tail $f]
+         set fname trimright .sample
+         if ![file exists ${prefix}/etc/${name}/${fname} ] {
+            copy ${f} ${prefix}/etc/${name}/${fname}
+         }
+     }
+}
+
+if {${subport} eq ${name}} {
+
+    livecheck.type     regex
+    livecheck.url       ${homepage}/downloads/asterisk/all-asterisk-versions
+    livecheck.regex     "<p>Latest Version - (\\d+(?:\\.\\d+)*)</p>"
+    #livecheck.regex     "Asterisk 12 - Standard</a></p><p><a class=\"download-link-blue\" href=\"http://downloads.asterisk.org/pub/telephony/asterisk/ChangeLog-12-current\">ChangeLog</a></p><p>Latest Version - (\\d+(?:\\.\\d+)*)</p>"
+}
+
+subport ${name}11 {
+    description         An Open Source PBX and telephony toolkit - Certified
+    version             11.6-cert7
+    master_sites        http://downloads.asterisk.org/pub/telephony/certified-asterisk/
+    distname            certified-asterisk-${version}
+
+    checksums           rmd160  901db627c27f524fd9760f22bac92deb47d1d2dd \
+                        sha256  21cf51e2097f62953ccb7490a30357c88d473ad897774f92e36db0047036064d
+
+    livecheck.type     regex
+    livecheck.url       ${homepage}/downloads/asterisk/all-asterisk-versions
+    livecheck.regex     "Certified Asterisk 11</a></p><p><a class=\"download-link-blue\" href=\"http://downloads.asterisk.org/pub/telephony/certified-asterisk/ChangeLog-11.\\d+-current\">ChangeLog</a></p><p>Latest Version - (\\d+(?:\\.\\d+-cert\\d+)*)</p>"
+}
+
+subport ${name}-devel {
+    version             13.0.0-beta3
+
+    checksums           rmd160  8d8ac4bd824f7f36374f39287fee6a541cff5fe3 \
+                        sha256  1c6ae3280ad037f86c9b03bd9c56c08756404109019b3481304b2a902f47f00b
+
+    livecheck.type     regex
+    livecheck.url       ${homepage}/downloads/asterisk/all-asterisk-versions
+    livecheck.regex     "Asterisk 13 - LTS</a></p><p><a class=\"download-link-blue\" href=\"http://downloads.asterisk.org/pub/telephony/asterisk/releases/ChangeLog-13.*?\">ChangeLog</a></p><p>Latest Version - (\\d+(?:\\.\\d+)*(?:-beta\\d+)*)</p>"
+}
+
+subport ${name}1 {
+    description         An Open Source PBX and telephony toolkit - Certified 1.8
+    version             1.8.15-cert7
+    master_sites        http://downloads.asterisk.org/pub/telephony/certified-asterisk/
+    distname            certified-asterisk-${version}
+
+    checksums           rmd160  d43110e7d496dfbb5b282110b057036b07d48e54 \
+                        sha256  9027442d22cb01557fb4a5fc4a90a3386692f0f1db1fadd4ad018969c42d3b8f
+
+    livecheck.type      none
+}
+
