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

name                lsh
version             2.1
revision            4
categories          net
license             GPL-2+
maintainers         nomaintainer
conflicts           openssh pkixssh

description         GNU implementation of the Secure Shell protocols
long_description    ${name} is a free implementation (in the GNU sense) \
                    of the ssh version 2 protocol, currently being standardised \
                    by the IETF SECSH working group.

homepage            https://www.lysator.liu.se/~nisse/lsh
master_sites        https://www.lysator.liu.se/~nisse/archive/
checksums           rmd160  ce1a67851bb860de5ab7f4ae0d6c6a36fdcc8c2b \
                    sha256  8bbf94b1aa77a02cac1a10350aac599b7aedda61881db16606debeef7ef212e3 \
                    size    1540150

# Need to support aarch64:
use_autoreconf      yes
autoreconf.args     -fvi

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

depends_lib-append  port:gmp \
                    port:liboop \
                    port:nettle \
                    port:readline \
                    port:tcp_wrappers \
                    port:xauth \
                    port:xorg-libXau \
                    port:zlib

patchfiles          configure-CC.patch \
                    configure-paths.patch \
                    missing-include.patch \
                    nettle3.patch \
                    nettle3.4.patch \
                    patch-argp-fmtstream.h.diff \
                    strndup.patch \
                    patch-unix_process.c.diff

# Prevent opportunistic usage of Guile, which fails to work:
# Unbound variable: use-syntax
# make[3]: *** [randomness.h.x] Error 1
# Build system suggests GUILE_AUTO_COMPILE=0, however it gets ignored.
# Instead, patch out the broken scm target.
patchfiles-append   patch-no-broken-scheme.diff

configure.args      --disable-datafellows-workarounds \
                    --disable-gss \
                    --disable-kerberos \
                    --disable-srp \
                    --with-include-path=${prefix}/include \
                    --with-lib-path=${prefix}/lib \
                    --with-pam \
                    --with-tcpwrappers \
                    --with-x \
                    --without-system-argp \
                    --x-includes=${prefix}/include \
                    --x-libraries=${prefix}/lib

configure.env-append \
                    XAUTH_PROGRAM=${prefix}/bin/xauth

platform darwin {
    if {${os.major} < 10} {
        # Before Snow Leopard, pam_appl.h was in /usr/include/pam instead of /usr/include/security.
        set paminclude ${workpath}/paminclude

        post-extract {
            file mkdir ${paminclude}
            ln -s /usr/include/pam ${paminclude}/security
        }

        configure.cppflags-prepend \
                    -I${paminclude}
    }

    patchfiles-append \
                    patch-src-unix_user.c.diff

    post-patch {
        # fix time stamps
        touch ${worksrcpath}/src/unix_user.c.x
    }

    if {${os.major} > 21 && [string match *clang* ${configure.compiler}]} {
        configure.cflags-append \
                    -Wno-error=incompatible-function-pointer-types
    }

    notes-append {
        Additionally, for PAM, you need to copy /etc/pam.d/sshd to\
        /etc/pam.d/lshd, or use another config with pam_securityserver.so.
    }
}

livecheck.regex     ${name}-(\[0-9.\]+)${extract.suffix}
