# -*- 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           cmake 1.1
PortGroup           github 1.0

github.setup        HaxeFoundation neko 2-3-0 v
revision            0

version             [string map {- .} ${github.version}]
categories          lang
maintainers         {ryandesign @ryandesign} openmaintainer
license             LGPL-2.1+

description         high-level dynamically-typed embeddable language

long_description    Neko is a high-level dynamically-typed programming \
                    language. It can be used as an embedded scripting \
                    language. It has been designed to provide a common \
                    runtime for several different languages. Learning and \
                    using Neko is very easy. You can easily extend the \
                    language with C libraries. You can also write generators \
                    from your own language to Neko and then use the Neko \
                    Runtime to compile, run, and access existing libraries.

homepage            https://nekovm.org
github.tarball_from archive

set connector_vers  3.0.9

master_sites        ${master_sites}:main \
                    http://ftp.hosteurope.de/mirror/archive.mariadb.org/connector-c-${connector_vers}/:connector

set main_distfile   ${distfiles}
set connector_distfile \
                    mariadb-connector-c-${connector_vers}-src.tar.gz

extract.only        ${main_distfile}

distfiles           ${main_distfile}:main \
                    ${connector_distfile}:connector

checksums           ${main_distfile} \
                    rmd160  b25103c19e167417ab9e307b1d921fd33953585e \
                    sha256  850e7e317bdaf24ed652efeff89c1cb21380ca19f20e68a296c84f6bad4ee995 \
                    size    514044 \
                    ${connector_distfile} \
                    rmd160  7e3bf070d0f5759c6c5dc5a2a4cc31c0b02c0b78 \
                    sha256  7277c0caba6f50b1d07e1d682baf0b962a63e2e6af9e00e09b8dcf36a7858641 \
                    size    668142

depends_build-append \
                    port:boehmgc \
                    bin:git:git \
                    path:bin/pkg-config:pkgconfig

depends_lib-append  port:apache2 \
                    port:mbedtls \
                    port:pcre \
                    port:sqlite3 \
                    port:zlib

patchfiles          patch-LP64.diff \
                    CMakeLists.txt.patch \
                    cgi.c.patch \
                    patch_mariadb.cmake.endif.patch \
                    patch_mariadb.cmake.libiconv.patch \
                    process.c.patch \
                    socket.c.patch \
                    ssl.c.patch \
                    ui.c.patch \
                    patch-vm-load.c.diff

variant universal   {}

set mysql           {}

cmake.generator     Ninja

post-patch {
    reinplace "s|@PREFIX@|${prefix}|g" ${worksrcpath}/vm/load.c
}

configure.args-append \
                    -DCMAKE_MAKE_PROGRAM=${prefix}/bin/ninja \
                    -DSTATIC_DEPS=MariaDBConnector \
                    -DRELOCATABLE=OFF \
                    -DRUN_LDCONFIG=OFF

post-configure {
    ln -s ${distpath}/${connector_distfile} ${build.dir}/libs/download/
}

use_parallel_build  no

test.run            yes

post-destroot {
    set docdir ${prefix}/share/doc/${subport}
    xinstall -d ${destroot}${docdir}
    xinstall -m 0644 -W ${worksrcpath} \
        CHANGES \
        LICENSE \
        ${destroot}${docdir}
}

variant mysql55 description {Use mysql55} conflicts mysql57 mariadb {
    depends_lib-append port:mysql55
    set mysql mysql55
}

variant mysql57 description {Use mysql57} conflicts mysql55 mariadb {
    depends_lib-append port:mysql57
    set mysql mysql57
}

variant mariadb description {Use mariadb} conflicts mysql55 mysql57 {
    depends_lib-append port:mariadb
    set mysql mariadb
}

if {![variant_isset mysql55] && ![variant_isset mysql57] && ![variant_isset mariadb]} {
    default_variants +mysql57
}

livecheck.type      regex
livecheck.version   ${version}
livecheck.url       ${homepage}/download/
livecheck.regex     {Neko ([0-9.]+) }
