# -*- 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.4
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  3f66546c376a3eda4af8879db139d7562bc41fbb \
                    sha256  f82b419750fcce561f3f897a0486b180186845d76fb5d99f248ce166108189c7 \
                    size    8168916

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
