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

# clock_gettime
legacysupport.newest_darwin_requires_legacy 15

github.setup            edbrowse edbrowse 3.8.13 v
revision                0
categories              www
platforms               darwin freebsd
maintainers             {ryandesign @ryandesign} openmaintainer
# edbrowse: GPL-2; quickjs: MIT
license                 GPL-2 MIT

description             Editor, browser and mail client that is 100% text-based.
long_description        Edbrowse is a combination editor, browser \
                        and mail client that is 100% text-based. \
                        The interface is similar to /bin/ed, though \
                        there are many more features, such as editing \
                        multiple files simultaneously, and rendering \
                        html. This program was originally written for \
                        blind users, but many sighted users have taken \
                        advantage of the unique scripting capabilities \
                        of this program, which can be found nowhere \
                        else. A batch job, or cron job, can access web \
                        pages on the internet, submit forms and send \
                        email, with no human intervention whatsoever. \
                        Edbrowse can also tap into databases through odbc.

homepage                http://edbrowse.org

checksums               rmd160  f051b1dadb31b5c9e0fda41dcd7bbeea7d0a04d4 \
                        sha256  599fdbc0ee6f500cc63af91c88404d90e79cbfb175c62b774c8d4d458b663877 \
                        size    1095751
github.tarball_from     archive

installs_libs           no

depends_extract-append  port:xz

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

depends_lib             port:curl \
                        port:pcre2 \
                        path:lib/pkgconfig/quickjs.pc:quickjs \
                        port:readline \
                        port:tidy \
                        port:unixODBC

set docdir              ${prefix}/share/doc/${subport}

patchfiles              docdir.patch

post-patch {
    reinplace "s|@DOCDIR@|${docdir}|g" ${worksrcpath}/doc/man-${name}-freebsd.1
}

# quickjs uses stdatomic
compiler.c_standard     2011
compiler.blacklist-append \
                        {clang < 700}

# Must be after compiler choice block:
if {[string match macports-gcc* ${configure.compiler}] \
    && ${configure.build_arch} in [list arm i386 ppc]} {
    configure.ldflags-append \
                        -latomic
}

build.env-append        LDFLAGS=${configure.ldflags} \
                        QUICKJS_INCLUDE=${prefix}/include/quickjs \
                        QUICKJS_LIB=${prefix}/lib/quickjs
build.args              STRIP=''

destroot {
    xinstall ${worksrcpath}/src/${name} ${destroot}${prefix}/bin
    xinstall -m 0444 ${worksrcpath}/doc/man-${name}-freebsd.1 \
        ${destroot}${prefix}/share/man/man1/${name}.1
    copy ${worksrcpath}/doc ${destroot}${docdir}
    delete {*}[glob ${destroot}${docdir}/man-${name}-*.1]
    xinstall -m 0644 -W ${worksrcpath} \
        CHANGES \
        LICENSE \
        README \
        ${destroot}${docdir}
}

# Create a launchd plist that creates the temporary directory with
# secure permissions. See README. This only needs to happen at load,
# so set startupitem.executable (to a dummy value) to avoid creating
# the unnecessary wrapper script and overwrite the plist MacPorts creates
# with our own to avoid the unnecessary use of daemondo.
startupitem.create      yes
startupitem.autostart   yes
startupitem.executable  /bin/true

if {${startupitem.type} eq "launchd"} {
    post-destroot {
        xinstall -m 0644 ${filespath}/${startupitem.uniquename}.plist \
            ${destroot}${prefix}/etc/${startupitem.location}/${startupitem.uniquename}/${startupitem.plist}
    }
    notes-append "
The startup item only creates a secure temporary directory for\
${subport}; it does not start ${subport}.
"
}
