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

name                            lua-md5
github.setup                    lunarmodules md5 1.3
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from             tarball
revision                        0
categories                      lua devel
license                         MIT
maintainers                     nomaintainer
description                     checksum facilities for Lua
long_description                MD5 offers {*}${description}.

checksums                       rmd160  0dc23c466d41eed97e73db9e7d010719202835a0 \
                                sha256  1451ed5d289c695fc94b4fbeb0f4fcc0c72c69fe5c42dfc042e56d02c3ef572e \
                                size    31393

makefile.override-append        PREFIX \
                                CFLAGS
makefile.has_destdir            no

build.args-append               LIB_OPTION="-bundle -undefined dynamic_lookup \$LDFLAGS"

foreach branch ${lua.branches} {
    set subname                 md5
    set branch_no_dot           [join [split ${branch} .] ""]
    set subport_name            lua${branch_no_dot}-${subname}

    subport ${subport_name} {}
    if {${subport} eq ${subport_name}} {
        lua.version             ${branch}
        destroot.args-append    LUA_SYS_VER=${lua.version}

        pre-destroot {
            xinstall -d -m 0755 ${destroot}${prefix}/lib/lua/${lua.version}
        }

        post-destroot {
            # see https://luarocks.org/manifests/tomasguisasola/md5-${version}-1.rockspec
            set luarocks_dir    ${prefix}/lib/luarocks/rocks-${lua.version}/md5/${version}-1

            xinstall -d -m 0755 ${destroot}${luarocks_dir}
            file copy           ${worksrcpath}/doc \
                                ${destroot}${luarocks_dir}
            file copy           ${worksrcpath}/tests \
                                ${destroot}${luarocks_dir}
        }
    }
}

subport ${name} {
    distfiles
    patchfiles
    extract.rename              no
    platforms                   any
    supported_archs             noarch
    foreach deptype {depends_extract depends_patch depends_lib depends_build depends_run depends_test} {
        ${deptype}
    }
    proc lua::callback {} {}
    build {}
    destroot {
        set docdir              ${destroot}${prefix}/share/doc/${subport}
        xinstall -d -m 0755     ${docdir}
        set f                   [open "${docdir}/README" w 0644]
        puts ${f}               "[option subport] is a stub port"
        close                   ${f}
    }
}
