# -*- 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        google jsonnet 0.17.0 v
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
revision            0
categories          devel

license             Apache-2
maintainers         nomaintainer

description         The data templating language

long_description    A data templating language for app and tool developers

homepage            https://jsonnet.org/

checksums           rmd160  e43a5cee00aaea3782407c9ce0b87d28f34fc3b9 \
                    sha256  9f4450ff784952a0f5c593ce7dabd83cbda2eed62a4b01cc2ba507b32483c8dd \
                    size    21859800

patchfiles-append   patch-Makefile.diff

post-patch {
    reinplace "s|@@PREFIX@@|${prefix}|g" Makefile
}

compiler.c_standard 1999
compiler.cxx_standard 2011

if {[string match *clang* ${configure.cxx}] && ${configure.cxx_stdlib} ne ""} {
    configure.ldflags-append -stdlib=${configure.cxx_stdlib}
}

if {${name} eq ${subport}} {
    PortGroup       makefile 1.0

    depends_lib-append \
                    port:nlohmann-json

    # needed for tests
    configure.ldflags-append \
                    "-I${worksrcpath}/include"

    build.target

    test.run        yes
}

# Python Bindings
# Name consistency with ${python.branch} and ${python.version} in
# ${prefix}/var/macports/sources/rsync.macports.org/macports/release/tarballs/ports/_resources/port1.0/group/python-1.0.tcl

set python_branches {3.7 3.8 3.9}
foreach python_branch ${python_branches} {
    set python_version [join [lrange [split ${python_branch} .] 0 1] ""]
    subport py${python_version}-${name} {
        PortGroup   python 1.0

        python.default_version ${python_version}

        categories-append \
                    devel

        master_sites \
                    ${github.master_sites}
    }
}

if {[string match "py*" ${subport}]} {
    depends_build-append \
                    port:py${python.version}-setuptools

    depends_lib-append \
                    port:jsonnet

    test.run        yes
}
