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

# strnlen, O_CLOEXEC
legacysupport.newest_darwin_requires_legacy 10

github.setup        janet-lang janet 1.41.2 v
github.tarball_from archive
revision            0

categories          lang
license             MIT

maintainers         {@tsujp wz.ht:jc+macports} openmaintainer

description         A dynamic language and bytecode vm
long_description    Janet is a functional and imperative programming \
                    language and bytecode interpreter. It is a lisp-like \
                    language, but lists are replaced by other data structures. \
                    The language also supports bridging to native code written \
                    in C, meta-programming with macros, and bytecode assembly.

homepage            https://janet-lang.org/

checksums           rmd160  5d1735e908240b652878c264d52afc15acfd79f8 \
                    sha256  168e97e1b790f6e9d1e43685019efecc4ee473d6b9f8c421b49c195336c0b725 \
                    size    612285

# Fixes passing correct link flags to boot_strap janet
#   and incorrect use of environ on macOS.
patch.pre_args-replace  -p0 -p1

# Fixes linking of boot strap binary on older systems.
patchfiles-append   fix-janet_boot-link-legacysupport.diff

compiler.c_standard 2011
# stdatomic.h
compiler.blacklist-append {clang < 700}

# We're using a seperate directory for jpm so we need to configure the
#   build such that Janet resolves jpm packages installed there
#   (either globally or via MacPorts).
build.env-append    "JANET_PATH=${prefix}/lib/jpm"

destroot.keepdirs   ${destroot}${prefix}/lib/${name}

pre-destroot {
    xinstall -d -m 0755 ${destroot}${prefix}/lib/${name}
}

post-destroot {
    # Need libjanet.a for all possible jpm behaviour.
    file copy ${destroot}${prefix}/lib/libjanet.a \
        ${destroot}${prefix}/lib/janet
}

test.run            yes
test.env            {*}${build.env}

notes "
Janet has a package ecosystem (similar to how Nodejs does) and\
these packages are managed by the package manager jpm. However\
jpm is not installed by default. You have a few options which\
are not mutually exclusive.

In both cases MacPorts will install jpm itself but you can then\
choose whether or not to use globally installed jpm packages as\
in (1) and/or you can install local versions of jpm\
packages as in (2) using the --local flag of jpm.

(1) Use jpm packages managed by MacPorts. These are available\
    with prefix 'janet-' so the package 'joy' is on MacPorts\
    as 'janet-joy' etc.

    e.g.
        \$ port install janet-joy

(2) Use jpm packages via jpm itself. It is _not_ recommended\
    to install packages globally as they would be unmanaged by\
    MacPorts meaning if you uninstall jpm these files would\
    remain on disk and not be cleaned up as you might expect.\
    Luckily jpm has functionality to install packages into\
    a custom directory (e.g. local to your janet project).\
    This is toggled via the --local flag when invoking jpm\
    See the installation notes for jpm for more information\
    beyond the basic example below.

    e.g.
        \$ port install jpm
        \$ cd ~/projects/foo && jpm install --local joy

Note: use of sudo in the above commands depends on whether your\
MacPorts is installed to a directory owned by the root user.
"

