# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:filetype=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0
PortGroup           meson 1.0

name                gexiv2
version             0.14.6
revision            0

categories          gnome graphics
license             GPL-2+
maintainers         {devans @dbevans} {mascguy @mascguy} openmaintainer
description         gexiv2 is a GObject-based wrapper around the exiv2 library.
long_description    ${description} \
                    It makes the basic features of exiv2 available to GNOME applications. \
                    Thanks to GObject Introspection support, gexiv2 has excellent support \
                    for Python, and can also be accessed by any other programming \
                    language that supports GI.
homepage            https://wiki.gnome.org/Projects/gexiv2

set branch          [join [lrange [split ${version} .] 0 1] .]
master_sites        gnome:sources/${name}/${branch}/
use_xz              yes

checksums           rmd160  b083c8a756fd855ffeb3a64d6d159847d4c83514 \
                    sha256  606c28aaae7b1f3ef5c8eabe5e7dffd7c5a1c866d25b7671fb847fe287a72b8b \
                    size    391436

# Disable unexpected download of subprojects
meson.wrap_mode     nodownload

set py_major        3
set py_minor_min    10
set py_minor_max    14

compiler.blacklist-append \
                    {clang < 900}

# Needs Cxx14 as of v0.14.x
compiler.cxx_standard 2014

# Be sure to specify Cxx14, as Cxx17 compilation fails for v0.14.1
configure.cxxflags-append \
                    -std=c++14

if { [string match *clang* ${configure.compiler}] } {
    # Quiet warnings
    configure.cxxflags-append \
                    -Wno-deprecated-declarations \
                    -Wno-error=unknown-warning-option \
                    -Wno-unknown-warning-option
}

depends_build-append \
                    port:gi-docgen \
                    port:gtk-doc \
                    port:pkgconfig \
                    path:bin/vala:vala

depends_lib-append \
                    port:exiv2 \
                    path:lib/pkgconfig/glib-2.0.pc:glib2 \
                    path:lib/pkgconfig/gobject-introspection-1.0.pc:gobject-introspection

license_noconflict  vala

configure.args-append \
                    -Dgtk_doc=true

proc py_ver_set {} {
    global py_major py_minor_min py_minor_max

    for {set v ${py_minor_min}} {${v} <= ${py_minor_max}} {incr v} {
        set pv         ${py_major}.${v}
        set pv_nodot   [string map {. {}} ${pv}]
        set pv_variant python${pv_nodot}

        if {[variant_isset ${pv_variant}]} {
            return ${pv}
        }
    }

    return ""
}

proc py_setup {p_py_ver} {
    global py_ver py_ver_nodot

    set py_ver       ${p_py_ver}
    set py_ver_nodot [string map {. {}} ${py_ver}]

    patchfiles-append \
                    patch-python-bins.diff

    post-patch {
        reinplace "s|@@PYTHON3_BIN@@|${prefix}/bin/python${py_ver}|" \
                    meson.build
    }

    depends_lib-append \
                    port:py${py_ver_nodot}-gobject3
}

# TODO: Generate these dynamically, since we define min/max supported versions
variant python310 conflicts python311 python312 python313 python314 \
    description {Build Python3 bindings using Python 3.10} {}
variant python311 conflicts python310 python312 python313 python314 \
    description {Build Python3 bindings using Python 3.11} {}
variant python312 conflicts python310 python311 python313 python314 \
    description {Build Python3 bindings using Python 3.12} {}
variant python313 conflicts python310 python311 python312 python314 \
    description {Build Python3 bindings using Python 3.13} {}
variant python314 conflicts python310 python311 python312 python313 \
    description {Build Python3 bindings using Python 3.14} {}

if {[py_ver_set] eq ""} {
    default_variants +python314
}

set py_ver [py_ver_set]
if {${py_ver} ne ""} {
    py_setup ${py_ver}
}

pre-configure {
    if {${py_ver} eq ""} {
        error "This port requires that one python variant be enabled"
    }
}

# uses g-ir-scanner, which uses $CC from env
if {${universal_possible} && [variant_isset universal]} {
    foreach arch ${configure.universal_archs} {
        lappend merger_build_env(${arch}) \
                    "CC=${configure.cc} -arch ${arch}"
        lappend merger_destroot_env(${arch}) \
                    "CC=${configure.cc} -arch ${arch}"
    }
} else {
    build.env-append \
                    "CC=${configure.cc} ${configure.cc_archflags}"
    destroot.env-append \
                    "CC=${configure.cc} ${configure.cc_archflags}"
}

livecheck.type      gnome
