# -*- 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.5
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  e3a79080210a5bcd80393a25e996f69e4d13c726 \
                    sha256  0913c53daabab1f1ab586afd55bb55370796f2b8abcc6e37640ab7704ad99ce1 \
                    size    390860

# Disable unexpected download of subprojects
meson.wrap_mode     nodownload

set py_major        3
set py_minor_min    9
set py_minor_max    13

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

depends_lib-append \
                    port:exiv2 \
                    path:lib/pkgconfig/glib-2.0.pc:glib2 \
                    path:lib/pkgconfig/gobject-introspection-1.0.pc:gobject-introspection \
                    path:bin/vala: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 python37 conflicts python38 python39 python310 python311 python312 python313 \
    description {Build Python3 bindings using Python 3.7} {}
variant python38 conflicts python37 python39 python310 python311 python312 python313 \
    description {Build Python3 bindings using Python 3.8} {}
variant python39 conflicts python37 python38 python310 python311 python312 python313 \
    description {Build Python3 bindings using Python 3.9} {}
variant python310 conflicts python37 python38 python39 python311 python312 python313 \
    description {Build Python3 bindings using Python 3.10} {}
variant python311 conflicts python37 python38 python39 python310 python312 python313 \
    description {Build Python3 bindings using Python 3.11} {}
variant python312 conflicts python37 python38 python39 python310 python311 python313 \
    description {Build Python3 bindings using Python 3.12} {}
variant python313 conflicts python37 python38 python39 python310 python311 python312 \
    description {Build Python3 bindings using Python 3.13} {}

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

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}"
}

platform darwin 8 {
    # Tiger lacks @rpath, apply the usual gtk-doc workaround
    destroot.env-append \
                    "DYLD_LIBRARY_PATH=${build_dir}/${name}"
}

livecheck.type      gnome
