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

# clock_gettime
legacysupport.newest_darwin_requires_legacy 15

github.setup            CMB edbrowse 3.8.6 v
set quickjs_version     2021-03-27
revision                0
set main_distfile       ${distfiles}
set quickjs_distname    quickjs-${quickjs_version}
set quickjs_distfile    ${quickjs_distname}.tar.xz
checksums               ${main_distfile} \
                        rmd160  fa8e70c6593f4fae953026db26d0756f265f949f \
                        sha256  85ce43c2832e1e79ea24e23c7726757080ef966d7c2c387f8aa9be108f36bf26 \
                        size    984841 \
                        ${quickjs_distfile} \
                        rmd160  0d59b21acc50db254d1087baed8c625e6390c113 \
                        sha256  a45bface4c3379538dea8533878d694e289330488ea7028b105f72572fe7fe1a \
                        size    753556

# As of 3.8.4 edbrowse no longer patches the quickjs source so it could now
# use a standard quickjs library from MacPorts, if we had a quickjs port.

categories              www
maintainers             {ryandesign @ryandesign} openmaintainer
# edbrowse: GPL-2; quickjs: MIT
license                 GPL-2 MIT

description             A combination 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/
set quickjs_homepage    https://bellard.org/quickjs/

github.tarball_from     archive
master_sites            ${github.master_sites}:main \
                        ${quickjs_homepage}:quickjs

extract.only            ${main_distfile}
distfiles               ${main_distfile}:main \
                        ${quickjs_distfile}:quickjs

platforms               darwin freebsd
installs_libs           no

depends_extract-append  port:xz

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

depends_lib             port:curl \
                        port:openssl \
                        port:pcre2 \
                        port:readline \
                        port:tidy \
                        port:unixODBC

set quickjs_worksrcpath ${workpath}/${quickjs_distname}
set docdir              ${prefix}/share/doc/${subport}

post-extract {
    system -W ${workpath} "xz -dc [shellescape ${distpath}/${quickjs_distfile}] | ${portutil::autoconf::tar_command} -xf -"
    ln -s ${distname} ${workpath}/${name}
    ln -s ${quickjs_distname} ${workpath}/quickjs
}

patch.dir               ${workpath}
patchfiles              build-quickjs.patch \
                        docdir.patch \
                        use-CFLAGS-LDFLAGS.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}

build.env               QUICKJS_DIR=${quickjs_worksrcpath}
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 \
        COPYING \
        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}.
"
}
