# -*- 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           cmake 1.1
PortGroup           legacysupport 1.1
PortGroup           openssl 1.0

# clock_gettime
legacysupport.newest_darwin_requires_legacy \
                    15

name                mosquitto
version             2.1.2
revision            0
categories          net devel
license             {EPL-1 EDL-1}

maintainers         {gmail.com:slewsys @slewsys} openmaintainer

description         Mosquitto is an open-source MQTT 5.0/3.1.1/3.1 broker
long_description    \
    MQTT is a machine-to-machine / "Internet of Things" connectivity protocol. \
    Mosquito provides an open-source MQTT v5.0 and v3.1.1 broker (i.e., server) \
    and both C and C++ client libraries and command-line tools.

homepage            https://mosquitto.org
master_sites        ${homepage}/files/source/

checksums           rmd160  6d750882c31c65c7f29b693e8ab5414f22c45b2a \
                    sha256  fd905380691ac65ea5a93779e8214941829e3d6e038d5edff9eac5fd74cbed02 \
                    size    2882727

depends_build-append \
                    path:bin/xsltproc:libxslt

# argon2 is not actually used atm, only checked for.
depends_lib-append  port:libcjson \
                    port:sqlite3

compiler.cxx_standard \
                    2017

# Using bundled libwebsockets due to:
# #warning "libwebsockets is not compiled with LWS_WITH_EXTERNAL_POLL support.
# Websocket performance will be unusable."
configure.args-append \
                    -DWITH_CTRL_SHELL:BOOL=OFF \
                    -DWITH_LTO:BOOL=ON \
                    -DWITH_SRV:BOOL=OFF \
                    -DWITH_TESTS:BOOL=OFF \
                    -DWITH_TLS:BOOL=ON \
                    -DWITH_WEBSOCKETS:BOOL=ON \
                    -DWITH_WEBSOCKETS_BUILTIN:BOOL=ON

# FIXME: fails to configure, as of 2.1.2.
variant lineedit description "Include mosquitto_ctrl interactive shell support" {
    depends_lib-append \
                    port:libedit
    configure.args-replace \
                    -DWITH_CTRL_SHELL:BOOL=OFF -DWITH_CTRL_SHELL:BOOL=ON
    configure.args-append \
                    -DLINEEDITING_INCLUDE_DIRS=${prefix}/include/editline \
                    -DLINEEDITING_LIBRARIES=${prefix}/lib/libedit.dylib
}

variant srv description "Add SRV record support to command-line tools" {
    depends_lib-append \
                    port:c-ares
    configure.args-replace \
                    -DWITH_SRV:BOOL=OFF -DWITH_SRV:BOOL=ON
}

set mosquitto_user  mosquitto
set mosquitto_group mosquitto

add_users ${mosquitto_user} group=${mosquitto_group} shell=/bin/sh \
    home=${prefix}/var/lib/${name} realname=Mosquitto\ MQTT\ Server

startupitem.create  yes
startupitem.init    \
    "MOSQUITTO=${prefix}/sbin/mosquitto"
startupitem.start    \
    "su ${mosquitto_user} -c \"\${MOSQUITTO}\""
startupitem.stop    \
    "su ${mosquitto_user} -c \"\pkill -U ${mosquitto_user} mosquitto\""

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