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

github.setup        janet-lang jpm 7f0af49ca2d18cd0657be37fd6d4d775613c99bb
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
version             20220615
revision            0

categories          devel
license             MIT
platforms           any
supported_archs     noarch

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

description         Janet Project Manager
long_description    JPM is the Janet Project Manager tool. It is for\
                    automating builds and downloading dependencies of\
                    Janet projects.

homepage            https://janet-lang.org/docs/jpm.html

checksums           rmd160  bf5a950af1c07086bd352794981f08b4c65cc1b3 \
                    sha256  8f92642231c39483b91261504d40a664dee3236abf5f6d202a30fbca1acc03f6 \
                    size    37254

# jpm is installed by executing `bootstrap.janet`, so we need Janet.
depends_lib         port:janet

use_configure       no

# Replace config values we want to set with strings we will grep for.
patchfiles          patch-macports-locations.diff

post-patch {
    # Actually set those values.
    reinplace "s|@@MACPORTS_PREFIX@@|${prefix}|g" ${worksrcpath}/configs/macos_config.janet
}

# Nothing to build, jpm is built and installed via `bootstrap.janet`.
build {}

# jpm by default assumes it's installed "under" janet (in whatever
#   directory janet is installed in); we're going to put it into
#   it's own so we have to make that directory: jpm.
pre-destroot {
    xinstall -d -m 0755         ${destroot}${prefix}/lib/jpm
}

# MacPorts puts DESTDIR at the end of the command so we have to do this. If
#   MacPorts put DESTDIR at the start this wouldn't be necessary.
destroot.env-append DESTDIR=${destroot}

# Intentionally empty to prevent default value `install`.
destroot.target

destroot.cmd        ${prefix}/bin/janet
destroot.args       bootstrap.janet configs/macos_config.janet

test.run            yes

# Intentionally empty to prevent default value `test`.
test.target

test.env-append     PREFIX=${prefix}
test.cmd            ${prefix}/bin/janet
test.args           test/installtest.janet

notes "
jpm is required to use MacPorts managed jpm packages (e.g.\
janet-joy) even though you could install joy yourself using\
jpm. This is because jpm builds those packages and is not\
included with janet by default.

If you want to globally install a package it is recommended\
you install the MacPorts port instead which are all available\
with the prefix 'janet-', so for 'uri' it would be janet-uri\
and for 'joy', janet-joy.

    e.g.
        \$ port install janet-joy

You can locally install jpm packages to individual projects\
by first changing to their directory and invoking jpm with\
the --local flag. You must keep using --local for things\
like listing your installed packages if you want them\
specific to your project, in this case foo. See man 1 jpm\
for more information regarding jpm's options.

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

This way you can have (or not) a globally installed janet-joy\
and a specific version local to a project you're working on via\
the above command. To delete installed packages simply delete\
your project's jpm_tree folder which you can think of being\
similar to node_modules in the npm ecosystem.

If you elect to use only jpm to globally install packages they\
will not be cleaned up by MacPorts if you uninstall jpm or\
janet because MacPorts cannot track these files. The special\
'janet-' prefixed ports are tracked hence 'janet-joy' etc.

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