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

# Please keep the stklos and stklos-devel ports as similar as possible.

name                    stklos
version                 1.70
revision                0
checksums               rmd160  55e82367cc6fdcc4bdd1f9c9b99d746ea7c0aa19 \
                        sha256  15a1251a0e72d66051011bb95ba9122b22f7acd8a5a0d0e4f8737cc9fcbb83c7 \
                        size    8767615

categories              lang
maintainers             {ryandesign @ryandesign} openmaintainer
license                 GPL-2+ GPL-3+
conflicts               ${subport}-devel

description             free Scheme system supporting most R7RS language features

long_description        STklos is a free Scheme system supporting most of the \
                        language features defined in R7RS. The aim of this \
                        implementation is to be fast as well as light. The \
                        implementation is based on an ad-hoc Virtual Machine.

homepage                https://stklos.net
master_sites            ${homepage}/download/

depends_build           port:pkgconfig

patchfiles              dynamic_lookup.patch \
                        implicit.patch \
                        no-gtklos.patch \
                        tmpcomp.patch

if {${subport} eq ${name}} {
    depends_lib-append  port:boehmgc \
                        port:gmp \
                        port:libffi \
                        port:pcre

    # The repl dlopens libreadline or libedit at runtime but in 1.70 it can't
    # find them. After 1.70 it seems to work; revisit adding a dependency on one
    # of those then and see if the code can be forced to use the one we pick.

    test.run            yes

    # The install target depends on install-sources which I assume we don't
    # need. The install-base target normally strips the executable which will
    # make it not work with extensions because the symbols the extensions want
    # to use have been stripped out:
    # https://github.com/egallesio/STklos/issues/353#issuecomment-1028125323
    # https://github.com/egallesio/STklos/issues/440#issuecomment-1473044496
    # There is an install-base-no-strip target which sets STRIP=no before
    # calling install-base, however install-doc depends on install-base, so if
    # we use "install-base-no-strip install-doc" then the executable will be
    # installed unstripped, and then will be reinstalled stripped. It's simpler
    # to use install-base and set STRIP=no ourselves.
    destroot.target     install-base install-doc
    destroot.args       STRIP=no

    livecheck.url       ${homepage}/download.html
} else {
    depends_lib-append  port:${name}

    build.dir           ${worksrcpath}/[string map [list stklos- extensions/] ${subport}]/src
    build.env           COMP=${prefix}/bin/stklos-compile

    livecheck.type      none
}

subport stklos-gtklos {
    description         GTK+ extension for STklos

    long_description    {*}${description}

    depends_lib-append  port:goocanvas2

    patchfiles-replace  no-gtklos.patch gtklos.patch

    post-patch {
        reinplace "s|@PREFIX@|${prefix}|g" ${build.dir}/lib/libs.stk
    }
}
