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

name                spatialite
version             5.1.0
revision            2
categories          databases gis
license             {MPL-1.1 GPL-2+ LGPL-2.1+}
maintainers         {yahoo.com:n_larsson @nilason} openmaintainer

description         Spatial extensions for SQLite 3

long_description    SpatiaLite is a library for geographic information \
                    systems (GIS) that implements the core OpenGIS \
                    specification. It provides SQLite with basic support \
                    for spatial data is intended for lightweight GIS \
                    projects.

homepage            https://www.gaia-gis.it/fossil/libspatialite/index
master_sites        https://www.gaia-gis.it/gaia-sins/libspatialite-sources
distname            libspatialite-${version}

checksums           rmd160  e3d2b0025fb0672efb04d5594a384aaf90f60fa8 \
                    sha256  43be2dd349daffe016dd1400c5d11285828c22fea35ca5109f21f3ed50605080 \
                    size    6517377

depends_build       path:bin/pkg-config:pkgconfig

depends_lib         port:geos \
                    port:librttopo \
                    port:libxml2 \
                    port:minizip \
                    port:zlib \
                    port:sqlite3 \
                    port:freexl

patchfiles-append   xmlNanoHTTPCleanup.patch

configure.args-append \
                    --enable-rttopo \
                    --enable-libxml2 \
                    --enable-freexl

configure.cppflags-delete   -I${prefix}/include

# Set PROJ
set proj_versions {6 7 8 9}
set proj_variants {}
foreach pjver ${proj_versions} {
    lappend proj_variants proj${pjver}
}
foreach proj_ver ${proj_versions} {
    set index [lsearch -exact ${proj_variants} proj${proj_ver}]
    set cflcts [lreplace ${proj_variants} ${index} ${index}]

    variant proj${proj_ver} description "Use Proj${proj_ver}" conflicts {*}${cflcts} "
        depends_lib-append          port:proj${proj_ver}
        configure.cppflags-append   -I${prefix}/lib/proj${proj_ver}/include
        configure.ldflags-append    -L${prefix}/lib/proj${proj_ver}/lib
    "
}
set projdf "if {"
foreach pv ${proj_versions} {
    set projdf "${projdf}!\[variant_isset proj${pv}\] && "
}
set projdf [string range ${projdf} 0 end-4]
set projdf "${projdf}} { default_variants +proj${pv} }"
eval ${projdf}

livecheck.type      regex
livecheck.url       ${homepage}
livecheck.regex     {current version is <b>(\d+\.\d+\.\d+)}
