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

github.setup                        actboy168 luamake 1.7 v
github.tarball_from                 archive
revision                            0
categories                          devel lua
license                             MIT
maintainers                         {mcalhoun @MarcusCalhoun-Lopez} openmaintainer
description                         a platform independent configuration and build system that uses the standard Lua command-line interpreter
long_description                    luamake is {*}${description}.

checksums                           rmd160  4de8deae9433a23549c6847b8a55f2b1156baac1 \
                                    sha256  7a128c33d036f85eb01bb6a64d4c2d55f29f306a1e620995709298605a533cd3 \
                                    size    56481

fetch.type                          git
post-extract {
    system -W ${worksrcpath}        "git submodule update --init"
}

# no Lua dependency
# luamkae uses bee.lua, which seems to reimplement parts of Lua
# see https://github.com/actboy168/bee.lua

depends_lib                         port:ninja
compiler.cxx_standard               2017

installs_libs                       no

patchfiles-append                   patch-macos.ninja.diff
post-extract {
    xinstall -m 0644                ${filespath}/Makefile \
                                    ${worksrcpath}
}

destroot {
    # do not pollute ${prefix}/bin with all the extra files and directories that are required to be in the same director as the luamake binary
    set bindir                      ${prefix}/libexec/${name}/bin

    set script                      [open "${destroot}${prefix}/bin/luamake" w 0755]
    puts ${script}                  "#!/bin/sh"
    puts ${script}                  ""
    puts ${script}                  "exec ${bindir}/luamake \"$@\""
    close ${script}

    xinstall -d -m 0755             ${destroot}${bindir}

    xinstall -m 0755                ${worksrcpath}/luamake \
                                    ${destroot}${bindir}

    xinstall -m 0644                ${worksrcpath}/main.lua \
                                    ${destroot}${bindir}

    foreach dir {scripts tools} {
        xinstall -d -m 0755         ${destroot}${bindir}/${dir}
        fs-traverse -tails f        ${worksrcpath}/${dir} {
            if {[file isdirectory   ${worksrcpath}/${dir}/${f}]} {
                xinstall -d -m 0755 ${destroot}${bindir}/${dir}/${f}
            } else {
                xinstall -m 0644    ${worksrcpath}/${dir}/${f} \
                                    ${destroot}${bindir}/${dir}/${f}
            }
        }
    }
}
