# -*- 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        nalgeon sqlean 0.27.1
github.tarball_from archive
revision            0

description         The ultimate set of SQLite extensions

long_description    \
    SQLite has few functions compared to other database management systems. \
    SQLite authors see this as a feature rather than a problem, because \
    SQLite has an extension mechanism in place. There are a lot of SQLite \
    extensions out there, but they are incomplete, inconsistent and scattered \
    across the internet. sqlean brings them together, neatly packaged into \
    domain modules, documented, tested, and built for Linux, Windows and macOS.

categories          databases
license             MIT
maintainers         {gmail.com:herby.gillot @herbygillot} \
                    openmaintainer

depends_lib-append  port:sqlite3

fetch.type          git

patchfiles          patch-Makefile.diff

# base32.c: error: ‘for’ loop initial declaration used outside C99 mode
# However just passing -std= flag does not fix the build:
# extension.c: error: ‘struct ipaddress’ has no member named ‘ipv4’
# So still need to blacklist old Xcode gcc.
compiler.blacklist-append \
                    *gcc-4.0 *gcc-4.2

# https://github.com/nalgeon/sqlean/issues/124
# https://github.com/nalgeon/sqlean/issues/132
if {${os.platform} eq "darwin" && ${os.major} < 18} {
    patchfiles-append \
                    patch-no-time-ext.diff
    configure.cflags-append \
                    -DSQLEAN_OMIT_UUID7
}

build.target        prepare-dist compile-macos

use_parallel_build  no

set extension_dir   ${prefix}/libexec/${name}

destroot {
    xinstall -d ${destroot}${extension_dir}
    xinstall {*}[glob ${worksrcpath}/dist/*] ${destroot}${extension_dir}

    xinstall -d ${destroot}${prefix}/share/doc/${name}
    xinstall \
        {*}[glob ${worksrcpath}/docs/*] ${destroot}${prefix}/share/doc/${name}/
}

notes "
${name} extensions have been installed to ${extension_dir}

You can load them with '.load', ie.:

    .load ${extension_dir}/crypto.dylib
"