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

github.setup        janet-lang janet 1.38.0 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  143623f7532e7e1dc6a269cabbe5ec218baf480d \
                    sha256  84dbf7db9c09677618549fb4be23631fd64f527af21051db02753241a2f6f752 \
                    size    590880

# 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

# Fixes non-standard use of $LD_FLAGS instead of the usual $LDFLAGS
#   for specifying libjanet linker flags.
patchfiles-append   fix-libjanet-ldflags.diff

# Fixes internal os/clock implementation on older systems.
patchfiles-append   fix-legacy-osx-clock.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.
"

