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

name                libzdb-mysql55
set name_package    libzdb
version             2.12
revision            1
set branch          [join [lrange [split ${version} .] 0 1] .]
categories          databases devel
maintainers         nomaintainer
license             GPL-3
platforms           darwin

description         A small, fast and easy to use Open Source Database Connection Pool Library.
long_description    "${description}
* Thread safe Database Connection Pool
* Connect to multiple database systems
* Zero runtime configuration, connect using a URL scheme
* C library
* Supports MySQL, PostgreSQL, SQLite and Oracle"

homepage            http://www.tildeslash.com/libzdb/
master_sites        ${homepage}dist/

distname            ${name_package}-${version}

checksums           rmd160  1838d7b7058db6a7dae155bd89912f660380818a \
                    sha256  37e6bd3d8254be7d8fe1419cf0500b9006783d0e3544eeeffc5e6954cbcd07d4 \
                    size    599160

configure.args      --with-sysroot=${prefix} \
                    --enable-optimized \
                    --without-postgresql \
                    --without-mysql \
                    --without-sqlite \
                    --without-oci \
                    --enable-openssl=no

set mp.ports {
    mysql51
    mysql55
    mysql56
    mariadb
}
set mp.names        {}
foreach mp.port ${mp.ports} {

    lappend mp.names "libzdb-${mp.port}"
}
foreach mp.name ${mp.names} {

    set idx [lsearch ${mp.names} ${mp.name}]
    set mp.port [lindex ${mp.ports} $idx]
    set mp.conflicts [lreplace ${mp.names} $idx $idx]
    if {[string compare ${mp.name} ${name}] == 0 && [string compare ${mp.name} ${subport}] == 0} {

        description         "Enable MySQL support for ${mp.port}"
#       conflicts ${mp.conflicts}

        depends_lib-append  port:${mp.port}
        configure.args-delete \
                            --without-mysql
        configure.args-append \
                            --with-mysql=${prefix}/lib/${mp.port}/bin/mysql_config \
                            --libdir=${prefix}/lib/${subport} \
                            --includedir=${prefix}/include/${subport} \
                            --datarootdir=${prefix}/share/${subport}
    } else {

        subport ${mp.name} {
    
            description         "Enable MySQL support for ${mp.port}"
#           conflicts ${mp.conflicts}

            depends_lib-append  port:${mp.port}
            configure.args-delete \
                                --without-mysql
            configure.args-append \
                                --with-mysql=${prefix}/lib/${mp.port}/bin/mysql_config \
                                --libdir=${prefix}/lib/${subport} \
                                --includedir=${prefix}/include/${subport} \
                                --datarootdir=${prefix}/share/${subport}
        }
    }
}

set mp.ports {
    postgresql16
}
set mp.names        {}
foreach mp.port ${mp.ports} {

    lappend mp.names "libzdb-${mp.port}"
}
foreach mp.name ${mp.names} {

    set idx [lsearch ${mp.names} ${mp.name}]
    set mp.port [lindex ${mp.ports} $idx]
#    set mp.conflicts [lreplace ${mp.names} $idx $idx]

    subport ${mp.name} {

        description "Enable PostgreSQL support for ${mp.port}"
#       conflicts ${mp.conflicts}

        depends_lib-append  port:${mp.port}
        configure.args-delete \
                            --without-postgresql
        configure.args-append \
                            --with-postgresql=${prefix}/lib/${mp.port}/bin/pg_config
    }

}

subport libzdb-oracle {

    revision            3

    description-append  {Built for oracle.}

    depends_lib-append      port:oracle-instantclient

    configure.args-delete   --without-oci
    configure.args-append   --with-oci-include=${prefix}/lib/oracle/sdk/include \
                            --with-oci-lib=${prefix}/lib/oracle \
                            --libdir=${prefix}/lib/${subport} \
                            --includedir=${prefix}/include/${subport} \
                            --datarootdir=${prefix}/share/${subport}
}

subport libzdb-sqlite3 {

    description-append  {Built for sqlite3.}

    depends_lib-append  port:sqlite3
    configure.args-delete \
                        --without-sqlite
    configure.args-append \
                        --with-sqlite=${prefix} \
                        --enable-sqliteunlock \
                        --libdir=${prefix}/lib/${subport} \
                        --includedir=${prefix}/include/${subport} \
                        --datarootdir=${prefix}/share/${subport}
}

post-destroot {

    xinstall -d ${destroot}${prefix}/share/${subport}/doc
    copy ${worksrcpath}/doc ${destroot}${prefix}/share/${subport}/doc
    xinstall -m 0644 -W ${worksrcpath} AUTHORS CHANGES COPYING README \
        ${destroot}${prefix}/share/${subport}/doc/
}

variant openssl description {Enable OpenSSL support} {

    depends_lib-append  path:lib/libssl.dylib:openssl
    configure.args-delete \
                        --enable-openssl=no
    configure.args-append \
                        --enable-openssl=${prefix}
}

test.run            yes
test.target         verify

livecheck.url       [lindex ${master_sites} 0]
livecheck.type      regex
livecheck.regex     "${name_package}-(\\d+\\.\\d+(\[0-9rc.\]+)?).tar.gz"
