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

github.setup        c3lang c3c 0.8.6 v
github.tarball_from archive
revision            0

name                c3
categories          lang
license             LGPL-3 MIT
maintainers         {gmail.com:herby.gillot @herbygillot} openmaintainer

description         Compiler for the C3 programming language
long_description    C3 is a systems programming language that builds on C's \
                    syntax and semantics, adding features such as modules, \
                    generics, contracts, and compile-time evaluation.
homepage            https://c3-lang.org/

checksums           rmd160  ffc07efc7bfc7c3f6bb4483bc8b4593d6644916a \
                    sha256  ce2bd6e7658b480278e3a3af7c999b7a55d8a042c26446e9ea317f9357a8416b \
                    size    27734266

set llvm_version    22
set llvm_prefix     ${prefix}/libexec/llvm-${llvm_version}

depends_lib-append  port:clang-${llvm_version} \
                    port:llvm-${llvm_version} \
                    port:curl \
                    port:libxml2 \
                    port:zstd

compiler.cxx_standard 2017

patchfiles          patch-cmake-install.diff

configure.args-append \
                    -DLLVM_DIR=${llvm_prefix}/lib/cmake/llvm \
                    -DC3_USE_MIMALLOC=OFF \
                    -DC3_USE_TB=OFF \
                    -DC3_FETCH_LLVM=OFF

post-destroot {
    # Keep the compiler and its runtime directory together, outside bin.
    xinstall -d ${destroot}${prefix}/libexec/${name}
    move ${destroot}${prefix}/bin/c3c ${destroot}${prefix}/libexec/${name}/c3c
    ln -s ../libexec/${name}/c3c ${destroot}${prefix}/bin/c3c
    if {${os.platform} eq "darwin"} {
        delete ${destroot}${prefix}/bin/c3c_rt
        ln -s ${llvm_prefix}/lib/clang/${llvm_version}/lib/darwin \
            ${destroot}${prefix}/libexec/${name}/c3c_rt
    }
}
