# -*- 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.16.1
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  f657bb86924d61c007522355f45c815e1f60fdc6 \
                    sha256  a4804e6b5d07465f599b369e3bb0cf8460811d42d2e3a158e41244a7951e86bc \
                    size    7449735

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

set postgresql_branches {12 13 14 15 16}

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

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}} {
    PortGroup       stub 1.0

    supported_archs noarch

    # set this stub port depends on its latest subport for legacy
    depends_lib     port:pg[lindex ${postgresql_branches} end]-${name}
}
