# -*- 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       compiler_blacklist_versions 1.0
PortGroup       github    1.0
PortGroup       perl5     1.0

github.setup    timescale timescaledb 2.17.2
revision        0
license         Apache-2
description     A time-series database that integrates with PostgreSQL.
maintainers     {blair @blair} openmaintainer
categories      databases
conflicts       timescaledb1
homepage        https://www.timescaledb.com/

long_description \
                TimescaleDB is an open-source database designed to \
                make SQL scalable for time-series data. It is \
                engineered up from PostgreSQL, providing automatic \
                partitioning across time and space (partitioning key), \
                as well as full SQL support. TimescaleDB is packaged \
                as a PostgreSQL extension.

checksums       rmd160  c9c2be49270dc3f40a05bf99ff10a97a6f2cbb7f \
                sha256  20cd2ebb73d776225efbc736502fa575c34f55f21a2ef6e8838b69d4dc1513f9 \
                size    7567823

depends_build   path:bin/cmake:cmake \
                port:perl${perl5.major} \
                port:p${perl5.major}-ipc-run

set postgresql_branches {12 13 14 15 16 17}

foreach branch ${postgresql_branches} {
    subport pg${branch}-${name} {
        set pg postgresql${branch}
        depends_lib-append      port:${pg}
        configure.env-append    PATH=${prefix}/lib/${pg}/bin:$::env(PATH)
    }
}

# End of support branches
subport pg12-${name} {
    # 2.11.2 is the last version supported for PostgreSQL 12.x.
    # https://github.com/timescale/timescaledb/releases/tag/2.12.0
    github.setup    timescale timescaledb 2.11.2
    revision        0
    checksums       rmd160  032705bda2f125dae286df68e800c664b0233663 \
                    sha256  06cf5047bb6cd03058724d6c91c29a871e419074ca92770302d182cd6ccedf0b \
                    size    7729279
}

subport pg13-${name} {
    # 2.15.3 is the last version supported for PostgreSQL 13.x.
    # https://github.com/timescale/timescaledb/releases/tag/2.16.0
    github.setup    timescale timescaledb 2.15.3
    revision        0
    checksums       rmd160  b94f13ddf31c7e2a79e95d3d1b30ef23ffc4de5c \
                    sha256  70b7aa63558323f60e063c870456fa604d8b89fba8e6dab94aa26c9472b99942 \
                    size    7441397
}

compiler.c_standard     2011
# Work around MacPorts base C11 compiler selection bug.
# https://github.com/macports/macports-base/pull/196
compiler.blacklist-append {clang < 500}

configure.cmd           ./bootstrap
configure.pre_args

# Do not remove -DAPACHE_ONLY from configure.args otherwise some
# binaries may be built that are licensed under the Timescale License
# (TSL). See https://github.com/timescale/timescaledb#timescaledb and
# https://github.com/timescale/timescaledb/blob/master/tsl/LICENSE-TIMESCALE.
# However, using +timescale_license will enable Timescale License'd code.
#
# -DLINTER=off: see https://github.com/timescale/timescaledb/issues/2889
configure.args          -DAPACHE_ONLY=1 \
                        -DLINTER=off \
                        -DPROJECT_INSTALL_METHOD=macports

build.dir               ${worksrcpath}/build

# @holymonson 2024-10-30: for smooth upgrade from legacy, kill this hack sometime later.
# https://trac.macports.org/wiki/PortfileRecipes#deactivatehack
pre-activate {
    if {![catch {lindex [registry_active timescaledb] 0} installed]} {
        set _version [lindex $installed 1]
        if {[vercmp $_version 2.16.1] < 0} {
            registry_deactivate_composite timescaledb "" [list ports_nodepcheck 1]
        }
    }
}

github.livecheck.regex  {([0-9.]+)}

variant timescale_license description {Enable Timescale License code, license will be Timescale License} {
    configure.args-delete   -DAPACHE_ONLY=1
    license                 Timescale-License
}

if {${name} eq ${subport}} {
    # make it a stub port like py-foo
    supported_archs noarch
    use_configure no
    extract     {}
    build       {}
    destroot {
        xinstall -d ${destroot}${prefix}/share/doc/${subport}
        system "echo $name is a stub port > ${destroot}${prefix}/share/doc/${name}/README"
    }

    set latest_branch [lindex ${postgresql_branches} end]
    depends_lib     port:pg${latest_branch}-${name}
}
