# -*- 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           luarocks 1.0
PortGroup           select 1.0

if {${subport} ne "lua-fennel-docs"} {
    luarocks.branches   5.1 5.2 5.3 5.4
}
luarocks.setup      fennel 1.3.1-1
revision            0
license             MIT
categories          lua lang
supported_archs     noarch
platforms           any
maintainers         {l2dy @l2dy} openmaintainer

description         a lisp that compiles to Lua
long_description    Fennel is {*}${description}.

homepage            https://fennel-lang.org/

checksums           rmd160  f587c235991ee959d05978a8c3632ae528ecb5c2 \
                    sha256  21f02f58793b2214284c018d43b4fb0460d70b25f4a025a290f3cc230972389e \
                    size    231142

subport lua-fennel-docs {
    depends_lib

    build.cmd       ${luarocks.bin}
    build.pre_args  --lua-version ${luarocks.branch} --tree ${destroot}${prefix}
    build.args      unpack
    build.post_args ${worksrcpath}/${luarocks.distname}.src.rock
    build {
        command_exec build
    }

    destroot {
        xinstall -m 644 {*}[glob ${worksrcpath}/${luarocks.distname}/fennel-*/*.1] ${destroot}${prefix}/share/man/man1
        xinstall -m 644 {*}[glob ${worksrcpath}/${luarocks.distname}/fennel-*/*.3] ${destroot}${prefix}/share/man/man3
        xinstall -m 644 {*}[glob ${worksrcpath}/${luarocks.distname}/fennel-*/*.5] ${destroot}${prefix}/share/man/man5
        xinstall -m 644 {*}[glob ${worksrcpath}/${luarocks.distname}/fennel-*/*.7] ${destroot}${prefix}/share/man/man7
    }
}

if {${subport} ne ${name} && ${subport} ne "lua-fennel-docs"} {
    select.entries  [list ${luarocks.module} ${subport} ${subport}]

    depends_run-append \
                    port:fennel_select \
                    port:lua-fennel-docs

    notes "
To make this the default fennel (i.e., the version run by\
the 'fennel' command), run:

    sudo port select --set fennel ${subport}
"
}
