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

name                idris2
github.setup        idris-lang Idris2 0.8.0 v
revision            0
categories          lang
license             BSD
maintainers         nomaintainer
description         Purely functional programming language with dependent types
long_description    {*}${description}
homepage            https://www.idris-lang.org
checksums           rmd160  cdb5c140068560a5486341b31979e46b960162c3 \
                    sha256  7b85226098c5dee96a0a77c892932d2e9fab8e5a5c2d08a0525520e1f4405551 \
                    size    6995063
github.tarball_from archive

depends_build-append \
                    path:libexec/coreutils/libstdbuf.so:coreutils

depends_lib-append  port:chez-scheme \
                    port:gmp

patchfiles          0001-prefix.patch

# https://github.com/idris-lang/Idris2/commit/8bfe6b92fc0f9f28c4922f0aeb21020084212c74
patchfiles-append    0002-use-memalign.patch

set idris_root      ${prefix}/libexec/idris2

post-patch {
    reinplace "s,@IDRIS_ROOT@,${idris_root}," ${worksrcpath}/config.mk
}

# error: stdnoreturn.h: No such file or directory
compiler.c_standard 2011

# idris_signal.c:7:10: fatal error: 'stdatomic.h' file not found
compiler.blacklist-append {clang < 700}

build.target        bootstrap

build.args-append   SCHEME=scheme

# https://github.com/idris-lang/Idris2/issues/3456
if {${os.platform} eq "darwin" && ${os.major} < 11} {
    depends_build-append \
                    port:zsh
    build.env-append \
                    SHELL=${prefix}/bin/zsh
}

post-destroot {
    foreach f {compileChez idris2-boot.so idris2-boot.ss} {
        if {[file exists ${destroot}${idris_root}/bin/idris2_app/${f}]} {
            delete ${f}
        }
    }
    ln -s ${idris_root}/bin/idris2 ${destroot}${prefix}/bin/idris2
}

test.run            yes
test.target         test
