# -*- 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.7.0 v
revision            1
categories          lang
license             BSD
maintainers         {@barracuda156 gmail.com:vital.had} openmaintainer
description         Purely functional programming language with dependent types
long_description    {*}${description}
homepage            https://www.idris-lang.org
checksums           rmd160  0632b400415932d03d750bc6f72b48d8a2d9a6f1 \
                    sha256  7a8612a1cd9f1f737893247260c6942bf93f193375d4b3df0148f7abf74d6e14 \
                    size    6987849
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/pull/3324
patchfiles-append   0002-idris_support-fix-environ-for-macOS.patch
# https://github.com/idris-lang/Idris2/pull/3325
patchfiles-append   0003-idris_signal-fix-static_assert.patch
# https://github.com/idris-lang/Idris2/pull/3326
patchfiles-append   0004-idris2.ss-support-powerpc.patch \
                    0005-Chez.idr-support-macOS-PowerPC.patch \
                    0006-ChezSep.idr-support-macOS-PowerPC.patch \
                    0007-chez-support.ss-support-macOS-PowerPC.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

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
