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

PortSystem      1.0
PortGroup       github 1.0

github.setup    jabberd2 jabberd2 2.3.4 jabberd-
revision        3
name            jabberd
categories      net
platforms       darwin
maintainers     nomaintainer
license         GPL-2+

description     Jabber messaging (XMPP) server
long_description \
    The Jabber server (jabberd) is a daemon for Jabber clients to connect and \
    communicate with using the XMPP protocol.

homepage        http://jabberd2.org/
distname        ${name}-${version}
github.tarball_from releases
use_xz          yes

checksums       rmd160  210d2b28b635797831a271a3dd5deddd9042cd4c \
                sha256  9a17fae72460dd4454814edb48a7a1af7071cf331dabc2b0b6029661a36bb671

depends_build   port:libudns

depends_lib     path:lib/libssl.dylib:openssl \
                port:expat \
                port:libgsasl \
                port:libidn \
                port:zlib

patchfiles      patch-configure.diff \
                patch-sx-plugins.h.diff

# gcc 4.1.1 miscompiles something at -Os. gcc 4.2.2 works. Don't know when it
# got fixed, therefore use -O2 on all gcc.
# https://github.com/jabberd2/jabberd2/issues/34
if {[string match *gcc* ${configure.compiler}]} {
    configure.optflags -O2
}

configure.args  --enable-mio=select \
                --enable-ssl \
                --disable-mysql \
                --disable-pgsql \
                --disable-sqlite \
                --disable-db \
                --disable-oracle \
                --disable-ldap \
                --disable-pam \
                --disable-pipe \
                --disable-anon \
                --disable-fs

destroot.keepdirs ${destroot}${prefix}/var/jabberd/pid

set conf_files {c2s.xml jabberd.cfg router-filter.xml router-users.xml router.xml s2s.xml sm.xml templates/roster.xml}

post-destroot {
    foreach f ${conf_files} {
        file delete ${destroot}${prefix}/etc/$f
    }
}

post-activate {
    foreach f ${conf_files} {
        if {![file exists ${prefix}/etc/$f]} {
            copy ${prefix}/etc/$f.dist ${prefix}/etc/$f
        }
    }
}