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

github.setup        alantech alan 0.1.44 v
github.tarball_from archive
revision            0

categories          lang

license             Apache-2 \
                    AGPL-3

homepage            https://alan-lang.org

description         The Alan Programming Language

long_description    {*}${description}: The alan compiler and runtime can \
                    parallelize your code without concurrent or asynchronous \
                    programming (threads, promises, channels, etc) by only \
                    allowing iteration and recursion that is guaranteed to \
                    halt (e.g. no while (true) \{\} loops)

checksums           rmd160  6606b539e4b534a966e997953c8cbdb1e2b91bc2 \
                    sha256  05e1a64413829c19cd469a6c5ffb749d6ed40fcd690dafacfa1232cde6a16a49 \
                    size    2837360

maintainers         {gmail.com:herby.gillot @herbygillot} \
                    openmaintainer

depends_build       port:cargo \
                    port:python27 \
                    port:protobuf3-cpp \
                    port:rust \
                    port:yarn \
                    path:bin/pkg-config:pkgconfig

depends_lib         port:libiconv \
                    port:openssl3

patchfiles          patch-avm-Cargo.lock.diff

build.env-append    PATH=${workpath}/bin:$env(PATH)
build.target

use_configure       no
use_parallel_build  no

post-extract {
    file mkdir ${workpath}/bin
    ln -s ${prefix}/bin/python2.7 ${workpath}/bin/python2

    # Use the native protoc; the bundled binary does not support macOS arm64.
    reinplace "s|protoc_bin_path().unwrap()|\"${prefix}/bin/protoc\"|g" \
        ${worksrcpath}/avm/build.rs

    # Replace npm with yarn in the build process
    reinplace "/npm init/ d" ${worksrcpath}/Makefile
    reinplace "s|npm run|yarn run|g" compiler/package.json

    # pkg 5.8 has no Node 22 runtime; use its latest supported runtime.
    reinplace {s|--targets host|--targets node18|g} ${worksrcpath}/Makefile

    # Don't run the envcheck script
    reinplace {s|\./\.envcheck\.sh|true|g} ${worksrcpath}/Makefile
}

destroot {
    xinstall -m 755 ${worksrcpath}/avm/target/release/${name} \
                    ${destroot}${prefix}/bin/
}

github.livecheck.regex {([0-9.]+)}
