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

name                nim
version             2.2.6
revision            0
license             MIT
categories          lang
supported_archs     i386 x86_64 ppc64 arm64
maintainers         {@esafak gmail.com:esafak} openmaintainer

description         Nim programming language
long_description    Nim is a statically typed compiled systems programming \
                    language. It combines successful concepts from mature \
                    languages like Python, Ada, and Modula. Its design focuses \
                    on efficiency, expressiveness, and elegance (in that \
                    order of priority).

homepage            https://nim-lang.org

master_sites        ${homepage}/download/
checksums           rmd160  3f62282891cc1c25dda93fb160efd56df9676951 \
                    sha256  657b0e3d5def788148d2a87fa6123fa755b2d92cad31ef60fd261e451785528b \
                    size    8471204

use_configure       no
use_xz              yes

variant doc description {Build HTML docs} {}

build {
    # See https://nim-lang.github.io/Nim/packaging.html
    set nim_build_arch ${os.arch}
    if {${build_arch} eq "arm64" } {
        # nim looks for aarch64 and not arm/arm64
        set nim_build_arch "aarch64"
    }
    system -W ${worksrcpath} "./build.sh --os ${os.platform} --cpu ${nim_build_arch}"
    system -W ${worksrcpath} "./bin/nim c koch"
    system -W ${worksrcpath} "./koch boot -d:release"
    system -W ${worksrcpath} "./koch tools -d:release"

    if {[variant_isset doc]} {
        system -W ${worksrcpath} "./koch docs"
    }
}

destroot {
    system -W \
        ${worksrcpath} "./install.sh [shellescape ${destroot}/${prefix}/lib]"

    foreach nimbin [glob ${worksrcpath}/bin/*] {
        xinstall -m 0755 ${nimbin} ${destroot}/${prefix}/lib/${name}/bin/

        ln -sf \
            ${prefix}/lib/${name}/bin/[file tail ${nimbin}] \
            ${destroot}/${prefix}/bin/
    }

    xinstall -d ${destroot}/${prefix}/share/doc/${name}
    copy {*}[glob ${worksrcpath}/doc/*] ${destroot}/${prefix}/share/doc/${name}
}

livecheck.url       ${homepage}/install.html
livecheck.regex     ${name}-(\[0-9.\]+).tar.xz
