# -*- 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                retawq
version             0.2.6c
revision            2
categories          www
license             GPL-2+
maintainers         nomaintainer
description         Text-based web-browser
long_description    ${name} is an interactive, multi-threaded network client \
                    (web-browser) for text terminals on computers with \
                    Unix-like operating systems. It is fast, small, nicely \
                    configurable and comfortable, e.g. the low-level \
                    network communications are performed in a non-blocking \
                    way, and you can keep open as many virtual windows \
                    as you want and work simultaneously in two of them \
                    in a split-screen mode.
homepage            https://retawq.sourceforge.net
master_sites        sourceforge:project/${name}/${name}/${name}-${version}

checksums           rmd160  2fe77deac308bf2857e8f202b2fe4598b842e3cf \
                    sha256  a42e82494f00e054c2de1b065bbc8fb439d93eb69f9b97cc4868e71e48a9eae0 \
                    size    393321

depends_build       port:gettext
depends_lib-append  port:gettext-runtime \
                    port:ncurses

patchfiles          patch-configure \
                    patch-resource_c \
                    patch-stuff_h

# https://trac.macports.org/ticket/70826
patchfiles-append   ncurses-opaque.patch

post-patch {
    reinplace "s|@PREFIX@|${prefix}|" ${worksrcpath}/docu/retawq.1 ${worksrcpath}/docu/example-config
}

configure.pre_args  --path-prefix=${prefix}
configure.args-append \
                    --enable-i18n \
                    --enable-ipv6 \
                    --path-man=${prefix}/share/man \
                    --path-doc=${prefix}/share/doc/${name} \
                    --set-threading=1

variant gnutls conflicts openssl description "Use GnuTLS for TLS" {
    depends_lib-append \
                    path:lib/pkgconfig/gnutls.pc:gnutls

    configure.args-append \
                    --set-tls=1

    configure.ldflags-append \
                    -lgnutls
}

variant openssl conflicts gnutls description "Use OpenSSL for TLS" {
    PortGroup       openssl 1.0

    patchfiles-append \
                    patch-tool_tlsmode

    post-patch {
        reinplace "s|@SSLROOT@|[openssl::install_area]|g" ${worksrcpath}/tool/tlsmode
    }

    configure.args-append \
                    --set-tls=2
}

if {![variant_isset gnutls]} {
    default_variants    +openssl
}

destroot {
    copy ${worksrcpath}/${name} ${destroot}${prefix}/bin
    xinstall -d ${destroot}${prefix}/man/man1
    copy ${worksrcpath}/docu/${name}.1 ${destroot}${prefix}/man/man1/
    xinstall -d ${destroot}${prefix}/share/doc/${name}
    fs-traverse f ${worksrcpath}/docu {
        if {[file isfile ${f}] && [file extension ${f}] == ".html"} {
            copy ${f} ${destroot}${prefix}/share/doc/${name}/
        }
    }
    xinstall -d ${destroot}${prefix}/share/examples/${name}
    copy ${worksrcpath}/docu/example-config ${destroot}${prefix}/share/examples/${name}/
}
