# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=portfile:et:sw=4:ts=4:sts=4

PortSystem          1.0

name                prosody
version             0.11.2
maintainers         {g5pw @g5pw} openmaintainer

categories          net chat
description         Prosody is a modern flexible communications server for \
                    Jabber/XMPP written in Lua.
long_description    ${description} It aims to be easy to set up and configure, \
                    and light on resources. For developers it aims to be easy \
                    to extend and give a flexible system on which to rapidly \
                    develop added functionality, or prototype new protocols.

platforms           darwin

homepage            https://prosody.im
license             MIT

master_sites        ${homepage}/downloads/source/

depends_lib         port:lua-luasocket \
                    port:lua-luasec \
                    port:lua-luaexpat \
                    port:lua-luafilesystem \
                    port:libidn

checksums           rmd160  a27ba1b4ddd4511842cba45aeef7193b42c7ff17 \
                    sha256  8911f6dc29b9e0c4edf9e61dc23fa22d77bc42c4caf28b809ab843b2f08e4831 \
                    size    420689

set logdir          ${prefix}/var/log/${name}
set rundir          ${prefix}/var/run/${name}

patchfiles          patch-config.diff

post-patch {
    reinplace "s|@@PREFIX@@|${prefix}|g" ${worksrcpath}/prosody.cfg.lua.dist
}

configure.cflags-append  -fPIC
configure.ldflags-append -bundle -undefined dynamic_lookup

configure.args-append \
                    --ostype=macosx \
                    --with-lua=${prefix} \
                    --with-lua-include=${prefix}/include \
                    --with-lua-lib=${prefix}/lib \
                    --c-compiler=${configure.cc} \
                    --linker=${configure.cc} \
                    --cflags=\"${configure.cflags}\" \
                    --ldflags=\"${configure.ldflags}\"

startupitem.create  yes
startupitem.start   "${prefix}/bin/${name}ctl start"
startupitem.stop    "${prefix}/bin/${name}ctl stop"
startupitem.restart "${prefix}/bin/${name}ctl restart"
startupitem.pidfile auto ${rundir}/prosody.pid

add_users           ${name} group=${name} realname=Prosody\ Server

destroot.keepdirs   ${destroot}${logdir} ${destroot}${rundir}

post-destroot {
    xinstall -o ${name} -g ${name} -d ${destroot}${logdir} ${destroot}${rundir}
}

livecheck.type      regex
livecheck.url       ${master_sites}
livecheck.regex     "${name}-(\\d+\\.\\d+\\.\\d+)"