# -*- 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-luasql-sqlite3
github.setup        lunarmodules luasql 2.6.0
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
version             2.6.1
revision            0
categories          lua devel
license             MIT
maintainers         {judaew @judaew} openmaintainer

description         LuaSQL is a simple interface from Lua to a DBMS.
long_description    {*}${description} It enables a Lua program to connect to\
    databases, execute arbitrary SQL statements and retrieve results in a\
    row-by-row cursor fashion.
homepage            http://lunarmodules.github.io/luasql/

checksums           rmd160  49881b131df6f29ee90459f10e84e28c176abdf4 \
                    sha256  719462f6defdc3cfe7f2da0d6ff7bf8c56797d02daa2eb7908f721dd28df54d2 \
                    size    107660

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

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

foreach branch ${lua.branches} {
    set subname                 luasql-sqlite3
    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/luasql-sqlite3-${version}-3.rockspec
            set luarocks_dir    ${prefix}/lib/luarocks/rocks-${lua.version}/luasql-sqlite3/${version}-3

            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}
    }
}
