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

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

# Versions newer than this don't build.
# https://github.com/egallesio/STklos/issues/514

github.setup            egallesio STklos 3bc8d1f9b7474f5458f22b9aa8f1595fc2c90946
name                    stklos-devel
version                 1.70-20230307-[string range ${git.branch} 0 7]
revision                0
checksums               rmd160  a77a23c3183d8347b33214a4aa29d6639da52495 \
                        sha256  e666d7067926704e6212dfc24c827e8bc0e9b5f9751d0d1088f596c1ff59b828 \
                        size    9313029

categories              lang
maintainers             {ryandesign @ryandesign} openmaintainer
license                 GPL-2+ GPL-3+
conflicts               [string map [list -devel {}] ${subport}]

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
github.tarball_from     archive
dist_subdir             stklos

depends_build           port:pkgconfig

patchfiles              dynamic_lookup.patch \
                        generate-git-info.patch \
                        no-gtklos.patch \
                        tmpcomp.patch

post-patch {
    set vparts          [split ${version} -]
    reinplace "s|@VERSION@|[lindex ${vparts} 0]|g;s|@COMMIT@|[lindex ${vparts} 2]|g" \
        ${worksrcpath}/utils/generate-git-info
}

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

    # Don't regenerate the documentation with asciidoctor if it is installed.
    configure.args-append \
                        ac_cv_prog_ASCIIDOCTOR=true

    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
} else {
    depends_lib-append  port:${name}

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

    livecheck.type      none
}

subport stklos-gtklos-devel {
    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
    }
}

subport stklos-curl-devel {
    # There is no non-devel curl extension yet.
    conflicts

    description         Curl extension for STklos

    long_description    {*}${description}

    depends_lib-append  port:curl

    patchfiles-append   curl.patch
}
