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

name                    mosh
version                 1.4.0
revision                3
categories              net
license                 {GPL-3+ OpenSSLException}
maintainers             {mit.edu:quentin @quentinmit} \
                        openmaintainer
description             Mobile Shell
long_description        Mosh is a replacement for ssh that better handles \
                        high-latency, high-packet-loss, dynamically-addressed \
                        network links
homepage                https://mosh.org/
master_sites            ${homepage}

checksums               rmd160  e5a06cbdee39cdf0259a4db08fe7919561ce52c5 \
                        sha256  872e4b134e5df29c8933dff12350785054d2fd2839b5ae6b5587b14db1465ddd \
                        size    393465

compiler.cxx_standard   2011

patchfiles-append       patch-fix-AltiVec.diff

perl5.require_variant   yes
perl5.conflict_variants yes
perl5.branches          5.34
perl5.default_branch    5.34
perl5.create_variants   ${perl5.branches}

depends_build-append    path:bin/pkg-config:pkgconfig

depends_lib-append      port:ncurses \
                        port:p${perl5.major}-getopt-long \
                        port:p${perl5.major}-io-socket-ip \
                        port:protobuf3-cpp \
                        port:zlib

post-patch {
    reinplace "s|#!/usr/bin/env perl|#!${prefix}/bin/perl${perl5.major}|" \
        ${worksrcpath}/scripts/mosh.pl
}

# https://github.com/protocolbuffers/protobuf/issues/9947
configure.cflags-append   -DNDEBUG

# avoid overlinking abseil
configure.ldflags-append  -Wl,-dead_strip_dylibs

# abseil uses C++17; use `gnu++17` as Mosh allows use of GNU extensions
configure.cxxflags-append -std=gnu++17

# force protobuf3-cpp into the no_threadlocal mode on older systems
if { ${os.platform} eq "darwin" && ${os.major} < 11 } {
    configure.cppflags-append -DGOOGLE_PROTOBUF_NO_THREADLOCAL
}

# Apple commoncrypto available 10.8 or later
if {${os.platform} eq "darwin" && ${os.major} > 11} {
    configure.args-append \
                        --with-crypto-library=apple-common-crypto
} else {
    depends_lib-append  path:lib/libssl.dylib:openssl
    configure.args-append \
                        --with-crypto-library=openssl
}

configure.args-append \
                    --enable-completion \
                    --disable-silent-rules

livecheck.type          regex
livecheck.url           ${homepage}
livecheck.regex         "[quotemeta ${name}]-(\[0-9a-z.\]+)[quotemeta ${extract.suffix}]"
