# -*- 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             1.6.14
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  0e73711bdfbd889495f2030140ff48dc674362dd \
                    sha256  d070d2f28ae2400df7fe4a49eceb9f45cd539906b107481856a0af7a8fa82dc9 \
                    size    5266632

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
